GHCommitState state = status.getState(); String key = status.getTargetUrl(); if (key == null) { continue;
public Map<String, List<GHCommitStatus>> getCommitStatuses() throws IOException { final GHRepository githubRepository = this.build.getGithubRepository(); final List<GHCommitStatus> commitStatuses = githubRepository.getCommit(this.build.getSha()).listStatuses().asList(); final Map<String, List<GHCommitStatus>> groupedStatuses = new HashMap<>(); for (final GHCommitStatus status : commitStatuses) { final String context = status.getContext(); if (groupedStatuses.get(context) == null) { groupedStatuses.put(context, new ArrayList<>()); } groupedStatuses.get(context).add(status); } groupedStatuses.put("- Latest Status -", Arrays.asList(githubRepository.getLastCommitStatus(this.build.getSha()))); return groupedStatuses; } }
public boolean isCommitStatusOK(String githubRepo, String sha) { Optional<CommitDetails> commit = getCommitDetails(githubRepo, sha); if (commit.isPresent()) { return commit.get().getCommitStatus().getState() == GHCommitState.SUCCESS; } return false; }
/** * Creates a commit status * * @param targetUrl * Optional parameter that points to the URL that has more details. * @param description * Optional short description. * @param context * Optinal commit status context. */ public GHCommitStatus createCommitStatus(String sha1, GHCommitState state, String targetUrl, String description, String context) throws IOException { return new Requester(root) .with("state", state.name().toLowerCase(Locale.ENGLISH)) .with("target_url", targetUrl) .with("description", description) .with("context", context) .to(String.format("/repos/%s/%s/statuses/%s",owner.login,this.name,sha1),GHCommitStatus.class).wrapUp(root); }
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); } }
GHCommitStatus status = getLastCommitStatus(ghRepository, pullRequest); if (status != null) { GHCommitState state = status.getState(); if (state != null && state.equals(GHCommitState.SUCCESS)) { String message = Markdown.UPDATEBOT_ICON + " merging this pull request as its CI was successful";
/** * Creates a commit status * * @param targetUrl * Optional parameter that points to the URL that has more details. * @param description * Optional short description. * @param context * Optinal commit status context. */ public GHCommitStatus createCommitStatus(String sha1, GHCommitState state, String targetUrl, String description, String context) throws IOException { return new Requester(root) .with("state", state) .with("target_url", targetUrl) .with("description", description) .with("context", context) .to(String.format("/repos/%s/%s/statuses/%s",getOwnerName(),this.name,sha1),GHCommitStatus.class).wrapUp(root); }
ghRepository.getLastCommitStatus(pullRequest.getHead().getSha()); if (status != null) { GHCommitState state = status.getState(); if (state != null && state.equals(GHCommitState.SUCCESS) && GitHubHelpers.checkCommitStatus(ghRepository,pullRequest,GHCommitState.SUCCESS)) { String message = Markdown.UPDATEBOT_ICON + " merging this pull request as its CI was successful";
/** * Creates a commit status * * @param targetUrl * Optional parameter that points to the URL that has more details. * @param description * Optional short description. * @param context * Optinal commit status context. */ public GHCommitStatus createCommitStatus(String sha1, GHCommitState state, String targetUrl, String description, String context) throws IOException { return new Requester(root) .with("state", state) .with("target_url", targetUrl) .with("description", description) .with("context", context) .to(String.format("/repos/%s/%s/statuses/%s",getOwnerName(),this.name,sha1),GHCommitStatus.class).wrapUp(root); }
@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; } }