public boolean isBranchBuildAllowed(GHPullRequest remotePR) { String branchName = remotePR.getBase().getRef(); //if allowed branch list is empty, it's allowed to build any branch boolean isAllowed = targetBranchList.isEmpty(); for (String branch : targetBranchList) { //if branch name matches to pattern, allow build isAllowed = Pattern.compile(branch).matcher(branchName).matches(); if (isAllowed) { break; } } LOGGER.trace("Target branch {} is {} in our whitelist of target branches", branchName, (isAllowed ? "" : "not ")); return isAllowed; }
/** * Base and Ref are part of the PullRequest object * * @return the sha to the base */ public String getTarget() { try { return getPullRequest().getBase().getRef(); } catch (IOException e) { return "UNKNOWN"; } }
public String getPullRequestBaseBranchName(int requestNumber) throws IOException { return ghRepo.getPullRequest(requestNumber).getBase().getRef(); }
private boolean checkCommit(GHPullRequest pr) { GHCommitPointer head = pr.getHead(); GHCommitPointer base = pr.getBase(); String headSha = head.getSha(); String baseSha = base.getSha(); if (StringUtils.equals(headSha, this.head) && StringUtils.equals(baseSha, this.base)) { return false; } LOGGER.log(Level.FINE, "New commit. Sha: Head[{0} => {1}] Base[{2} => {3}]", new Object[] {this.head, headSha, this.base, baseSha}); setHead(headSha); setBase(baseSha); if (accepted) { shouldRun = true; } return true; }
private String getParentSha(final GHCommit commit, final GitBranch gitBranch) throws IOException { final String parentSha; if (gitBranch.isPullRequest()) { final GHPullRequest pullRequest = this.githubRepositoryService.getGithubRepository().getPullRequest(gitBranch.pullRequestNumber()); parentSha = pullRequest.getBase().getSha(); } else { parentSha = (commit.getParentSHA1s() != null && commit.getParentSHA1s().size() > 0) ? commit.getParentSHA1s().get(0) : null; } return parentSha; }
private void setPullRequest(GHPullRequest pr) { if (pr == null) { return; } synchronized (this) { this.pr = pr; try { if (updated == null) { setUpdated(pr.getCreatedAt()); } } catch (IOException e) { LOGGER.log(Level.WARNING, "Unable to get date for new PR", e); setUpdated(new Date()); } if (StringUtils.isEmpty(this.head)) { GHCommitPointer prHead = pr.getHead(); setHead(prHead.getSha()); } if (StringUtils.isEmpty(this.base)) { GHCommitPointer prBase = pr.getBase(); setBase(prBase.getSha()); } } }
protected PullRequestInfo extractPullRequestInfo(GHEvent event, String payload, GitHub gh) throws IOException { switch (event) { case ISSUE_COMMENT: { GHEventPayload.IssueComment commentPayload = gh.parseEventPayload(new StringReader(payload), GHEventPayload.IssueComment.class); int issueNumber = commentPayload.getIssue().getNumber(); return new PullRequestInfo(commentPayload.getRepository().getFullName(), issueNumber); } case PULL_REQUEST: { GHEventPayload.PullRequest pr = gh.parseEventPayload(new StringReader(payload), GHEventPayload.PullRequest.class); return new PullRequestInfo(pr.getPullRequest().getRepository().getFullName(), pr.getNumber(), pr.getPullRequest().getBase().getRef()); } default: throw new IllegalStateException(format("Did you add event %s in events() method?", event)); } } }
PullRequestAction(GHPullRequest pr) { number = pr.getNumber(); url = pr.getHtmlUrl(); title = pr.getTitle(); userLogin = pr.getUser().getLogin(); baseRef = pr.getBase().getRef(); }
@Override public PullRequestStatus apply(GHPullRequest input) { int prID = GHUtils.prIdFrom(input.getDiffUrl().toString()); try { GHUser user = input.getUser(); return new PullRequestStatus(prID, input.getHead().getSha(), mergedSHA, input.getHead().getLabel(), input.getBase().getLabel(), input.getHtmlUrl().toString(), user.getName(), user.getEmail(), input.getBody(), input.getTitle()); } catch (IOException e) { throw new RuntimeException(e); } } };
/** * {@inheritDoc} */ @Override public boolean isExcluded(@NonNull SCMSourceRequest request, @NonNull SCMHead head) { if (head instanceof BranchSCMHead && request instanceof GitHubSCMSourceRequest) { for (GHPullRequest p : ((GitHubSCMSourceRequest) request).getPullRequests()) { GHRepository headRepo = p.getHead().getRepository(); if (headRepo != null // head repo can be null if the PR is from a repo that has been deleted && p.getBase().getRepository().getFullName().equalsIgnoreCase(headRepo.getFullName()) && p.getHead().getRef().equals(head.getName())) { return true; } } } return false; } }
/** * {@inheritDoc} */ @Override public boolean isExcluded(@NonNull SCMSourceRequest request, @NonNull SCMHead head) { if (head instanceof BranchSCMHead && request instanceof GitHubSCMSourceRequest) { for (GHPullRequest p : ((GitHubSCMSourceRequest) request).getPullRequests()) { GHRepository headRepo = p.getHead().getRepository(); if (headRepo != null // head repo can be null if the PR is from a repo that has been deleted && p.getBase().getRepository().getFullName().equalsIgnoreCase(headRepo.getFullName()) && p.getHead().getRef().equals(head.getName())) { return false; } } return true; } return false; } }
.setBaseRef(pullRequest.getBase()) .setHeadRef(pullRequest.getHead()); return Optional.of(result);
PullRequestSCMHead(GHPullRequest pr, String name, boolean merge) { super(name); // the merge flag is encoded into the name, so safe to store here this.merge = merge; this.number = pr.getNumber(); this.target = new BranchSCMHead(pr.getBase().getRef()); // the source stuff is immutable for a pull request on github, so safe to store here GHRepository repository = pr.getHead().getRepository(); // may be null for deleted forks JENKINS-41246 this.sourceOwner = repository == null ? null : repository.getOwnerName(); this.sourceRepo = repository == null ? null : repository.getName(); this.sourceBranch = pr.getHead().getRef(); this.origin = pr.getRepository().getOwnerName().equalsIgnoreCase(sourceOwner) ? SCMHeadOrigin.DEFAULT : new SCMHeadOrigin.Fork(this.sourceOwner); }
headRef = pr.getHead().getRef(); title = pr.getTitle(); baseRef = pr.getBase().getRef(); htmlUrl = pr.getHtmlUrl();
break; default: baseHash = pr.getBase().getSha(); break;