use of io.pivotal.cla.egit.github.core.ContextCommitStatus in project pivotal-cla by pivotalsoftware.
the class MylynGitHubApi method createOrUpdatePullRequestComment.
private void createOrUpdatePullRequestComment(PullRequestId pullRequestId, PullRequestStatus commitStatus, boolean hasSignedCla, boolean obviousFix, ContextCommitStatus status, List<Comment> comments, String claUserLogin) throws IOException {
String claLinkMarkdown = String.format("[%s](%s)", CONTRIBUTOR_LICENSE_AGREEMENT, status.getUrl());
String userMentionMarkdown = String.format("@%s", commitStatus.getGitHubUsername());
IssueService issues = getIssueService();
List<Comment> claUserComments = //
comments.stream().filter(//
comment -> comment.getUser().getLogin().equals(claUserLogin)).collect(Collectors.toList());
if (hasSignedCla) {
String body = String.format("%s %s %s!", userMentionMarkdown, THANK_YOU, claLinkMarkdown);
if (claUserComments.stream().anyMatch(c -> c.getBody().contains(PLEASE_SIGN))) {
if (claUserComments.stream().anyMatch(c -> c.getBody().contains(THANK_YOU))) {
return;
}
issues.createComment(pullRequestId.getRepositoryId(), commitStatus.getPullRequestId(), body);
}
} else {
String sync = String.format("\n\n[Click here](%s) %s.", commitStatus.getSyncUrl(), TO_MANUALLY_SYNCHRONIZE_THE_STATUS);
String faq = String.format("\n\nSee the [FAQ](%s) for %s.", commitStatus.getFaqUrl(), FREQUENTLY_ASKED_QUESTIONS);
String oldBody = String.format("%s %s %s!", userMentionMarkdown, PLEASE_SIGN, claLinkMarkdown);
String body = String.format("%s%s%s", oldBody, sync, faq);
if (obviousFix) {
if (claUserComments.stream().anyMatch(c -> c.getBody().contains(PLEASE_SIGN)) && claUserComments.stream().noneMatch(comment -> comment.getBody().contains(THIS_PR_CONTAINS_AN_OBVIOUS_FIX))) {
createObviousFixCommentIfNecessary(pullRequestId, userMentionMarkdown, issues, claUserComments);
}
return;
}
if (claUserComments.stream().anyMatch(c -> c.getBody().contains(FREQUENTLY_ASKED_QUESTIONS) && c.getBody().contains(TO_MANUALLY_SYNCHRONIZE_THE_STATUS))) {
return;
}
Optional<Comment> oldComment = claUserComments.stream().filter(c -> c.getBody().trim().contains(PLEASE_SIGN)).findFirst();
if (oldComment.isPresent()) {
Comment toEdit = oldComment.get();
toEdit.setBody(body);
issues.editComment(pullRequestId.getRepositoryId(), toEdit);
} else {
issues.createComment(pullRequestId.getRepositoryId(), pullRequestId.getId(), body);
}
}
}
use of io.pivotal.cla.egit.github.core.ContextCommitStatus in project pivotal-cla by pivotalsoftware.
the class MylynGitHubApi method createCommitStatusIfNecessary.
private ContextCommitStatus createCommitStatusIfNecessary(PullRequestId pullRequestId, PullRequestStatus commitStatus, boolean hasSignedCla, boolean obviousFix, GitHubClient client) {
ContextCommitService commitService = new ContextCommitService(client);
ContextCommitStatus status = new ContextCommitStatus();
String description;
if (obviousFix) {
description = OBVIOUS_FIX_CLA_NOT_REQUIRED;
} else if (hasSignedCla) {
description = String.format("%s %s!", THANK_YOU, CONTRIBUTOR_LICENSE_AGREEMENT);
} else {
description = String.format("%s %s!", PLEASE_SIGN, CONTRIBUTOR_LICENSE_AGREEMENT);
}
status.setDescription(description);
status.setState((hasSignedCla || obviousFix) ? CommitStatus.STATE_SUCCESS : CommitStatus.STATE_FAILURE);
status.setContext("ci/pivotal-cla");
status.setUrl(commitStatus.getUrl());
status.setTargetUrl(status.getUrl());
List<ContextCommitStatus> statuses = commitService.getContextStatuses(pullRequestId.getRepositoryId(), commitStatus.getSha());
if (!statuses.stream().anyMatch(s -> matches(status, s))) {
commitService.createStatus(pullRequestId.getRepositoryId(), commitStatus.getSha(), status);
}
return status;
}
use of io.pivotal.cla.egit.github.core.ContextCommitStatus in project pivotal-cla by pivotalsoftware.
the class MylynGitHubApi method save.
@SneakyThrows
public void save(PullRequestStatus commitStatus) {
String repoId = commitStatus.getRepoId();
String accessToken = commitStatus.getAccessToken();
if (accessToken == null) {
return;
}
PullRequestId pullRequestId = PullRequestId.of(RepositoryId.createFromId(repoId), commitStatus.getPullRequestId());
boolean hasSignedCla = commitStatus.isSuccess();
GitHubClient client = createClient(accessToken);
String claUserLogin = getGitHubClaUserLogin();
List<Comment> comments = getComments(pullRequestId, getIssueService());
boolean obviousFix = isObviousFix(pullRequestId, comments, claUserLogin, commitStatus.getPullRequestBody());
ContextCommitStatus status = createCommitStatusIfNecessary(pullRequestId, commitStatus, hasSignedCla, obviousFix, client);
createOrUpdatePullRequestComment(pullRequestId, commitStatus, hasSignedCla, obviousFix, status, comments, claUserLogin);
}
Aggregations