Search in sources :

Example 1 with PullRequestService

use of org.eclipse.egit.github.core.service.PullRequestService in project pivotal-cla by pivotalsoftware.

the class SmokeTests method createPullRequest.

/**
 * @return the HTML link of the Pull Request
 * @throws InterruptedException
 */
private static String createPullRequest(User user, int count) throws IOException, InterruptedException {
    GitHubClient client = createClient(user.getGitHubAccessToken());
    PullRequestService pulls = new PullRequestService(client);
    RestTemplate rest = new RestTemplate();
    // get sha for master
    DataService references = new DataService(client);
    RepositoryId forkRepositoryId = RepositoryId.create(user.getGitHubUsername(), "cla-test");
    Reference forked = references.getReference(forkRepositoryId, "heads/master");
    // create a branch for our Pull Request
    Reference createPullRequestBranch = new Reference();
    createPullRequestBranch.setRef("refs/heads/pull-" + count);
    createPullRequestBranch.setObject(forked.getObject());
    references.createReference(forkRepositoryId, createPullRequestBranch);
    // create a file for our Pull Request
    Map<String, String> content = new HashMap<>();
    content.put("message", "We added some content for " + count);
    content.put("content", "bXkgbmV3IGZpbGUgY29udGVudHM=");
    content.put("branch", "pull-" + count);
    rest.put("https://api.github.com/repos/{owner}/{repo}/contents/forPullRequest?access_token={token}", content, user.getGitHubUsername(), "cla-test", user.getGitHubAccessToken());
    PullRequest request = new PullRequest();
    request.setTitle("Please merge");
    request.setBody("Please merge");
    PullRequestMarker head = new PullRequestMarker();
    head.setLabel(signUser.getGitHubUsername() + ":pull-" + count);
    request.setHead(head);
    PullRequestMarker base = new PullRequestMarker();
    base.setLabel("master");
    request.setBase(base);
    Thread.sleep(TimeUnit.SECONDS.toMillis(1));
    PullRequest newPull = pulls.createPullRequest(RepositoryId.createFromId(linkUser.getGitHubUsername() + "/" + "cla-test"), request);
    Thread.sleep(TimeUnit.SECONDS.toMillis(1));
    return newPull.getHtmlUrl();
}
Also used : PullRequestService(org.eclipse.egit.github.core.service.PullRequestService) GitHubClient(org.eclipse.egit.github.core.client.GitHubClient) HashMap(java.util.HashMap) Reference(org.eclipse.egit.github.core.Reference) PullRequest(org.eclipse.egit.github.core.PullRequest) RestTemplate(org.springframework.web.client.RestTemplate) PullRequestMarker(org.eclipse.egit.github.core.PullRequestMarker) RepositoryId(org.eclipse.egit.github.core.RepositoryId) DataService(org.eclipse.egit.github.core.service.DataService)

Example 2 with PullRequestService

use of org.eclipse.egit.github.core.service.PullRequestService in project pivotal-cla by pivotalsoftware.

the class MylynGitHubApi method createUpdatePullRequestStatuses.

@Override
@SneakyThrows
public List<PullRequestStatus> createUpdatePullRequestStatuses(MigratePullRequestStatusRequest request) {
    GitHubClient client = createClient(request.getAccessToken());
    PullRequestService pullRequestService = new PullRequestService(client);
    String commitStatusUrl = request.getCommitStatusUrl();
    String accessToken = request.getAccessToken();
    List<PullRequestStatus> results = new ArrayList<>();
    for (String repositoryId : request.getRepositoryIds()) {
        RepositoryId repository = RepositoryId.createFromId(repositoryId);
        List<PullRequest> repositoryPullRequests = pullRequestService.getPullRequests(repository, "open");
        for (PullRequest pullRequest : repositoryPullRequests) {
            PullRequestStatus status = new PullRequestStatus();
            String sha = pullRequest.getHead().getSha();
            String syncUrl = UriComponentsBuilder.fromHttpUrl(request.getBaseSyncUrl()).queryParam("repositoryId", repositoryId).queryParam("pullRequestId", pullRequest.getNumber()).build().toUriString();
            status.setPullRequestId(pullRequest.getNumber());
            status.setRepoId(repositoryId);
            status.setSha(sha);
            status.setGitHubUsername(pullRequest.getUser().getLogin());
            status.setUrl(commitStatusUrl);
            status.setAccessToken(accessToken);
            status.setFaqUrl(request.getFaqUrl());
            status.setSyncUrl(syncUrl);
            status.setPullRequestState(pullRequest.getState());
            results.add(status);
        }
    }
    return results;
}
Also used : PullRequestService(org.eclipse.egit.github.core.service.PullRequestService) GitHubClient(org.eclipse.egit.github.core.client.GitHubClient) PullRequest(org.eclipse.egit.github.core.PullRequest) RepositoryId(org.eclipse.egit.github.core.RepositoryId) SneakyThrows(lombok.SneakyThrows)

