Search in sources :

Example 1 with ClaPullRequestStatusRequest

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";
}
Also used : ContributorLicenseAgreement(io.pivotal.cla.data.ContributorLicenseAgreement) ClaPullRequestStatusRequest(io.pivotal.cla.service.ClaPullRequestStatusRequest) CorporateSignature(io.pivotal.cla.data.CorporateSignature) Date(java.util.Date) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ClaPullRequestStatusRequest

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;
}
Also used : ClaPullRequestStatusRequest(io.pivotal.cla.service.ClaPullRequestStatusRequest) PullRequestStatus(io.pivotal.cla.service.github.PullRequestStatus)

Example 3 with ClaPullRequestStatusRequest

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";
}
Also used : ContributorLicenseAgreement(io.pivotal.cla.data.ContributorLicenseAgreement) ClaPullRequestStatusRequest(io.pivotal.cla.service.ClaPullRequestStatusRequest) Date(java.util.Date) IndividualSignature(io.pivotal.cla.data.IndividualSignature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with ClaPullRequestStatusRequest

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");
}
Also used : Repository(org.eclipse.egit.github.core.Repository) User(org.eclipse.egit.github.core.User) ClaPullRequestStatusRequest(io.pivotal.cla.service.ClaPullRequestStatusRequest) PullRequest(org.eclipse.egit.github.core.PullRequest) Gson(com.google.gson.Gson) RepositoryAware(io.pivotal.cla.egit.github.core.event.RepositoryAware) PullRequestStatus(io.pivotal.cla.service.github.PullRequestStatus) RepositoryId(org.eclipse.egit.github.core.RepositoryId) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with ClaPullRequestStatusRequest

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;
}
Also used : ClaPullRequestStatusRequest(io.pivotal.cla.service.ClaPullRequestStatusRequest) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute)

Aggregations

ClaPullRequestStatusRequest (io.pivotal.cla.service.ClaPullRequestStatusRequest)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ContributorLicenseAgreement (io.pivotal.cla.data.ContributorLicenseAgreement)2 PullRequestStatus (io.pivotal.cla.service.github.PullRequestStatus)2 Date (java.util.Date)2 PullRequest (org.eclipse.egit.github.core.PullRequest)2 Gson (com.google.gson.Gson)1 CorporateSignature (io.pivotal.cla.data.CorporateSignature)1 IndividualSignature (io.pivotal.cla.data.IndividualSignature)1 RepositoryAware (io.pivotal.cla.egit.github.core.event.RepositoryAware)1 Repository (org.eclipse.egit.github.core.Repository)1 RepositoryId (org.eclipse.egit.github.core.RepositoryId)1 User (org.eclipse.egit.github.core.User)1 ModelAttribute (org.springframework.web.bind.annotation.ModelAttribute)1