private void build(GHPullRequest pr, GHUser buildRequester, TriggerCause cause) throws IOException { ArrayList<ParameterValue> parameters = getDefaultBuildParameters(); parameters.add(new StringParameterValue(PR_COMMIT, pr.getHead().getSha())); parameters.add(new StringParameterValue(PR_BRANCH, pr.getHead().getRef())); if (buildRequester != null) { parameters.add(new StringParameterValue(BUILD_REQUESTER, buildRequester.getLogin())); if (buildRequester.getEmail() != null) { parameters.add(new StringParameterValue(BUILD_REQUEST_EMAIL, buildRequester.getEmail())); } } parameters.add(new StringParameterValue(PR_NUMBER, String.valueOf(pr.getNumber()))); parameters.add(new StringParameterValue(PR_MERGE_BRANCH, pr.getBase().getRef())); parameters.add(new StringParameterValue(PR_OWNER, pr.getUser().getLogin())); if (pr.getUser().getEmail() != null) { parameters.add(new StringParameterValue(PR_OWNER_EMAIL, pr.getUser().getEmail())); } final StringParameterValue prUrlParam = new StringParameterValue(PR_URL, pr.getHtmlUrl().toString()); parameters.add(prUrlParam); project.scheduleBuild2( project.getQuietPeriod(), cause, new ParametersAction(parameters), getBuildData(prUrlParam), new RevisionParameterAction(pr.getHead().getSha())); }
public void check() { if (!initGhRepository()) { return; } if (helper.isProjectDisabled()) { logger.log(Level.FINE, "Project is disabled, not checking github state"); return; } List<GHPullRequest> openPulls; try { openPulls = ghRepository.getPullRequests(GHIssueState.OPEN); } catch (IOException ex) { logger.log(Level.SEVERE, "Could not retrieve open pull requests.", ex); return; } ConcurrentMap<Integer, GhprbPullRequest> pulls = helper.getTrigger().getPulls(); Set<Integer> closedPulls = new HashSet<Integer>(pulls.keySet()); for (GHPullRequest pr : openPulls) { if (pr.getHead() == null) { try { pr = ghRepository.getPullRequest(pr.getNumber()); } catch (IOException ex) { logger.log(Level.SEVERE, "Could not retrieve pr " + pr.getNumber(), ex); return; } } try { check(pr); } catch (IOException ex) { logger.log(Level.SEVERE, "Could not retrieve pr " + pr.getNumber(), ex); return; } closedPulls.remove(pr.getNumber()); } // remove closed pulls so we don't check them again for (Integer id : closedPulls) { pulls.remove(id); } }
private void check(GHPullRequest pr) throws IOException { ConcurrentMap<Integer, GhprbPullRequest> pulls = helper.getTrigger().getPulls(); final Integer id = pr.getNumber(); GhprbPullRequest pull; if (pulls.containsKey(id)) { pull = pulls.get(id); } else { pulls.putIfAbsent(id, new GhprbPullRequest(pr, helper, this)); pull = pulls.get(id); } pull.check(pr); }