org.kohsuke.github.GHIssueState Java Examples
The following examples show how to use
org.kohsuke.github.GHIssueState.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GitHubPRCloseEvent.java From github-integration-plugin with MIT License | 6 votes |
@Override public GitHubPRCause check(@Nonnull GitHubPRDecisionContext prDecisionContext) throws IOException { TaskListener listener = prDecisionContext.getListener(); GHPullRequest remotePR = prDecisionContext.getRemotePR(); final PrintStream logger = listener.getLogger(); final GitHubPRPullRequest localPR = prDecisionContext.getLocalPR(); if (isNull(localPR)) { return null; } GitHubPRCause cause = null; // must be closed once if (remotePR.getState().equals(GHIssueState.CLOSED)) { logger.println(DISPLAY_NAME + ": state has changed (PR was closed)"); cause = prDecisionContext.newCause("PR was closed", false); } return cause; }
Example #2
Source File: PullRequestToCauseConverterTest.java From github-integration-plugin with MIT License | 6 votes |
/** * Test trigger configuration of: * <p> * 1.) Skip PR if label is not present (when label is not present) * 2.) Cause PR if commit changed (when commit has changed) * <p> * Expected result is that the PR should be skipped. No causes should be * identified. */ @Test public void shouldSkipSkippableEvents() throws Exception { GHCommitPointer commitPtr = mock(GHCommitPointer.class); GHRepository headRepo = mock(GHRepository.class); when(headRepo.getOwnerName()).thenReturn("owner"); when(commitPtr.getRepository()).thenReturn(headRepo); when(local.getPulls()).thenReturn(ImmutableMap.of(3, localPR)); when(localPR.getHeadSha()).thenReturn("this is not the sha you are looking for"); when(remotePR.getNumber()).thenReturn(3); when(remotePR.getState()).thenReturn(GHIssueState.OPEN); when(remotePR.getHead()).thenReturn(commitPtr); when(trigger.getEvents()).thenReturn(asList( new GitHubPRLabelNotExistsEvent(new GitHubPRLabel("notfound"), true), new GitHubPRCommitEvent())); final GitHubPRCause cause = toGitHubPRCause(local, tlRule.getListener(), trigger) .apply(remotePR); assertThat(cause, nullValue()); }
Example #3
Source File: GitHubPRNonMergeableEventTest.java From github-integration-plugin with MIT License | 6 votes |
@Before public void before() throws IOException { when(remotePr.getUser()).thenReturn(ghUser); GHRepository headRepo = mock(GHRepository.class); when(headRepo.getOwnerName()).thenReturn("owner"); when(remotePr.getHead()).thenReturn(ghCommitPointer); when(remotePr.getBase()).thenReturn(ghCommitPointer); when(ghCommitPointer.getSha()).thenReturn("1r134rsha324"); when(ghCommitPointer.getRef()).thenReturn("some/branch"); when(ghCommitPointer.getRepository()).thenReturn(headRepo); when(remotePr.getRepository()).thenReturn(ghRepository); when(ghRepository.getIssue(0)).thenReturn(ghIssue); when(ghIssue.getLabels()).thenReturn(Collections.<GHLabel>emptySet()); when(remotePr.getState()).thenReturn(GHIssueState.OPEN); }
Example #4
Source File: GithubRepository.java From cloud-search-samples with Apache License 2.0 | 6 votes |
/** * Fetch all issues for the repository. Includes pull requests. * * @param repo Repository to get issues for * @return Items to push into the queue for later indexing * @throws IOException if error reading issues */ private PushItems collectIssues(GHRepository repo) throws IOException { PushItems.Builder builder = new PushItems.Builder(); List<GHIssue> issues = repo.listIssues(GHIssueState.ALL) .withPageSize(1000) .asList(); for (GHIssue issue : issues) { String resourceName = issue.getHtmlUrl().getPath(); log.info(() -> String.format("Adding issue %s", resourceName)); PushItem item = new PushItem(); item.setMetadataHash(Long.toHexString(issue.getUpdatedAt().getTime())); builder.addPushItem(resourceName, item); } return builder.build(); }
Example #5
Source File: GitHubPRLabelExistsEvent.java From github-integration-plugin with MIT License | 6 votes |
@Override public GitHubPRCause check(@Nonnull GitHubPRDecisionContext prDecisionContext) throws IOException { TaskListener listener = prDecisionContext.getListener(); GHPullRequest remotePR = prDecisionContext.getRemotePR(); if (remotePR.getState().equals(GHIssueState.CLOSED)) { return null; // already closed, skip check? } GitHubPRCause cause = null; Collection<GHLabel> remoteLabels = remotePR.getRepository().getIssue(remotePR.getNumber()).getLabels(); Set<String> existingLabels = new HashSet<>(); for (GHLabel ghLabel : remoteLabels) { existingLabels.add(ghLabel.getName()); } if (existingLabels.containsAll(label.getLabelsSet())) { final PrintStream logger = listener.getLogger(); logger.println(DISPLAY_NAME + ": " + label.getLabelsSet() + " found"); cause = prDecisionContext.newCause(label.getLabelsSet() + " labels exist", isSkip()); } return cause; }
Example #6
Source File: GitHubPRTrigger.java From github-integration-plugin with MIT License | 6 votes |
/** * @return remote pull requests for future analysing. */ private static Set<GHPullRequest> pullRequestsToCheck(@Nullable Integer prNumber, @Nonnull GHRepository remoteRepo, @Nonnull GitHubPRRepository localRepo) throws IOException { if (prNumber != null) { return execute(() -> singleton(remoteRepo.getPullRequest(prNumber))); } else { List<GHPullRequest> remotePulls = execute(() -> remoteRepo.getPullRequests(GHIssueState.OPEN)); Set<Integer> remotePRNums = from(remotePulls).transform(extractPRNumber()).toSet(); return from(localRepo.getPulls().keySet()) // add PRs that was closed on remote .filter(not(in(remotePRNums))) .transform(fetchRemotePR(remoteRepo)) .filter(notNull()) .append(remotePulls) .toSet(); } }
Example #7
Source File: Issues.java From updatebot with Apache License 2.0 | 5 votes |
public static List<GHIssue> getOpenIssues(GHRepository ghRepository, String label) throws IOException { List<GHIssue> issues = retryGithub(() -> ghRepository.getIssues(GHIssueState.OPEN)); List<GHIssue> answer = new ArrayList<>(); for (GHIssue issue : issues) { if (GitHubHelpers.hasLabel(getLabels(issue), label) && !issue.isPullRequest()) { answer.add(issue); } } return answer; }
Example #8
Source File: PullRequestToCauseConverterTest.java From github-integration-plugin with MIT License | 5 votes |
@Before public void setUp() throws Exception { GHRepository headRepo = mock(GHRepository.class); when(headRepo.getOwnerName()).thenReturn("owner"); when(commit.getRepository()).thenReturn(headRepo); when(remotePR.getUser()).thenReturn(user); when(remotePR.getHead()).thenReturn(commit); when(remotePR.getBase()).thenReturn(commit); when(remotePR.getRepository()).thenReturn(remoteRepo); when(remotePR.getState()).thenReturn(GHIssueState.OPEN); when(remoteRepo.getIssue(Matchers.any(Integer.class))).thenReturn(new GHIssue()); }
Example #9
Source File: LocalRepoUpdaterTest.java From github-integration-plugin with MIT License | 5 votes |
@Test public void shouldRemoveClosedPRs() throws Exception { localRepo.getPulls().put(1, localPR); when(remotePR.getState()).thenReturn(GHIssueState.CLOSED); when(remotePR.getNumber()).thenReturn(1); LocalRepoUpdater.updateLocalRepo(localRepo).apply(remotePR); assertThat("replace", localRepo.getPulls(), not(hasKey(1))); }
Example #10
Source File: LocalRepoUpdaterTest.java From github-integration-plugin with MIT License | 5 votes |
@Test public void shouldReplaceOpenedPRs() throws Exception { when(localPR.getHeadSha()).thenReturn(SHA_LOCAL); localRepo.getPulls().put(1, localPR); when(remotePR.getState()).thenReturn(GHIssueState.OPEN); when(remotePR.getNumber()).thenReturn(1); LocalRepoUpdater.updateLocalRepo(localRepo).apply(remotePR); assertThat("replace", localRepo.getPulls(), hasKey(1)); assertThat("sha", localRepo.getPulls().get(1).getHeadSha(), is(SHA_REMOTE)); }
Example #11
Source File: LocalRepoUpdaterTest.java From github-integration-plugin with MIT License | 5 votes |
@Test public void shouldAddOpenedPRs() throws Exception { when(remotePR.getState()).thenReturn(GHIssueState.OPEN); when(remotePR.getNumber()).thenReturn(1); LocalRepoUpdater.updateLocalRepo(localRepo).apply(remotePR); assertThat("new", localRepo.getPulls(), hasKey(1)); }
Example #12
Source File: GitHubPRCommentEventTest.java From github-integration-plugin with MIT License | 5 votes |
private void commonExpectations(Set<String> localLabels) throws IOException { when(labels.getLabelsSet()).thenReturn(localLabels); when(localPR.getLabels()).thenReturn(localLabels); when(remotePr.getState()).thenReturn(GHIssueState.OPEN); when(remotePr.getRepository()).thenReturn(repository); when(repository.getIssue(anyInt())).thenReturn(issue); when(repository.getOwnerName()).thenReturn("ownerName"); when(listener.getLogger()).thenReturn(logger); }
Example #13
Source File: GitHubPRLabelAddedEventTest.java From github-integration-plugin with MIT License | 5 votes |
private void commonExpectations(Set<String> localLabels) throws IOException { when(labels.getLabelsSet()).thenReturn(checkedLabels); when(localPR.getLabels()).thenReturn(localLabels); when(remotePr.getState()).thenReturn(GHIssueState.OPEN); when(remotePr.getRepository()).thenReturn(repository); when(repository.getIssue(anyInt())).thenReturn(issue); when(repository.getOwnerName()).thenReturn("ownerName"); when(listener.getLogger()).thenReturn(logger); }
Example #14
Source File: GitHubPRLabelRemovedEventTest.java From github-integration-plugin with MIT License | 5 votes |
private void commonExpectations(Set<String> localLabels) throws IOException { when(labels.getLabelsSet()).thenReturn(checkedLabels); when(localPR.getLabels()).thenReturn(localLabels); when(remotePr.getState()).thenReturn(GHIssueState.OPEN); when(remotePr.getRepository()).thenReturn(repository); when(repository.getIssue(anyInt())).thenReturn(issue); when(listener.getLogger()).thenReturn(logger); }
Example #15
Source File: GitHubPRNumberTest.java From github-integration-plugin with MIT License | 5 votes |
private void commonExpectations() throws IOException { when(localPR.getLabels()).thenReturn(Collections.<String>emptySet()); when(remotePr.getState()).thenReturn(GHIssueState.OPEN); when(remotePr.getRepository()).thenReturn(repository); when(repository.getIssue(anyInt())).thenReturn(issue); when(listener.getLogger()).thenReturn(logger); }
Example #16
Source File: GHPRAppeared.java From github-integration-plugin with MIT License | 5 votes |
@Override public Boolean call() throws Exception { for (GHPullRequest pr : repository.listPullRequests(GHIssueState.OPEN)) { if (pr.getNumber() == pullRequest.getNumber()) { LOG.debug("[WAIT] appeared PR {}, delay {} ms", pullRequest.getNumber(), currentTimeMillis() - startTime); return true; } } LOG.debug("[WAIT] no PR {}", pullRequest.getNumber()); return false; }
Example #17
Source File: GitHubPRHandler.java From github-integration-plugin with MIT License | 5 votes |
private static Stream<GHPullRequest> fetchRemotePRs(GitHubPRRepository localRepo, GHRepository remoteRepo) throws IOException { // fetch open prs Map<Integer, GHPullRequest> remotePulls = execute(() -> remoteRepo.getPullRequests(GHIssueState.OPEN)).stream() .collect(Collectors.toMap(GHPullRequest::getNumber, Function.identity())); // collect closed pull requests we knew of previously Stream<GHPullRequest> closed = new HashSet<>(localRepo.getPulls().keySet()).stream() .filter(pr -> !remotePulls.containsKey(pr)) .map(iof(remoteRepo::getPullRequest)); return Stream.concat(remotePulls.values().stream(), closed); }
Example #18
Source File: GitHubPRLabelNotExistsEvent.java From github-integration-plugin with MIT License | 5 votes |
@Override public GitHubPRCause check(@Nonnull GitHubPRDecisionContext prDecisionContext) throws IOException { TaskListener listener = prDecisionContext.getListener(); GHPullRequest remotePR = prDecisionContext.getRemotePR(); if (remotePR.getState().equals(GHIssueState.CLOSED)) { return null; // already closed, skip check? } GitHubPRCause cause = null; Collection<GHLabel> remoteLabels = remotePR.getRepository().getIssue(remotePR.getNumber()).getLabels(); Set<String> existingLabels = new HashSet<>(); for (GHLabel ghLabel : remoteLabels) { existingLabels.add(ghLabel.getName()); } existingLabels.retainAll(label.getLabelsSet()); if (existingLabels.isEmpty()) { final PrintStream logger = listener.getLogger(); LOG.debug("{}:{} not found", DISPLAY_NAME, label.getLabelsSet()); logger.println(DISPLAY_NAME + ": " + label.getLabelsSet() + " not found"); cause = prDecisionContext.newCause(label.getLabelsSet() + " labels not exist", isSkip()); } return cause; }
Example #19
Source File: GitHubPRLabelAddedEvent.java From github-integration-plugin with MIT License | 5 votes |
@Override public GitHubPRCause check(@Nonnull GitHubPRDecisionContext prDecisionContext) throws IOException { TaskListener listener = prDecisionContext.getListener(); GitHubPRPullRequest localPR = prDecisionContext.getLocalPR(); GHPullRequest remotePR = prDecisionContext.getRemotePR(); if (remotePR.getState().equals(GHIssueState.CLOSED)) { return null; // already closed, skip check? } if (isNull(label)) { LOG.error("Label is null. Bad configured event: {}", getDescriptor().getDisplayName()); throw new IllegalStateException("Label is null. Bad configured event: " + getDescriptor().getDisplayName()); } //localPR exists before, checking for changes if (localPR != null && localPR.getLabels().containsAll(label.getLabelsSet())) { return null; // label existed before exiting } GitHubPRCause cause = null; Collection<GHLabel> labels = remotePR.getRepository().getIssue(remotePR.getNumber()).getLabels(); Set<String> existingLabels = new HashSet<String>(); for (GHLabel curLabel : labels) { existingLabels.add(curLabel.getName()); } if (existingLabels.containsAll(label.getLabelsSet())) { final PrintStream logger = listener.getLogger(); logger.println(DISPLAY_NAME + ": state has changed (" + label.getLabelsSet() + " labels were added"); cause = prDecisionContext.newCause(label.getLabelsSet() + " labels were added", false); } return cause; }
Example #20
Source File: GitHubPRCommitEvent.java From github-integration-plugin with MIT License | 5 votes |
@Override public GitHubPRCause check(@Nonnull GitHubPRDecisionContext prDecisionContext) throws IOException { TaskListener listener = prDecisionContext.getListener(); GHPullRequest remotePR = prDecisionContext.getRemotePR(); GitHubPRPullRequest localPR = prDecisionContext.getLocalPR(); if (remotePR.getState().equals(GHIssueState.CLOSED)) { //TODO check whether push to closed allowed? return null; // already closed, nothing to check } if (isNull(localPR)) { // new return null; // not interesting for this event } GitHubPRCause cause = null; GHCommitPointer head = remotePR.getHead(); if (!localPR.getHeadSha().equals(head.getSha())) { LOGGER.debug("New commit. Sha: {} => {}", localPR.getHeadSha(), head.getSha()); final PrintStream logger = listener.getLogger(); logger.println(this.getClass().getSimpleName() + ": new commit found, sha " + head.getSha()); // GHUser user = head.getUser(); cause = prDecisionContext.newCause(DISPLAY_NAME, false); } return cause; }
Example #21
Source File: GitHubSCMSource.java From github-branch-source-plugin with MIT License | 5 votes |
@Override protected Iterable<GHPullRequest> create() { try { request.checkApiRateLimit(); Set<Integer> prs = request.getRequestedPullRequestNumbers(); if (prs != null && prs.size() == 1) { Integer number = prs.iterator().next(); request.listener().getLogger().format("%n Getting remote pull request #%d...%n", number); GHPullRequest pullRequest = repo.getPullRequest(number); if (pullRequest.getState() != GHIssueState.OPEN) { return Collections.emptyList(); } return new CacheUpdatingIterable(Collections.singletonList(pullRequest)); } Set<String> branchNames = request.getRequestedOriginBranchNames(); if (branchNames != null && branchNames.size() == 1) { // TODO flag to check PRs are all origin PRs // if we were including multiple PRs and they are not all from the same origin branch // then branchNames would have a size > 1 therefore if the size is 1 we must only // be after PRs that come from this named branch String branchName = branchNames.iterator().next(); request.listener().getLogger().format( "%n Getting remote pull requests from branch %s...%n", branchName ); return new CacheUpdatingIterable(repo.queryPullRequests() .state(GHIssueState.OPEN) .head(repo.getOwnerName() + ":" + branchName) .list()); } request.listener().getLogger().format("%n Getting remote pull requests...%n"); fullScanRequested = true; return new CacheUpdatingIterable(LazyPullRequests.this.repo.queryPullRequests() .state(GHIssueState.OPEN) .list()); } catch (IOException | InterruptedException e) { throw new GitHubSCMSource.WrappedException(e); } }
Example #22
Source File: Issues.java From updatebot with Apache License 2.0 | 5 votes |
public static boolean isOpen(GHIssue issue) { GHIssueState state = issue.getState(); if (state == null) { return true; } return state == GHIssueState.OPEN; }
Example #23
Source File: PullRequests.java From updatebot with Apache License 2.0 | 5 votes |
public static List<GHPullRequest> getOpenPullRequests(GHRepository ghRepository, String label) throws IOException { List<GHPullRequest> pullRequests = retryGithub(() -> ghRepository.getPullRequests(GHIssueState.OPEN)); List<GHPullRequest> answer = new ArrayList<>(); if (pullRequests != null) { for (GHPullRequest pullRequest : pullRequests) { if (GitHubHelpers.hasLabel(Issues.getLabels(pullRequest), label)) { answer.add(pullRequest); } } } return answer; }
Example #24
Source File: StatusInfo.java From updatebot with Apache License 2.0 | 4 votes |
public GHIssueState getIssueState() { return issueState; }
Example #25
Source File: StatusInfo.java From updatebot with Apache License 2.0 | 4 votes |
protected static GHIssueState state(GHIssue issue) { if (issue != null) { return issue.getState(); } return null; }
Example #26
Source File: StatusInfo.java From updatebot with Apache License 2.0 | 4 votes |
public GHIssueState getPullRequestState() { return pullRequestState; }
Example #27
Source File: StatusInfo.java From updatebot with Apache License 2.0 | 4 votes |
protected String format(GHIssueState state) { if (state != null) { return state.toString().toLowerCase(); } return null; }
Example #28
Source File: StatusInfo.java From updatebot with Apache License 2.0 | 4 votes |
protected static boolean nullOrClosed(GHIssueState state) { return state == null || state.equals(GHIssueState.CLOSED); }
Example #29
Source File: GitHubPRDescriptionEventTest.java From github-integration-plugin with MIT License | 3 votes |
private void commonExpectations() throws IOException { when(job.getFullName()).thenReturn("Full job name"); when(trigger.getJob()).thenReturn((Job) job); when(remotePr.getState()).thenReturn(GHIssueState.OPEN); when(remotePr.getRepository()).thenReturn(repository); when(repository.getIssue(anyInt())).thenReturn(issue); when(repository.getOwnerName()).thenReturn("ownerName"); when(listener.getLogger()).thenReturn(logger); }