use of org.eclipse.egit.github.core.CommitStatus 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 org.eclipse.egit.github.core.CommitStatus 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 org.eclipse.egit.github.core.CommitStatus in project camel by apache.
the class PullRequestStateProducerTest method testPullRequestStateProducer.
@Test
public void testPullRequestStateProducer() throws Exception {
commitsha = commitService.getNextSha();
Endpoint stateProducerEndpoint = getMandatoryEndpoint("direct:validPullRequest");
Exchange exchange = stateProducerEndpoint.createExchange();
String text = "Message sent at " + new Date();
exchange.getIn().setBody(text);
Exchange response = template.send(stateProducerEndpoint, exchange);
assertNotNull(response.getOut().getBody());
if (!(response.getOut().getBody() instanceof CommitStatus)) {
fail("Expecting CommitStatus");
}
CommitStatus status = response.getOut().getBody(CommitStatus.class);
// Check status set on commit service
if (commitService.getCommitStatus(commitsha) != status) {
fail("Commit status sent to service is different from response");
}
assertEquals(status.getState(), "success");
assertEquals(status.getDescription(), text);
}
use of org.eclipse.egit.github.core.CommitStatus in project camel by apache.
the class PullRequestStateProducer method process.
public void process(Exchange exchange) throws Exception {
String pullRequestNumberSHA = exchange.getIn().getHeader(GitHubConstants.GITHUB_PULLREQUEST_HEAD_COMMIT_SHA, String.class);
String text = exchange.getIn().getBody(String.class);
CommitStatus status = new CommitStatus();
if (state != null) {
status.setState(state);
}
if (targetUrl != null) {
status.setTargetUrl(targetUrl);
}
if (text != null) {
status.setDescription(text);
}
CommitStatus response = commitService.createStatus(getRepository(), pullRequestNumberSHA, status);
// copy the header of in message to the out message
exchange.getOut().copyFrom(exchange.getIn());
exchange.getOut().setBody(response);
}
Aggregations