Skip to content

Commit

Permalink
First stab at maintain-one-comment action
Browse files Browse the repository at this point in the history
  • Loading branch information
gsmet committed Aug 11, 2024
1 parent b7cbd36 commit beba14c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
9 changes: 9 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ inputs:
build-metadata-file-path:
description: 'Path to the build-metadata.json file'
required: false
body:
description: 'Body of the comment'
required: false
body-marker:
description: 'Comment marker'
required: false
pr-number:
description: 'The number of the pull request'
required: false
runs:
using: "composite"
steps:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.quarkus.bot.maintainonecomment;

import java.io.IOException;
import java.util.Optional;

import org.kohsuke.github.GHIssueComment;
import org.kohsuke.github.GHPullRequest;
import org.kohsuke.github.GHRepository;
import org.kohsuke.github.GitHub;

import io.quarkiverse.githubaction.Action;
import io.quarkiverse.githubaction.Context;
import io.quarkiverse.githubaction.Inputs;

public class MaintainOneCommentAction {

@Action("maintain-one-comment")
void maintainOneComment(Context context, Inputs inputs, GitHub gitHub) throws IOException {
String body = inputs.getRequired("body");
String bodyMarker = inputs.getRequired("body-marker");
int prNumber = inputs.getRequiredInt("pr-number");

GHRepository repository = gitHub.getRepository(context.getGitHubRepository());
GHPullRequest pullRequest = repository.getPullRequest(prNumber);

Optional<GHIssueComment> maintainedComment = pullRequest.listComments().toList().stream()
.filter(c -> c.getBody() != null && c.getBody().contains(bodyMarker))
.findFirst();

String markedBody = body + "\n\n" + bodyMarker;

if (maintainedComment.isEmpty()) {
pullRequest.comment(markedBody);
} else {
maintainedComment.get().update(markedBody);
}
}
}

0 comments on commit beba14c

Please sign in to comment.