-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First stab at maintain-one-comment action
- Loading branch information
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/io/quarkus/bot/maintainonecomment/MaintainOneCommentAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |