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; }
@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; }
/** * Obtains the commit that this pointer is referring to. */ public GHCommit getCommit() throws IOException { return getRepository().getCommit(getSha()); }
/** * Obtains the commit that this pointer is referring to. */ public GHCommit getCommit() throws IOException { return getRepository().getCommit(getSha()); }
/** * Obtains the commit that this pointer is referring to. */ public GHCommit getCommit() throws IOException { return getRepository().getCommit(getSha()); }
@Override public String fetchHeadSha(GHRepository remoteRepo) throws IOException { GHPullRequest pullRequest = remoteRepo.getPullRequest(prNumber); if (pullRequest == null) { throw new IOException("No PR " + prNumber + " in " + remoteRepo.getFullName()); } return pullRequest.getHead().getSha(); }
public void createOrUpdateReviewComment(InputFile inputFile, Integer line, String body) { String fullpath = getPath(inputFile); Integer lineInPatch = patchPositionMappingByFile.get(fullpath).get(line); try { if (existingReviewCommentsByLocationByFile.containsKey(fullpath) && existingReviewCommentsByLocationByFile.get(fullpath).containsKey(lineInPatch)) { GHPullRequestReviewComment existingReview = existingReviewCommentsByLocationByFile.get(fullpath).get(lineInPatch); if (!existingReview.getBody().equals(body)) { existingReview.update(body); } reviewCommentToBeDeletedById.remove(existingReview.getId()); } else { pr.createReviewComment(body, pr.getHead().getSha(), fullpath, lineInPatch); } } catch (IOException e) { throw new IllegalStateException("Unable to create or update review comment in file " + fullpath + " at line " + line, e); } }
@Override public GitHubPRCause check(@Nonnull GitHubPRDecisionContext prDecisionContext) throws IOException { TaskListener listener = prDecisionContext.getListener(); GHPullRequest remotePR = prDecisionContext.getRemotePR(); GitHubPRPullRequest localPR = prDecisionContext.getLocalPR(); if (remotePR.getState().equals(GHIssueState.CLOSED)) { //TODO check whether push to closed allowed? return null; // already closed, nothing to check } if (isNull(localPR)) { // new return null; // not interesting for this event } GitHubPRCause cause = null; GHCommitPointer head = remotePR.getHead(); if (!localPR.getHeadSha().equals(head.getSha())) { LOGGER.debug("New commit. Sha: {} => {}", localPR.getHeadSha(), head.getSha()); final PrintStream logger = listener.getLogger(); logger.println(this.getClass().getSimpleName() + ": new commit found, sha " + head.getSha()); // GHUser user = head.getUser(); cause = prDecisionContext.newCause(DISPLAY_NAME, false); } return cause; }
@CheckForNull GHCommitStatus getCommitStatusForContext(GHPullRequest pr, String context) { List<GHCommitStatus> statuses; try { statuses = pr.getRepository().listCommitStatuses(pr.getHead().getSha()).asList(); } catch (IOException e) { throw new IllegalStateException("Unable to retrieve commit statuses.", e); } for (GHCommitStatus status : statuses) { if (context.equals(status.getContext())) { return status; } } return null; } }
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()); } } }
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; }
PagedIterable<GHCommitStatus> statuses = repository.getCommit(pullRequest.getHead().getSha()).listStatuses();
public void createOrUpdateSonarQubeStatus(GHCommitState status, String statusDescription) { try { // Copy previous targetUrl in case it was set by an external system (like the CI job). String targetUrl = null; GHCommitStatus lastStatus = getCommitStatusForContext(pr, COMMIT_CONTEXT); if (lastStatus != null) { targetUrl = lastStatus.getTargetUrl(); } ghRepo.createCommitStatus(pr.getHead().getSha(), status, targetUrl, statusDescription, COMMIT_CONTEXT); } catch (FileNotFoundException e) { String msg = "Unable to set pull request status. GitHub account probably miss push permission on the repository."; if (LOG.isDebugEnabled()) { LOG.warn(msg, e); } else { LOG.warn(msg); } } catch (IOException e) { throw new IllegalStateException("Unable to update commit status", e); } }
@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); } } };
if (!ghPullRequest.getBase().getSha().matches(GitHubSCMSource.VALID_GIT_SHA1)) { if (!ghPullRequest.getHead().getSha().matches(GitHubSCMSource.VALID_GIT_SHA1)) { new AbstractGitSCMSource.SCMRevisionImpl(head, ghPullRequest.getHead().getSha()); result.put(head, hash); revision = new PullRequestSCMRevision( head, ghPullRequest.getBase().getSha(), ghPullRequest.getHead().getSha() ); break;
.append(localPR.getIssueUpdatedAt(), remotePR.getIssueUpdatedAt()).build() < 0; boolean headUpd = !StringUtils.equals(localPR.getHeadSha(), remotePR.getHead().getSha()); // or head? boolean updated = prUpd || issueUpd || headUpd;
public org.kohsuke.github.GHCommit getHeadCommitForBranch(final String branch) throws IOException { String sha; final GitBranch gitBranch = new GitBranch(branch); if (gitBranch.isPullRequest()) { try { sha = getGithubRepository().getPullRequest(gitBranch.pullRequestNumber()).getHead().getSha(); } catch (final IOException e) { throw new RuntimeException(e); } } else { try { final GHRef ref = getRef("heads/" + gitBranch); sha = ref.getObject().getSha(); } catch (final IOException e) { sha = gitBranch.toString(); } } return getGithubRepository().getCommit(sha); }
headSha = pr.getHead().getSha(); headRef = pr.getHead().getRef(); title = pr.getTitle();
try { GHCommitStatus status = getLastCommitStatus(ghRepository, pullRequest); ghRepository.getLastCommitStatus(pullRequest.getHead().getSha()); if (status != null) { GHCommitState state = status.getState();