Search in sources :

Example 1 with RequestException

use of org.eclipse.egit.github.core.client.RequestException 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 2 with RequestException

use of org.eclipse.egit.github.core.client.RequestException in project ontrack by nemerosa.

the class DefaultOntrackGitHubClient method getIssue.

@Override
public GitHubIssue getIssue(String repository, int id) {
    // Logging
    logger.debug("[github] Getting issue {}/{}", repository, id);
    // Getting a client
    GitHubClient client = createGitHubClient();
    // Issue service using this client
    IssueService service = new IssueService(client);
    // Gets the repository for this project
    String owner = StringUtils.substringBefore(repository, "/");
    String name = StringUtils.substringAfter(repository, "/");
    Issue issue;
    try {
        issue = service.getIssue(owner, name, id);
    } catch (RequestException ex) {
        if (ex.getStatus() == 404) {
            return null;
        } else {
            throw new OntrackGitHubClientException(ex);
        }
    } catch (IOException e) {
        throw new OntrackGitHubClientException(e);
    }
    // Conversion
    return new GitHubIssue(id, issue.getHtmlUrl(), issue.getTitle(), issue.getBodyText(), issue.getBodyHtml(), toUser(issue.getAssignee()), toLabels(issue.getLabels()), toState(issue.getState()), toMilestone(repository, issue.getMilestone()), toDateTime(issue.getCreatedAt()), toDateTime(issue.getUpdatedAt()), toDateTime(issue.getClosedAt()));
}
Also used : IssueService(org.eclipse.egit.github.core.service.IssueService) GitHubClient(org.eclipse.egit.github.core.client.GitHubClient) IOException(java.io.IOException) RequestException(org.eclipse.egit.github.core.client.RequestException)

Aggregations

GitHubClient (org.eclipse.egit.github.core.client.GitHubClient)2 RequestException (org.eclipse.egit.github.core.client.RequestException)2 IOException (java.io.IOException)1 SneakyThrows (lombok.SneakyThrows)1 IssueService (org.eclipse.egit.github.core.service.IssueService)1 PullRequestService (org.eclipse.egit.github.core.service.PullRequestService)1