use of io.pivotal.cla.service.ClaPullRequestStatusRequest in project pivotal-cla by pivotalsoftware.
the class CclaController method signCla.
@RequestMapping(value = "/sign/{claName}/ccla", method = RequestMethod.POST)
public String signCla(@AuthenticationPrincipal User user, @Valid SignCorporateClaForm signCorporateClaForm, BindingResult result, Map<String, Object> model, RedirectAttributes redirect) throws Exception {
ContributorLicenseAgreement cla = clas.findOne(signCorporateClaForm.getClaId());
List<String> currentUserGitHubOrganizations = gitHub.getOrganizations(user.getGitHubLogin());
if (result.hasErrors()) {
model.put("cla", cla);
signCorporateClaForm.setGitHubOrganizations(currentUserGitHubOrganizations);
return "cla/ccla/sign";
}
CorporateSignature signature = new CorporateSignature();
signature.setCla(cla);
signature.setEmail(signCorporateClaForm.getEmail());
signature.setDateOfSignature(new Date());
signature.setGitHubLogin(user.getGitHubLogin());
signature.setGitHubOrganization(signCorporateClaForm.getGitHubOrganization());
signature.setTitle(signCorporateClaForm.getTitle());
signature.setCountry(signCorporateClaForm.getCountry());
signature.setName(signCorporateClaForm.getName());
signature.setMailingAddress(signCorporateClaForm.getMailingAddress());
signature.setTelephone(signCorporateClaForm.getTelephone());
signature.setCompanyName(signCorporateClaForm.getCompanyName());
corporate.save(signature);
// update github
String repositoryId = signCorporateClaForm.getRepositoryId();
Integer pullRequestId = signCorporateClaForm.getPullRequestId();
redirect.addAttribute("claName", cla.getName());
if (repositoryId == null || pullRequestId == null) {
return "redirect:/sign/{claName}/ccla";
}
ClaPullRequestStatusRequest updatePullRequest = signCorporateClaForm.createUpdatePullRequestStatus(user.getGitHubLogin());
if (updatePullRequest != null) {
updatePullRequest.getCommitStatus().setSuccess(true);
claService.savePullRequestStatus(updatePullRequest);
}
redirect.addAttribute("repositoryId", repositoryId);
redirect.addAttribute("pullRequestId", pullRequestId);
return "redirect:/sign/{claName}/ccla";
}
use of io.pivotal.cla.service.ClaPullRequestStatusRequest in project pivotal-cla by pivotalsoftware.
the class ClaRequest method createUpdatePullRequestStatus.
public ClaPullRequestStatusRequest createUpdatePullRequestStatus(String currentUserGitHubLogin) throws Exception {
if (pullRequestId == null) {
return null;
}
PullRequestStatus commitStatus = new PullRequestStatus();
commitStatus.setRepoId(repositoryId);
commitStatus.setPullRequestId(pullRequestId);
commitStatus.setUrl(signUrl());
commitStatus.setSyncUrl(syncUrl());
commitStatus.setFaqUrl(faqUrl());
commitStatus.setGitHubUsername(currentUserGitHubLogin);
commitStatus.setPullRequestState(PullRequestStatus.UNKNOWN_PULL_REQUEST_STATE);
ClaPullRequestStatusRequest request = new ClaPullRequestStatusRequest();
request.setClaName(claName);
request.setCommitStatus(commitStatus);
return request;
}
use of io.pivotal.cla.service.ClaPullRequestStatusRequest in project pivotal-cla by pivotalsoftware.
the class IclaController method signCla.
@RequestMapping(value = "/sign/{claName}/icla", method = RequestMethod.POST)
public String signCla(@AuthenticationPrincipal User user, @Valid SignClaForm signClaForm, BindingResult result, Map<String, Object> model, RedirectAttributes redirect) throws Exception {
String claName = signClaForm.getClaName();
Integer pullRequestId = signClaForm.getPullRequestId();
String repositoryId = signClaForm.getRepositoryId();
ContributorLicenseAgreement cla = clas.findOne(signClaForm.getClaId());
if (result.hasErrors()) {
model.put("cla", cla);
return "cla/icla/sign";
}
IndividualSignature signature = new IndividualSignature();
signature.setCla(cla);
signature.setName(signClaForm.getName());
signature.setCountry(signClaForm.getCountry());
signature.setEmail(signClaForm.getEmail());
signature.setMailingAddress(signClaForm.getMailingAddress());
signature.setDateOfSignature(new Date());
signature.setTelephone(signClaForm.getTelephone());
signature.setGitHubLogin(user.getGitHubLogin());
individual.save(signature);
// update github
redirect.addAttribute("claName", claName);
if (repositoryId == null || pullRequestId == null) {
return "redirect:/sign/{claName}/icla";
}
ClaPullRequestStatusRequest updatePullRequest = signClaForm.createUpdatePullRequestStatus(user.getGitHubLogin());
if (updatePullRequest != null) {
updatePullRequest.getCommitStatus().setSuccess(true);
claService.savePullRequestStatus(updatePullRequest);
}
redirect.addAttribute("repositoryId", repositoryId);
redirect.addAttribute("pullRequestId", pullRequestId);
return "redirect:/sign/{claName}/icla";
}
use of io.pivotal.cla.service.ClaPullRequestStatusRequest 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.ClaPullRequestStatusRequest in project pivotal-cla by pivotalsoftware.
the class UserControllerAdvice method importedSignature.
@ModelAttribute("importedSignature")
boolean importedSignature(@AuthenticationPrincipal User currentUser, ImportedSignaturesSessionAttr importedSignaturesSessionAttr, @ModelAttribute ClaRequest claRequest) throws Exception {
if (!importedSignaturesSessionAttr.getValue()) {
return false;
}
ClaPullRequestStatusRequest updatePullRequest = claRequest.createUpdatePullRequestStatus(currentUser.getGitHubLogin());
if (updatePullRequest != null) {
claService.savePullRequestStatus(updatePullRequest);
}
importedSignaturesSessionAttr.setValue(false);
return true;
}
Aggregations