Example 3 with PullRequestService

use of org.eclipse.egit.github.core.service.PullRequestService in project pivotal-cla by pivotalsoftware.

the class MylynGitHubApi method findPullRequest.

@Override
@SneakyThrows
public Optional<PullRequest> findPullRequest(String repoId, int pullRequestId, String accessToken) {
    GitHubClient client = createClient(accessToken);
    PullRequestService service = new PullRequestService(client);
    try {
        return Optional.ofNullable(service.getPullRequest(RepositoryId.createFromId(repoId), pullRequestId));
    } catch (RequestException e) {
        if (e.getStatus() == HttpStatus.NOT_FOUND.value()) {
            return Optional.empty();
        }
        throw e;
    }
}
Also used : PullRequestService(org.eclipse.egit.github.core.service.PullRequestService) GitHubClient(org.eclipse.egit.github.core.client.GitHubClient) RequestException(org.eclipse.egit.github.core.client.RequestException) SneakyThrows(lombok.SneakyThrows)

Example 4 with PullRequestService

use of org.eclipse.egit.github.core.service.PullRequestService in project jbpm-work-items by kiegroup.

the class MergePullRequestWorkitemHandler method executeWorkItem.

public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) {
    try {
        Map<String, Object> results = new HashMap<String, Object>();
        String repoOwner = (String) workItem.getParameter("RepoOwner");
        String repoName = (String) workItem.getParameter("RepoName");
        String pullRequestNum = (String) workItem.getParameter("PullRequestNum");
        String commitMessage = (String) workItem.getParameter("CommitMessage");
        MergeStatus mergeStatus;
        if (StringUtils.isNotEmpty(repoOwner) && StringUtils.isNotEmpty(repoName) && StringUtils.isNumeric(pullRequestNum)) {
            PullRequestService pullRequestService = auth.getPullRequestService(this.userName, this.password);
            RepositoryId repositoryId = new RepositoryId(repoOwner, repoName);
            if (pullRequestService.getPullRequest(repositoryId, Integer.parseInt(pullRequestNum)).isMergeable()) {
                mergeStatus = pullRequestService.merge(repositoryId, Integer.parseInt(pullRequestNum), commitMessage);
                results.put(RESULTS_VALUE, mergeStatus.isMerged());
            } else {
                results.put(RESULTS_VALUE, false);
            }
            workItemManager.completeWorkItem(workItem.getId(), results);
        } else {
            logger.error("Missing repository and pull request info.");
            throw new IllegalArgumentException("Missing repository and pull request info.");
        }
    } catch (Exception e) {
        handleException(e);
    }
}
Also used : PullRequestService(org.eclipse.egit.github.core.service.PullRequestService) HashMap(java.util.HashMap) MergeStatus(org.eclipse.egit.github.core.MergeStatus) RepositoryId(org.eclipse.egit.github.core.RepositoryId)

Example 5 with PullRequestService

use of org.eclipse.egit.github.core.service.PullRequestService in project pivotal-cla by pivotalsoftware.

the class MylynGitHubApi method getShaForPullRequest.

@SneakyThrows
public String getShaForPullRequest(PullRequestId pullRequestId) {
    PullRequestService service = getPullRequestService();
    PullRequest pullRequest = service.getPullRequest(pullRequestId.getRepositoryId(), pullRequestId.getId());
    if (pullRequest == null) {
        throw new IllegalArgumentException(String.format("Cannot find Pull-request %s#%s", pullRequestId.getRepositoryId(), pullRequestId.getId()));
    }
    return pullRequest.getHead().getSha();
}
Also used : PullRequestService(org.eclipse.egit.github.core.service.PullRequestService) PullRequest(org.eclipse.egit.github.core.PullRequest) SneakyThrows(lombok.SneakyThrows)

Aggregations

PullRequestService (org.eclipse.egit.github.core.service.PullRequestService)6 SneakyThrows (lombok.SneakyThrows)4 PullRequest (org.eclipse.egit.github.core.PullRequest)4 RepositoryId (org.eclipse.egit.github.core.RepositoryId)4 GitHubClient (org.eclipse.egit.github.core.client.GitHubClient)4 HashMap (java.util.HashMap)2 MergeStatus (org.eclipse.egit.github.core.MergeStatus)1 PullRequestMarker (org.eclipse.egit.github.core.PullRequestMarker)1 Reference (org.eclipse.egit.github.core.Reference)1 RequestException (org.eclipse.egit.github.core.client.RequestException)1 DataService (org.eclipse.egit.github.core.service.DataService)1 RestTemplate (org.springframework.web.client.RestTemplate)1