use of io.pivotal.cla.service.github.PullRequestStatus in project pivotal-cla by pivotalsoftware.
the class GitHubHooksControllerTests method markCommitStatusSuccessIndividualAcceptingReviewComments.
@Test
public void markCommitStatusSuccessIndividualAcceptingReviewComments() throws Exception {
User user = WithSigningUserFactory.create();
when(mockUserRepo.findOne(anyString())).thenReturn(user);
when(mockTokenRepo.findOne("rwinch/176_test")).thenReturn(new AccessToken("rwinch/176_test", "mock_access_token_value"));
when(mockIndividualSignatureRepository.findSignaturesFor(any(), any(), anyString())).thenReturn(Arrays.asList(individualSignature));
mockMvc.perform(hookRequest().header("X-GitHub-Event", GithubEvents.PULL_REQUEST_REVIEW_COMMENT).content(getPayload("pull_request_review_comment.json"))).andExpect(status().isOk());
ArgumentCaptor<PullRequestStatus> statusCaptor = ArgumentCaptor.forClass(PullRequestStatus.class);
verify(mockGitHub).save(statusCaptor.capture());
PullRequestStatus status = statusCaptor.getValue();
assertThat(status.getRepoId()).isEqualTo("rwinch/176_test");
assertThat(status.getAccessToken()).isEqualTo("mock_access_token_value");
assertThat(status.getPullRequestId()).isEqualTo(2);
assertThat(status.getSha()).isEqualTo("a6befb598a35c1c206e1bf7bbb3018f4403b9610");
assertThat(status.getUrl()).isEqualTo("http://localhost/sign/pivotal?repositoryId=rwinch/176_test&pullRequestId=2");
assertThat(status.isSuccess()).isTrue();
assertThat(status.getGitHubUsername()).isEqualTo(user.getGitHubLogin());
assertThat(status.getPullRequestBody()).isNotEmpty();
}
use of io.pivotal.cla.service.github.PullRequestStatus in project pivotal-cla by pivotalsoftware.
the class GitHubHooksController method pullRequest.
/**
* @param request
* @param body
* @param cla
* @param githubEvent
* @return
* @throws Exception
*/
@RequestMapping("/github/hooks/pull_request/{cla}")
public ResponseEntity<String> pullRequest(HttpServletRequest request, @RequestBody String body, @PathVariable String cla, @RequestHeader("X-GitHub-Event") String githubEvent) throws Exception {
if (!ACCEPTED_EVENTS.contains(githubEvent)) {
return ResponseEntity.badRequest().body(String.format("X-Github-Event: %s not acceptable", githubEvent));
}
Gson gson = GsonUtils.createGson();
RepositoryAware payload = gson.fromJson(body, PAYLOAD_TYPES.get(githubEvent));
PullRequest pullRequest = getPullRequest(payload);
if (pullRequest == null) {
return ResponseEntity.badRequest().body("Not related to a Pull request");
}
User senderUser = getSender(payload);
if (senderUser.getLogin().equals(gitHubApi.getGitHubClaUserLogin())) {
return ResponseEntity.ok("Skipping self-events");
}
User user = getPullRequestUser(payload);
Repository repository = payload.getRepository();
RepositoryId repoId = RepositoryId.createFromId(repository.getOwner().getLogin() + "/" + repository.getName());
String sha = getPullRequestSha(repoId, pullRequest);
String gitHubLogin = user.getLogin();
PullRequestStatus status = new PullRequestStatus();
status.setGitHubUsername(gitHubLogin);
status.setPullRequestId(pullRequest.getNumber());
status.setPullRequestBody(pullRequest.getBody());
status.setRepoId(repoId.generateId());
status.setSha(sha);
String signUrl = UrlBuilder.signUrl().request(request).claName(cla).repositoryId(status.getRepoId()).pullRequestId(status.getPullRequestId()).build();
status.setUrl(signUrl);
status.setPullRequestState(pullRequest.getState());
String syncUrl = UrlBuilder.createSyncUrl(request, cla, status.getRepoId(), status.getPullRequestId());
status.setSyncUrl(syncUrl);
String faqUrl = UrlBuilder.createAboutUrl(request);
status.setFaqUrl(faqUrl);
ClaPullRequestStatusRequest pullRequestStatusRequest = new ClaPullRequestStatusRequest();
pullRequestStatusRequest.setClaName(cla);
pullRequestStatusRequest.setCommitStatus(status);
claService.savePullRequestStatus(pullRequestStatusRequest);
return ResponseEntity.ok("SUCCESS");
}
use of io.pivotal.cla.service.github.PullRequestStatus in project pivotal-cla by pivotalsoftware.
the class ClaService method savePullRequestStatus.
public void savePullRequestStatus(ClaPullRequestStatusRequest request) {
String claName = request.getClaName();
PullRequestStatus commitStatus = request.getCommitStatus();
String gitHubLogin = commitStatus.getGitHubUsername();
if (commitStatus.getAccessToken() == null) {
AccessToken accessToken = accessTokenRepository.findOne(commitStatus.getRepoId());
if (accessToken == null) {
return;
}
String token = accessToken.getToken();
commitStatus.setAccessToken(token);
}
if (commitStatus.getSha() == null) {
String sha = gitHub.getShaForPullRequest(commitStatus);
if (sha == null) {
return;
}
commitStatus.setSha(sha);
}
if (commitStatus.getSuccess() == null) {
boolean hasSigned = hasSigned(gitHubLogin, claName);
commitStatus.setSuccess(hasSigned);
}
gitHub.save(commitStatus);
}
Aggregations