Search in sources :

Example 1 with UrlBuilder

use of io.pivotal.cla.mvc.util.UrlBuilder in project pivotal-cla by pivotalsoftware.

the class AdminLinkClaController method linkCla.

@RequestMapping(value = "/admin/cla/link", method = RequestMethod.POST)
public String linkCla(@AuthenticationPrincipal User user, HttpServletRequest request, Map<String, Object> model, @Valid LinkClaForm linkClaForm, BindingResult result, RedirectAttributes attrs) throws Exception {
    if (result.hasErrors()) {
        model.put("licenses", findPrimaryClas());
        model.put("accessTokensUrl", ACCESS_TOKENS_URL);
        model.put("repositories", gitHub.findRepositoryNamesWithAdminPermission(user.getAccessToken()));
        return "admin/cla/link";
    }
    AccessToken accessToken = tokenRepo.findOne(AccessToken.CLA_ACCESS_TOKEN_ID);
    UrlBuilder pullRequestUrlBldr = UrlBuilder.fromRequest(request);
    UrlBuilder signClaUrlBldr = UrlBuilder.fromRequest(request);
    String urlEncodedClaName = URLEncoder.encode(linkClaForm.getClaName(), "UTF-8");
    String pullRequestHookUrl = pullRequestUrlBldr.path(UrlBuilder.pullRequestHookCallbackPath(linkClaForm.getClaName())).build();
    String signClaUrl = signClaUrlBldr.path("/sign/" + urlEncodedClaName).build();
    CreatePullRequestHookRequest createPullRequest = new CreatePullRequestHookRequest();
    createPullRequest.setAccessToken(user.getAccessToken());
    List<String> repositoryIds = linkClaForm.getRepositories();
    createPullRequest.setRepositoryIds(repositoryIds);
    createPullRequest.setGitHubEventUrl(pullRequestHookUrl);
    createPullRequest.setSecret(accessToken.getToken());
    ContributingUrlsResponse contributingUrls = gitHub.getContributingUrls(repositoryIds);
    List<String> hookUrls = gitHub.createPullRequestHooks(createPullRequest);
    for (String repositoryId : repositoryIds) {
        AccessToken token = new AccessToken();
        token.setId(repositoryId);
        token.setToken(user.getAccessToken());
        tokenRepo.save(token);
    }
    UpdatePullRequestStatusesForm updatePullRequestStatusesForm = new UpdatePullRequestStatusesForm();
    updatePullRequestStatusesForm.setClaName(linkClaForm.getClaName());
    updatePullRequestStatusesForm.setRepositories(repositoryIds);
    attrs.addFlashAttribute("signClaUrl", signClaUrl);
    attrs.addFlashAttribute("hookUrls", hookUrls);
    attrs.addFlashAttribute("success", true);
    attrs.addFlashAttribute("editContributingAdocUrls", contributingUrls.getAsciidoc());
    attrs.addFlashAttribute("editContributingMdUrls", contributingUrls.getMarkdown());
    attrs.addFlashAttribute("updatePullRequestStatusesForm", updatePullRequestStatusesForm);
    return "redirect:/admin/cla/link";
}
Also used : CreatePullRequestHookRequest(io.pivotal.cla.service.github.CreatePullRequestHookRequest) AccessToken(io.pivotal.cla.data.AccessToken) ContributingUrlsResponse(io.pivotal.cla.service.github.ContributingUrlsResponse) UrlBuilder(io.pivotal.cla.mvc.util.UrlBuilder) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with UrlBuilder

use of io.pivotal.cla.mvc.util.UrlBuilder in project pivotal-cla by pivotalsoftware.

the class AdminLinkClaController method updatePullRequestStatuses.

@RequestMapping(value = "/admin/cla/link/migrate", method = RequestMethod.POST)
public String updatePullRequestStatuses(@AuthenticationPrincipal User user, @ModelAttribute UpdatePullRequestStatusesForm updatePullRequestStatusesForm, HttpServletRequest request) throws Exception {
    String claName = updatePullRequestStatusesForm.getClaName();
    String urlEncodedClaName = URLEncoder.encode(claName, "UTF-8");
    UrlBuilder signClaUrlBldr = UrlBuilder.fromRequest(request);
    String signClaUrl = signClaUrlBldr.path("/sign/" + urlEncodedClaName).build();
    UrlBuilder aboutUrlBldr = UrlBuilder.fromRequest(request);
    String aboutUrl = aboutUrlBldr.path("/about").build();
    UrlBuilder baseSyncUrlBldr = UrlBuilder.fromRequest(request);
    String baseSyncUrl = baseSyncUrlBldr.path("/sync/" + urlEncodedClaName).build();
    MigratePullRequestStatusRequest migratePullRequests = MigratePullRequestStatusRequest.builder().accessToken(user.getAccessToken()).commitStatusUrl(signClaUrl).repositoryIds(updatePullRequestStatusesForm.getRepositories()).faqUrl(aboutUrl).baseSyncUrl(baseSyncUrl).build();
    claService.migratePullRequestStatus(updatePullRequestStatusesForm.getClaName(), migratePullRequests);
    return "redirect:/admin/cla/link";
}
Also used : MigratePullRequestStatusRequest(io.pivotal.cla.service.MigratePullRequestStatusRequest) UrlBuilder(io.pivotal.cla.mvc.util.UrlBuilder) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

UrlBuilder (io.pivotal.cla.mvc.util.UrlBuilder)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 AccessToken (io.pivotal.cla.data.AccessToken)1 MigratePullRequestStatusRequest (io.pivotal.cla.service.MigratePullRequestStatusRequest)1 ContributingUrlsResponse (io.pivotal.cla.service.github.ContributingUrlsResponse)1 CreatePullRequestHookRequest (io.pivotal.cla.service.github.CreatePullRequestHookRequest)1