public GitHubCommentsProvider( ViolationsLogger violationsLogger, final ViolationCommentsToGitHubApi violationCommentsToGitHubApi) { this.violationsLogger = violationsLogger; final GitHubClient gitHubClient = createClient(violationCommentsToGitHubApi.getGitHubUrl()); if (violationCommentsToGitHubApi.getOAuth2Token() != null) { gitHubClient.setOAuth2Token(violationCommentsToGitHubApi.getOAuth2Token()); } else if (violationCommentsToGitHubApi.getUsername() != null && violationCommentsToGitHubApi.getPassword() != null) { gitHubClient.setCredentials( violationCommentsToGitHubApi.getUsername(), violationCommentsToGitHubApi.getPassword()); } repository = new RepositoryId( violationCommentsToGitHubApi.getRepositoryOwner(), violationCommentsToGitHubApi.getRepositoryName()); pullRequestService = new PullRequestService(gitHubClient); issueSerivce = new IssueService(gitHubClient); List<RepositoryCommit> commits = null; try { commits = pullRequestService.getCommits( repository, violationCommentsToGitHubApi.getPullRequestId()); } catch (final IOException e) { throw new RuntimeException(e); } pullRequestCommit = commits.get(commits.size() - 1).getSha(); this.violationCommentsToGitHubApi = violationCommentsToGitHubApi; }