Java Code Examples for org.kohsuke.github.GHPullRequest#getComments()

The following examples show how to use org.kohsuke.github.GHPullRequest#getComments() . 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: UpdatePullRequests.java    From updatebot with Apache License 2.0 6 votes vote down vote up
/**
 * Lets load the old command context from comments on the PullRequest so that we can re-run a command to rebase things.
 */
protected CompositeCommand loadCommandsFromPullRequest(CommandContext context, GHRepository ghRepository, GHPullRequest pullRequest) throws IOException {
    List<GHIssueComment> comments = pullRequest.getComments();
    String lastCommand = null;
    for (GHIssueComment comment : comments) {
        String command = updateBotCommentCommand(context, comment);
        if (command != null) {
            lastCommand = command;
        }
    }
    if (lastCommand == null) {
        context.warn(LOG, "No UpdateBot comment found on pull request " + pullRequest.getHtmlUrl() + " so cannot rebase!");
        return null;
    }
    return parseUpdateBotCommandComment(context, lastCommand);
}
 
Example 2
Source File: GitHubPRCommentEvent.java    From github-integration-plugin with MIT License 5 votes vote down vote up
@Override
public GitHubPRCause check(@Nonnull GitHubPRDecisionContext prDecisionContext) {
    final TaskListener listener = prDecisionContext.getListener();
    final PrintStream llog = listener.getLogger();
    final GitHubPRPullRequest localPR = prDecisionContext.getLocalPR();
    final GHPullRequest remotePR = prDecisionContext.getRemotePR();
    final GitHubPRUserRestriction prUserRestriction = prDecisionContext.getPrUserRestriction();

    GitHubPRCause cause = null;
    try {
        for (GHIssueComment issueComment : remotePR.getComments()) {
            if (isNull(localPR) // test all comments for trigger word even if we never saw PR before
                    || isNull(localPR.getLastCommentCreatedAt()) // PR was created but had no comments
                    // don't check comments that we saw before
                    || localPR.getLastCommentCreatedAt().compareTo(issueComment.getCreatedAt()) < 0) {
                llog.printf("%s: state has changed (new comment found - '%s')%n",
                        DISPLAY_NAME, issueComment.getBody());

                cause = checkComment(prDecisionContext, issueComment, prUserRestriction, listener);
                if (nonNull(cause)) {
                    break;
                }
            }
        }
    } catch (Exception e) {
        LOG.warn("Couldn't obtain comments: {}", e);
        listener.error("Couldn't obtain comments", e);
    }

    if (isNull(cause)) {
        LOG.debug("No matching comments found for {}", remotePR.getNumber());
        llog.println("No matching comments found for " + remotePR.getNumber());
    }

    return cause;
}
 
Example 3
Source File: GithubRepository.java    From cloud-search-samples with Apache License 2.0 4 votes vote down vote up
/**
 * Build the ApiOperation to index a pull request.
 *
 * @param pullRequest  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(GHPullRequest pullRequest, Item previousItem)
    throws IOException {
  String metadataHash = pullRequest.getUpdatedAt().toString();

  // If previously indexed and unchanged, just requeue as unmodified
  if (canSkipIndexing(previousItem, metadataHash)) {
    return notModified(previousItem.getName());
  }

  String resourceName = pullRequest.getHtmlUrl().getPath();
  FieldOrValue<String> title = FieldOrValue.withValue(pullRequest.getTitle());
  FieldOrValue<String> url = FieldOrValue.withValue(
      pullRequest.getHtmlUrl().toExternalForm());
  FieldOrValue<DateTime> createTime = FieldOrValue.withValue(
      new DateTime(pullRequest.getCreatedAt().getTime()));
  FieldOrValue<DateTime> updateTime = FieldOrValue.withValue(
      new DateTime(pullRequest.getUpdatedAt().getTime()));
  String containerName = pullRequest.getRepository().getHtmlUrl().getPath();

  // Structured data based on the schema
  Multimap<String, Object> structuredData = ArrayListMultimap.create();
  structuredData.put("organization", pullRequest.getRepository().getOwnerName());
  structuredData.put("repository", pullRequest.getRepository().getName());
  structuredData.put("status", pullRequest.getState().name().toLowerCase());
  structuredData.put("openedBy", pullRequest.getUser() != null ?
      pullRequest.getUser().getLogin() : null);
  structuredData.put("assignee", pullRequest.getAssignee() != null ?
      pullRequest.getAssignee().getLogin() : null);
  for (GHLabel label : pullRequest.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 : pullRequest.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", pullRequest.getCreatedAt());
  structuredData.put("updatedAt", pullRequest.getUpdatedAt());

  Item item = IndexingItemBuilder.fromConfiguration(resourceName)
      .setTitle(title)
      .setContainerName(containerName)
      .setSourceRepositoryUrl(url)
      .setItemType(IndexingItemBuilder.ItemType.CONTAINER_ITEM)
      .setObjectType("pullRequest")
      .setValues(structuredData)
      .setVersion(Longs.toByteArray(pullRequest.getUpdatedAt().getTime()))
      .setCreateTime(createTime)
      .setUpdateTime(updateTime)
      .setHash(metadataHash)
      .build();

  // TODO - Index the actual patch/diff?
  // TODO - Render markdown to HTML
  AbstractInputStreamContent content = new ByteArrayContent(
      "text/plain",
      pullRequest.getBody().getBytes(StandardCharsets.UTF_8));
  return new RepositoryDoc.Builder()
      .setItem(item)
      .setContent(content, IndexingService.ContentFormat.TEXT)
      .setRequestMode(IndexingService.RequestMode.SYNCHRONOUS)
      .build();
}