Search in sources :

Example 6 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(PullRequestStatus commitStatus) {
    String repositoryId = commitStatus.getRepoId();
    int pullRequestId = commitStatus.getPullRequestId();
    String currentUserGitHubLogin = commitStatus.getGitHubUsername();
    String accessToken = commitStatus.getAccessToken();
    if (accessToken == null) {
        return null;
    }
    GitHubClient client = createClient(accessToken);
    RepositoryId id = RepositoryId.createFromId(repositoryId);
    PullRequestService service = new PullRequestService(client);
    PullRequest pullRequest = service.getPullRequest(id, pullRequestId);
    String githubLoginForContributor = pullRequest.getUser().getLogin();
    if (commitStatus.isAdmin()) {
        commitStatus.setGitHubUsername(githubLoginForContributor);
    } else if (!githubLoginForContributor.equals(currentUserGitHubLogin)) {
        return null;
    }
    return pullRequest.getHead().getSha();
}
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)

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