/** * If this thread is about an issue, return that issue. * * @return null if this thread is not about an issue. */ public GHIssue getBoundIssue() throws IOException { if (!"Issue".equals(subject.type) && "PullRequest".equals(subject.type)) return null; return repository.getIssue( Integer.parseInt(subject.url.substring(subject.url.lastIndexOf('/') + 1))); }
/** * If this thread is about an issue, return that issue. * * @return null if this thread is not about an issue. */ public GHIssue getBoundIssue() throws IOException { if (!"Issue".equals(subject.type) && "PullRequest".equals(subject.type)) return null; return repository.getIssue( Integer.parseInt(subject.url.substring(subject.url.lastIndexOf('/') + 1))); }
/** * If this thread is about an issue, return that issue. * * @return null if this thread is not about an issue. */ public GHIssue getBoundIssue() throws IOException { if (!"Issue".equals(subject.type) && "PullRequest".equals(subject.type)) return null; return repository.getIssue( Integer.parseInt(subject.url.substring(subject.url.lastIndexOf('/') + 1))); }
private static boolean syncIssue(final GHRepository rep, final int issueId, final String body) { try { GHIssue issue = rep.getIssue(issueId); issue.setBody(body); return true; } catch (Exception e) { e.printStackTrace(); } return false; }
public FormValidation doTestComment( @QueryParameter("serverAPIUrl") final String serverAPIUrl, @QueryParameter("credentialsId") final String credentialsId, @QueryParameter("repo") final String repoName, @QueryParameter("issueId") final int issueId, @QueryParameter("message1") final String comment) { try { GitHubBuilder builder = getBuilder(null, serverAPIUrl, credentialsId); if (builder == null) { return FormValidation.error("Unable to look up GitHub credentials using ID: " + credentialsId + "!!"); } GitHub gh = builder.build(); GHRepository repo = gh.getRepository(repoName); GHIssue issue = repo.getIssue(issueId); issue.comment(comment); return FormValidation.ok("Issued comment to issue: " + issue.getHtmlUrl()); } catch (Exception ex) { return FormValidation.error("Unable to issue comment: " + ex); } }
public static GHIssue getGhIssue(final Run<?, ?> run) throws IOException { return getGhRepositoryFromPRTrigger(run).getIssue(getPRNumberFromPRCause(run)); }
@Override public GitHubPRCause check(@Nonnull GitHubPRDecisionContext prDecisionContext) throws IOException { TaskListener listener = prDecisionContext.getListener(); GHPullRequest remotePR = prDecisionContext.getRemotePR(); final PrintStream logger = listener.getLogger(); for (GHLabel ghLabel : remotePR.getRepository().getIssue(remotePR.getNumber()).getLabels()) { for (String labelPatternStr : label.getLabelsSet()) { Pattern labelPattern = Pattern.compile(labelPatternStr); if (labelPattern.matcher(ghLabel.getName()).matches()) { logger.println(DISPLAY_NAME + ": Pull request has label: " + labelPatternStr); LOGGER.info("Pull request has '{}' label.", labelPatternStr); return prDecisionContext.newCause("PR has label: " + labelPatternStr, isSkip()); } } } return null; }
@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; }
@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; }
@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; }
final GHIssue issue = remoteRepo.getIssue(issueNo); if (issue.getState() != GHIssueState.CLOSED) { result.addWarning(String.format("[WARN] Issue #%d \"%s\" is not closed!",
Collection<GHLabel> labels = remotePR.getRepository().getIssue(remotePR.getNumber()).getLabels(); for (GHLabel remoteLabel : labels) { for (String checkedLabel : label.getLabelsSet()) {
updateLabels(execute(() -> remoteRepo.getIssue(number).getLabels())); } catch (IOException e) { LOGGER.error("Can't retrieve label list: {}", e);
private static StatusInfo createStatus(Configuration configuration, StatusInfo oldStatus) { GHRepository repository = null; GHIssue issue = oldStatus.getIssue(); if (issue != null) { repository = issue.getRepository(); try { issue = repository.getIssue(issue.getNumber()); } catch (IOException e) { configuration.warn(LOG, "Failed to lookup issue " + oldStatus.getIssueUrl() + ". " + e, e); } } GHPullRequest pullRequest = oldStatus.getPullRequest(); if (pullRequest != null) { if (repository == null) { repository = pullRequest.getRepository(); } try { pullRequest = repository.getPullRequest(pullRequest.getNumber()); } catch (IOException e) { configuration.warn(LOG, "Failed to lookup pull request " + oldStatus.getPullRequestUrl() + ". " + e, e); } } return new StatusInfo(oldStatus.getRepository(), oldStatus.getStatus(), issue, pullRequest); }
private static StatusInfo createStatus(Configuration configuration, StatusInfo oldStatus) { GHRepository repository = null; GHIssue issue = oldStatus.getIssue(); if (issue != null) { repository = issue.getRepository(); try { issue = repository.getIssue(issue.getNumber()); } catch (IOException e) { configuration.warn(LOG, "Failed to lookup issue " + oldStatus.getIssueUrl() + ". " + e, e); } } GHPullRequest pullRequest = oldStatus.getPullRequest(); if (pullRequest != null) { if (repository == null) { repository = pullRequest.getRepository(); } try { pullRequest = repository.getPullRequest(pullRequest.getNumber()); } catch (IOException e) { configuration.warn(LOG, "Failed to lookup pull request " + oldStatus.getPullRequestUrl() + ". " + e, e); } } return new StatusInfo(oldStatus.getRepository(), oldStatus.getStatus(), issue, pullRequest); }