/** * @inheritDoc */ @Override public PullRequest getPullRequestIfExists(String base, String head, String repository) { RepositoryService repositoryService = new RepositoryService(); org.eclipse.egit.github.core.Repository openmrs = null; boolean exists = false; try { openmrs = repositoryService.getRepository(OPENMRS_USER, repository); PullRequestService pullRequestService = new PullRequestService(); List<PullRequest> openPRs = pullRequestService.getPullRequests(openmrs, "open"); for(PullRequest openPR : openPRs){ if(matchPullRequest(base, head, openPR)){ return openPR; } } } catch (IOException e) { throw new RuntimeException("Failed to access remote repository data",e); } return null; }
public void process(Exchange exchange) throws Exception { Integer pullRequestNumber = exchange.getIn().getHeader(GitHubConstants.GITHUB_PULLREQUEST, Integer.class); PullRequest pullRequest = pullRequestService.getPullRequest(getRepository(), pullRequestNumber); pullRequest.setState("closed"); pullRequest.setClosedAt(Calendar.getInstance().getTime()); pullRequest = pullRequestService.editPullRequest(getRepository(), pullRequest); // support InOut if (exchange.getPattern().isOutCapable()) { // copy the header of in message to the out message exchange.getOut().copyFrom(exchange.getIn()); exchange.getOut().setBody(pullRequest); } }
public List<CommitComment> getComments(final IRepositoryIdProvider repository, final int pullrequestId) { List<CommitComment> comments = null; try { comments = service.getComments(repository, pullrequestId); } catch (IOException e) { log.error("IO Exception fetching comments {}:{}", new Object[]{repository.generateId(), pullrequestId, e}); } return comments; }
pullRequestService = (PullRequestService) service; } else { pullRequestService = new PullRequestService(); List<PullRequest> pullRequests = pullRequestService.getPullRequests(getRepository(), "open"); for (PullRequest pullRequest : pullRequests) { List<CommitComment> commitComments = pullRequestService.getComments(getRepository(), pullRequest.getNumber()); for (Comment comment : commitComments) {
public PullMinerV3(final IGitHubClient ghc) { super(); service = new PullRequestService(ghc); }
if (pullRequestService.getPullRequest(repositoryId, Integer.parseInt(pullRequestNum)).isMergeable()) { mergeStatus = pullRequestService.merge(repositoryId, Integer.parseInt(pullRequestNum), commitMessage);
/** * @inheritDoc */ @Override public PullRequest openPullRequest(GithubPrRequest request) { RepositoryService repositoryService = new RepositoryService(); repositoryService.getClient().setCredentials(request.getUsername(), request.getPassword()); org.eclipse.egit.github.core.Repository openmrs = null; try { openmrs = repositoryService.getRepository(OPENMRS_USER, request.getRepository()); } catch (IOException e) { throw new RuntimeException("Failed to get repository data", e); } PullRequestService pullRequestService = new PullRequestService(); pullRequestService.getClient().setCredentials(request.getUsername(), request.getPassword()); PullRequest pr = new org.eclipse.egit.github.core.PullRequest(); pr.setTitle(request.getTitle()); pr.setHead(new PullRequestMarker().setLabel(request.getHead())); pr.setBase(new PullRequestMarker().setLabel(request.getBase())); pr.setBody(request.getDescription()); try { return pullRequestService.createPullRequest(openmrs, pr); } catch (IOException e) { throw new RuntimeException("Failed to create pull request:"+pr, e); } }
List<PullRequest> pullRequests = pullRequestService.getPullRequests(getRepository(), "open"); List<CommitComment> commitComments = pullRequestService.getComments(getRepository(), pullRequest.getNumber()); for (Comment comment : commitComments) { if (!commentIds.contains(comment.getId())) {
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; }
public PullRequest getPullRequest(final IRepositoryIdProvider repository, final int pullrequestId) { PullRequest pullrequest = null; try { pullrequest = service.getPullRequest(repository, pullrequestId); } catch (IOException e) { log.error("IO Exception fetching PullRequest {}:{}", new Object[]{repository.generateId(), pullrequestId, e}); } return pullrequest; }
public Collection<PullRequest> getClosedPullRequests(final IRepositoryIdProvider repository) { Collection<PullRequest> pullrequests = null; try { pullrequests = service.getPullRequests(repository, IssueService.STATE_CLOSED); } catch (IOException e) { log.error("IOException in getOpenPullRequests {} {}", new Object[]{repository.generateId(), e}); } return pullrequests; }
public void process(Exchange exchange) throws Exception { Integer pullRequestNumber = exchange.getIn().getHeader(GitHubConstants.GITHUB_PULLREQUEST, Integer.class); java.util.List<CommitFile> response = pullRequestService.getFiles(getRepository(), pullRequestNumber); // copy the header of in message to the out message exchange.getOut().copyFrom(exchange.getIn()); exchange.getOut().setBody(response); }
public PullRequestService getPullRequestService(String username, String password) throws IOException { return new PullRequestService(getGitHubClient(username, password)); }
when(pullRequestService.getPullRequest(any(RepositoryId.class), anyInt())).thenReturn(pullRequest); when(pullRequest.isMergeable()).thenReturn(true); when(pullRequestService.merge(any(RepositoryId.class), anyInt(), anyString())).thenReturn(mergeStatus);
public Collection<PullRequest> getOpenPullRequests(final IRepositoryIdProvider repository) { Collection<PullRequest> pullrequests = null; try { pullrequests = service.getPullRequests(repository, IssueService.STATE_OPEN); } catch (IOException e) { log.error("IOException in getOpenPullRequests {} {}", new Object[]{repository.generateId(), e}); } return pullrequests; }
@Override public List<ChangedFile> getFiles() { final List<ChangedFile> changedFiles = new ArrayList<>(); try { final List<CommitFile> files = pullRequestService.getFiles(repository, violationCommentsToGitHubApi.getPullRequestId()); for (final CommitFile commitFile : files) { final List<String> list = new ArrayList<>(); list.add(commitFile.getPatch()); changedFiles.add(new ChangedFile(commitFile.getFilename(), list)); } } catch (final IOException e) { violationsLogger.log(SEVERE, e.getMessage(), e); } return changedFiles; }
public PullRequestConsumer(GitHubEndpoint endpoint, Processor processor) throws Exception { super(endpoint, processor); Registry registry = endpoint.getCamelContext().getRegistry(); Object service = registry.lookupByName(GitHubConstants.GITHUB_PULL_REQUEST_SERVICE); if (service != null) { LOG.debug("Using PullRequestService found in registry {}", service.getClass().getCanonicalName()); pullRequestService = (PullRequestService) service; } else { pullRequestService = new PullRequestService(); } initService(pullRequestService); LOG.info("GitHub PullRequestConsumer: Indexing current pull requests..."); List<PullRequest> pullRequests = pullRequestService.getPullRequests(getRepository(), "open"); if (pullRequests.size() > 0) { lastOpenPullRequest = pullRequests.get(0).getNumber(); } }
public PullRequestFilesProducer(GitHubEndpoint endpoint) throws Exception { super(endpoint); Registry registry = endpoint.getCamelContext().getRegistry(); Object service = registry.lookupByName(GitHubConstants.GITHUB_PULL_REQUEST_SERVICE); if (service != null) { LOG.debug("Using PullRequestService found in registry {}", service.getClass().getCanonicalName()); pullRequestService = (PullRequestService) service; } else { pullRequestService = new PullRequestService(); } initService(pullRequestService); }
@Override protected int poll() throws Exception { List<PullRequest> openPullRequests = pullRequestService.getPullRequests(getRepository(), "open");
@Override public List<Comment> getComments() { final List<Comment> comments = new ArrayList<>(); try { final List<String> specifics = new ArrayList<>(); for (final CommitComment commitComment : pullRequestService.getComments( repository, violationCommentsToGitHubApi.getPullRequestId())) { comments.add( new Comment( Long.toString(commitComment.getId()), commitComment.getBody(), TYPE_DIFF, specifics)); } for (final org.eclipse.egit.github.core.Comment comment : issueSerivce.getComments(repository, violationCommentsToGitHubApi.getPullRequestId())) { comments.add( new Comment(Long.toString(comment.getId()), comment.getBody(), TYPE_PR, specifics)); } } catch (final Exception e) { violationsLogger.log(SEVERE, e.getMessage(), e); } return comments; }