org.kohsuke.github.GHIssue Java Examples
The following examples show how to use
org.kohsuke.github.GHIssue.
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: 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 #2
Source File: LocalRepoUpdaterTest.java From github-integration-plugin with MIT License | 6 votes |
@Before public void setUp() throws Exception { localRepo = new GitHubPRRepository(remoteRepo); GHRepository headRepo = mock(GHRepository.class); when(headRepo.getOwnerName()).thenReturn("owner"); when(commit.getRepository()).thenReturn(headRepo); when(remotePR.getUser()).thenReturn(new GHUser()); when(remotePR.getHead()).thenReturn(commit); when(remotePR.getBase()).thenReturn(commit); when(remotePR.getRepository()).thenReturn(remoteRepo); when(remoteRepo.getIssue(Matchers.any(Integer.class))).thenReturn(new GHIssue()); when(commit.getSha()).thenReturn(SHA_REMOTE); }
Example #3
Source File: GitHubPRLabelAddPublisher.java From github-integration-plugin with MIT License | 6 votes |
@Override public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath workspace, @Nonnull Launcher launcher, @Nonnull TaskListener listener) throws InterruptedException, IOException { if (getStatusVerifier() != null && !getStatusVerifier().isRunAllowed(run)) { return; } try { HashSet<String> remoteLabels = new HashSet<>(); final GHIssue ghIssue = getGhIssue(run); //remote labels List -> Set ghIssue.getLabels().stream() .map(GHLabel::getName) .collect(Collectors.toList()) .forEach(remoteLabels::add); remoteLabels.addAll(getLabelProperty().getLabelsSet()); ghIssue.setLabels(remoteLabels.toArray(new String[remoteLabels.size()])); } catch (IOException ex) { final int number = getPRNumberFromPRCause(run); listener.getLogger().println("Couldn't add label for PR #" + number + ex.getMessage()); LOGGER.error("Couldn't add label for PR #{}", number, ex); handlePublisherError(run); } }
Example #4
Source File: TemplateProcessorTest.java From contribution with GNU Lesser General Public License v2.1 | 5 votes |
private static ReleaseNotesMessage createReleaseNotesMessage(int number, String title, String author) throws IllegalAccessException, NoSuchFieldException { final GHIssue issue = new GHIssue(); final Field titleField = issue.getClass().getDeclaredField("title"); titleField.setAccessible(true); titleField.set(issue, title); final Field numberField = issue.getClass().getDeclaredField("number"); numberField.setAccessible(true); numberField.set(issue, number); return new ReleaseNotesMessage(issue, author); }
Example #5
Source File: ReleaseNotesMessage.java From contribution with GNU Lesser General Public License v2.1 | 5 votes |
/** * Returns actual title of issue or pull request which is represented as an issue. * * @param issue issue object. * @return actual title of issue or pull request which is represented as an issue. */ private static String getActualTitle(GHIssue issue) { final String actualTitle; final String issueTitle = issue.getTitle(); if (issueTitle.startsWith("Pull")) { actualTitle = issueTitle.substring(issueTitle.indexOf(':') + 2); } else { actualTitle = issueTitle; } return actualTitle; }
Example #6
Source File: ReleaseNotesMessage.java From contribution with GNU Lesser General Public License v2.1 | 5 votes |
/** * Constructs a release notes message for issue. * * @param issue issue. * @param author author. */ public ReleaseNotesMessage(GHIssue issue, String author) { issueNo = issue.getNumber(); title = getActualTitle(issue); shortWidthTitle = split(title); this.author = author; }
Example #7
Source File: NotesBuilder.java From contribution with GNU Lesser General Public License v2.1 | 5 votes |
/** * Returns issue label for release notes. * * @param issue issue. * @return issue label for release notes * @throws IOException if an I/o error occurs. */ private static String getIssueLabelFrom(GHIssue issue) throws IOException { final Collection<GHLabel> issueLabels = issue.getLabels(); final Optional<GHLabel> label = issueLabels.stream() .filter(input -> Arrays.binarySearch(Constants.ISSUE_LABELS, input.getName()) >= 0) .findFirst(); return label.map(GHLabel::getName).orElse(""); }
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: SyncDocsToGithubSubCommand.java From RocketMQ-Master-analyze with Apache License 2.0 | 5 votes |
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; }
Example #10
Source File: SyncDocsToGithubSubCommand.java From rocketmq with Apache License 2.0 | 5 votes |
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; }
Example #11
Source File: ForkJoinReleaseTest.java From updatebot with Apache License 2.0 | 5 votes |
public void assertOpenIssueAndPullRequestCount(String repoName, int expectedIssueCount, int exepectedPullRequestCount, boolean verbose) throws IOException { LocalRepository repository = assertLocalRepository(repoName); GHRepository gitHubRepository = GitHubHelpers.getGitHubRepository(repository); assertThat(gitHubRepository).describedAs("Not a GitHub repository " + repository).isNotNull(); String label = configuration.getGithubPullRequestLabel(); List<GHIssue> issues; List<GHPullRequest> prs; boolean doAssert = true; if (doAssert) { issues = GithubAssertions.assertOpenIssueCount(gitHubRepository, label, expectedIssueCount); prs = GithubAssertions.assertOpenPullRequestCount(gitHubRepository, label, exepectedPullRequestCount); } else { issues = Issues.getOpenIssues(gitHubRepository, configuration); prs = PullRequests.getOpenPullRequests(gitHubRepository, configuration); } if (verbose) { LOG.warn("===> " + gitHubRepository.getName() + " Issue count: " + issues.size() + " PR count: " + prs.size()); Issues.logOpen(issues); PullRequests.logOpen(prs); } }
Example #12
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 #13
Source File: Issues.java From updatebot with Apache License 2.0 | 5 votes |
/** * Lets try find the issue */ public static GHIssue findIssue(CommandContext context, List<GHIssue> issues) { String prefix = context.createIssueTitlePrefix(); if (issues != null) { for (GHIssue issue : issues) { String title = issue.getTitle(); if (title != null && title.startsWith(prefix)) { return issue; } } } return null; }
Example #14
Source File: Issues.java From updatebot with Apache License 2.0 | 5 votes |
public static List<DependencyVersionChange> loadPendingChangesFromIssue(CommandContext context, GHIssue issue) throws IOException { List<GHIssueComment> comments = issue.getComments(); String lastCommand = null; for (GHIssueComment comment : comments) { String command = updateBotIssuePendingChangesComment(context, comment); if (command != null) { lastCommand = command; } } if (lastCommand == null) { LOG.warn("No UpdateBot comment found on issue " + issue.getHtmlUrl()); return new ArrayList<>(); } return parseUpdateBotIssuePendingChangesComment(lastCommand); }
Example #15
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 #16
Source File: SyncDocsToGithubSubCommand.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 5 votes |
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; }
Example #17
Source File: CommandSupport.java From updatebot with Apache License 2.0 | 5 votes |
protected GHIssue getOrFindIssue(CommandContext context, GHRepository ghRepository) throws IOException { GHIssue issue = context.getIssue(); if (issue == null) { List<GHIssue> issues = Issues.getOpenIssues(ghRepository, context.getConfiguration()); issue = Issues.findIssue(context, issues); context.setIssue(issue); } return issue; }
Example #18
Source File: ModifyFilesCommandSupport.java From updatebot with Apache License 2.0 | 5 votes |
public void updatePendingChanges(CommandContext context, DependenciesCheck check, List<DependencyVersionChange> pendingChanges) throws IOException { Configuration configuration = context.getConfiguration(); List<DependencyVersionChange> currentPendingChanges = check.getInvalidChanges(); GHRepository ghRepository = context.gitHubRepository(); if (ghRepository != null) { GHIssue issue = getOrFindIssue(context, ghRepository); if (currentPendingChanges.equals(pendingChanges)) { if (issue != null) { LOG.debug("Pending changes unchanged so not modifying the issue"); } return; } String operationDescrption = getOperationDescription(context); if (currentPendingChanges.isEmpty()) { if (issue != null) { context.info(LOG, "Closing issue as we have no further pending issues " + issue.getHtmlUrl()); issue.comment(Issues.CLOSE_MESSAGE + operationDescrption); issue.close(); } return; } if (issue == null) { issue = Issues.createIssue(context, ghRepository); context.setIssue(issue); context.info(LOG, configuration.colored(Configuration.COLOR_PENDING, "Created issue " + issue.getHtmlUrl())); } else { context.info(LOG, configuration.colored(Configuration.COLOR_PENDING, "Modifying issue " + issue.getHtmlUrl())); } Issues.addConflictsComment(issue, currentPendingChanges, operationDescrption, check); } else { // TODO what to do with vanilla git repos? } }
Example #19
Source File: ModifyFilesCommandSupport.java From updatebot with Apache License 2.0 | 5 votes |
protected List<DependencyVersionChange> loadPendingChanges(CommandContext context) throws IOException { GHRepository ghRepository = context.gitHubRepository(); if (ghRepository != null) { List<GHIssue> issues = Issues.getOpenIssues(ghRepository, context.getConfiguration()); GHIssue issue = Issues.findIssue(context, issues); if (issue != null) { context.setIssue(issue); return Issues.loadPendingChangesFromIssue(context, issue); } } else { // TODO what to do with vanilla git repos? } return new ArrayList<>(); }
Example #20
Source File: StatusInfo.java From updatebot with Apache License 2.0 | 5 votes |
public StatusInfo(LocalRepository repository, Status status, GHIssue issue, GHPullRequest pullRequest) { this.repository = repository; this.issue = issue; this.pullRequest = pullRequest; this.issueUrl = (issue != null) ? Strings.toString(issue.getHtmlUrl()) : null; this.pullRequestUrl = (pullRequest != null) ? Strings.toString(pullRequest.getHtmlUrl()) : null; this.cloneUrl = repository.getCloneUrl(); this.issueState = state(issue); this.pullRequestState = state(pullRequest); if (nullOrClosed(issueState) && nullOrClosed(pullRequestState) && status.equals(Status.PENDING)) { status = Status.COMPLETE; } this.status = status; }
Example #21
Source File: ParentContext.java From updatebot with Apache License 2.0 | 5 votes |
public List<GHIssue> getIssues() { List<GHIssue> answer = new ArrayList<>(); for (CommandContext child : children) { GHIssue issue = child.getIssue(); if (issue != null) { answer.add(issue); } } return answer; }
Example #22
Source File: GithubRepository.java From cloud-search-samples with Apache License 2.0 | 4 votes |
/** * Build the ApiOperation to index an issue. * * @param issue Pull request to index * @param previousItem Previous item state in the index * @return ApiOperation (RepositoryDoc if indexing, PushItem if not modified) * @throws IOException if unable to create operation */ private ApiOperation indexItem(GHIssue issue, Item previousItem) throws IOException { String metadataHash = issue.getUpdatedAt().toString(); // If previously indexed and unchanged, just requeue as unmodified if (canSkipIndexing(previousItem, metadataHash)) { return notModified(previousItem.getName()); } String resourceName = issue.getHtmlUrl().getPath(); FieldOrValue<String> title = FieldOrValue.withValue(issue.getTitle()); FieldOrValue<String> url = FieldOrValue.withValue( issue.getHtmlUrl().toExternalForm()); FieldOrValue<DateTime> createTime = FieldOrValue.withValue( new DateTime(issue.getCreatedAt().getTime())); FieldOrValue<DateTime> updateTime = FieldOrValue.withValue( new DateTime(issue.getUpdatedAt().getTime())); String containerName = issue.getRepository().getHtmlUrl().getPath(); // Structured data based on the schema Multimap<String, Object> structuredData = ArrayListMultimap.create(); structuredData.put("organization", issue.getRepository().getOwnerName()); structuredData.put("repository", issue.getRepository().getName()); structuredData.put("status", issue.getState().name().toLowerCase()); structuredData.put("reportedBy", issue.getUser() != null ? issue.getUser().getLogin() : null); structuredData.put("assignee", issue.getAssignee() != null ? issue.getAssignee().getLogin() : null); for (GHLabel label : issue.getLabels()) { structuredData.put("labels", label.getName()); } // Index comments as sub objects in the metadata. This makes the comments // searchable but still tied to the issue itself. for (GHIssueComment comment : issue.getComments()) { Multimap<String, Object> commentData = ArrayListMultimap.create(); commentData.put("comment", comment.getBody()); commentData.put("user", comment.getUser() != null ? comment.getUser().getLogin() : null); structuredData.put("comments", commentData); } structuredData.put("createdAt", issue.getCreatedAt()); structuredData.put("updatedAt", issue.getUpdatedAt()); Item item = IndexingItemBuilder.fromConfiguration(resourceName) .setTitle(title) .setContainerName(containerName) .setSourceRepositoryUrl(url) .setItemType(IndexingItemBuilder.ItemType.CONTAINER_ITEM) .setObjectType("issue") .setValues(structuredData) .setVersion(Longs.toByteArray(issue.getUpdatedAt().getTime())) .setCreateTime(createTime) .setUpdateTime(updateTime) .setHash(metadataHash) .build(); // TODO - Render markdown to HTML AbstractInputStreamContent content = new ByteArrayContent( "text/plain", issue.getBody().getBytes(StandardCharsets.UTF_8)); return new RepositoryDoc.Builder() .setItem(item) .setContent(content, IndexingService.ContentFormat.TEXT) .setRequestMode(IndexingService.RequestMode.SYNCHRONOUS) .build(); }
Example #23
Source File: Issues.java From updatebot with Apache License 2.0 | 4 votes |
public static List<GHIssue> getOpenIssues(GHRepository ghRepository, Configuration configuration) throws IOException { String label = configuration.getGithubPullRequestLabel(); return getOpenIssues(ghRepository, label); }
Example #24
Source File: CommandContext.java From updatebot with Apache License 2.0 | 4 votes |
public GHIssue getIssue() { return issue; }
Example #25
Source File: JobHelper.java From github-integration-plugin with MIT License | 4 votes |
public static GHIssue getGhPullRequest(final Run<?, ?> run) throws IOException { return getGhRepositoryFromPRTrigger(run).getPullRequest(getPRNumberFromPRCause(run)); }
Example #26
Source File: JobHelper.java From github-integration-plugin with MIT License | 4 votes |
public static GHIssue getGhIssue(final Run<?, ?> run) throws IOException { return getGhRepositoryFromPRTrigger(run).getIssue(getPRNumberFromPRCause(run)); }
Example #27
Source File: CommandContext.java From updatebot with Apache License 2.0 | 4 votes |
public void setIssue(GHIssue issue) { this.issue = issue; }
Example #28
Source File: UpdatePullRequests.java From updatebot with Apache License 2.0 | 4 votes |
@Override public void run(CommandContext context) throws IOException { Status contextStatus = Status.COMPLETE; GHRepository ghRepository = context.gitHubRepository(); if (ghRepository != null) { // lets look for a pending issue GHIssue issue = getOrFindIssue(context, ghRepository); if (issue != null && isOpen(issue)) { contextStatus = Status.PENDING; } List<GHPullRequest> pullRequests = PullRequests.getOpenPullRequests(ghRepository, context.getConfiguration()); for (GHPullRequest pullRequest : pullRequests) { Configuration configuration = context.getConfiguration(); if (GitHubHelpers.hasLabel(getLabels(pullRequest), configuration.getGithubPullRequestLabel())) { context.setPullRequest(pullRequest); if (!GitHubHelpers.isMergeable(pullRequest)) { // lets re-run the update commands we can find on the PR CompositeCommand commands = loadCommandsFromPullRequest(context, ghRepository, pullRequest); if (commands != null) { commands.run(context, ghRepository, pullRequest); } } if (mergeOnSuccess) { try { GHCommitStatus status = getLastCommitStatus(ghRepository, pullRequest); if (status != null) { GHCommitState state = status.getState(); if (state != null && state.equals(GHCommitState.SUCCESS)) { String message = Markdown.UPDATEBOT_ICON + " merging this pull request as its CI was successful"; pullRequest.merge(message); } } } catch (IOException e) { context.warn(LOG, "Failed to find last commit status for PR " + pullRequest.getHtmlUrl() + " " + e, e); } } if (isOpen(pullRequest)) { contextStatus = Status.PENDING; } } } } context.setStatus(contextStatus); }
Example #29
Source File: GithubAssertions.java From updatebot with Apache License 2.0 | 4 votes |
public static List<GHIssue> assertOpenIssueCount(GHRepository repository, String label, int expectedIssueCount) throws IOException { List<GHIssue> openIssues = Issues.getOpenIssues(repository, label); assertThat(openIssues).describedAs("open github issues with label " + label + ": " + openIssues).hasSize(expectedIssueCount); return openIssues; }
Example #30
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; }