@CheckForNull public URL getGithubUrl(@Nullable InputComponent inputComponent, @Nullable Integer issueLine) { if (inputComponent instanceof InputPath) { String path = getPath((InputPath) inputComponent); URL url1 = ghRepo.getHtmlUrl(); try { return new URI(url1.getProtocol(), null, url1.getHost(), url1.getPort(), url1.getFile() + "/blob/" + pr.getHead().getSha() + "/" + path, null, issueLine != null ? ("L" + issueLine) : "").toURL(); } catch (MalformedURLException | URISyntaxException e) { LOG.error("Invalid URL", e); } } return null; }
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; }
/** * Obtains the commit that this pointer is referring to. */ public GHCommit getCommit() throws IOException { return getRepository().getCommit(getSha()); }
/** * Does this repository match the repository referenced in the given {@link GHCommitPointer}? */ public boolean matches(GHCommitPointer commit) { final GHUser user; try { user = commit.getUser(); } catch (IOException ex) { LOGGER.debug("Failed to extract user from commit " + commit, ex); return false; } return userName.equals(user.getLogin()) && repositoryName.equals(commit.getRepository().getName()) && host.equals(commit.getRepository().getHtmlUrl().getHost()); }
/** * {@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; } }
String prOwnerName = ghPullRequest.getHead().getUser().getLogin(); if (!prOwnerName.matches(GitHubSCMSource.VALID_GITHUB_USER_NAME)) { if (!ghPullRequest.getBase().getSha().matches(GitHubSCMSource.VALID_GIT_SHA1)) { if (!ghPullRequest.getHead().getSha().matches(GitHubSCMSource.VALID_GIT_SHA1)) { .withTraits(src.getTraits()); if (!fork && context.wantBranches()) { final String branchName = ghPullRequest.getHead().getRef(); SCMHead head = new BranchSCMHead(branchName); boolean excluded = false; new AbstractGitSCMSource.SCMRevisionImpl(head, ghPullRequest.getHead().getSha()); result.put(head, hash); revision = new PullRequestSCMRevision( head, ghPullRequest.getBase().getSha(), ghPullRequest.getHead().getSha() ); break;
@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); } } };
private Commit createCommitForMetrics(PullRequest prInformation, boolean base) { Commit commit = new Commit(); GHCommitPointer ghCommitPointer; GHCommit ghCommit; if (base) { ghCommitPointer = prInformation.getBaseRef(); } else { ghCommitPointer = prInformation.getHeadRef(); } try { ghCommit = ghCommitPointer.getCommit(); String branchLabel = ghCommitPointer.getLabel(); String branchName = branchLabel.substring(branchLabel.indexOf(":") + 1, branchLabel.length()); commit.setRepoName(ghCommitPointer.getRepository().getFullName()); commit.setBranchName(branchName); commit.setSha(ghCommit.getSHA1()); commit.setUrl(ghCommit.getHtmlUrl().toString()); commit.setDate(ghCommit.getCommitDate()); return commit; } catch (IOException e) { this.addStepError("Exception while writing properties related to commits.", e); } return null; }
public String getAuthorRepoGitUrl() { GHCommitPointer prHead = pr.getHead(); String authorRepoGitUrl = ""; if (prHead != null && prHead.getRepository() != null) { authorRepoGitUrl = prHead.getRepository().gitHttpTransportUrl(); } return authorRepoGitUrl; }
private GHPullRequest getPullRequestWithPullReqIdentifier(GHRepository parent) throws IOException { List<GHPullRequest> pullRequests; GHUser myself; try { pullRequests = parent.getPullRequests(GHIssueState.OPEN); myself = gitHubUtil.getMyself(); } catch (IOException e) { log.warn("Error occurred while retrieving pull requests for {}", parent.getFullName()); return null; } for (GHPullRequest pullRequest : pullRequests) { GHUser user = pullRequest.getHead().getUser(); if (myself.equals(user) && pullRequest.getBody().equals(Constants.PULL_REQ_ID)) { return pullRequest; } } return null; } }
/** * {@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; } }
PullRequest prInformation = new PullRequest(); GHRepository headRepo = pullRequest.getHead().getRepository();
private GHPullRequest getPullRequestWithPullReqIdentifier(GHRepository parent) throws IOException { List<GHPullRequest> pullRequests; GHUser myself; try { pullRequests = parent.getPullRequests(GHIssueState.OPEN); myself = gitHubUtil.getMyself(); } catch (IOException e) { log.warn("Error occurred while retrieving pull requests for {}", parent.getFullName()); return null; } for (GHPullRequest pullRequest : pullRequests) { GHUser user = pullRequest.getHead().getUser(); if (myself.equals(user) && pullRequest.getBody().equals(Constants.PULL_REQ_ID)) { return pullRequest; } } return null; } }
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; }
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); }
/** * Obtains the commit that this pointer is referring to. */ public GHCommit getCommit() throws IOException { return getRepository().getCommit(getSha()); }
/** * Head and Ref are part of the PullRequest object * * @return the sha for the head. */ public String getSource() { try { return getPullRequest().getHead().getRef(); } catch (IOException e) { return "UNKNOWN"; } }