-
Notifications
You must be signed in to change notification settings - Fork 26
Delete or Update Editorial bot comments when violations are fixed #546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ayagmar
wants to merge
1
commit into
quarkusio:main
Choose a base branch
from
ayagmar:feat/469
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,78 @@ | ||
package io.quarkus.bot; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import jakarta.inject.Singleton; | ||
|
||
import org.jboss.logging.Logger; | ||
import org.kohsuke.github.GHIssue; | ||
import org.kohsuke.github.GHIssueComment; | ||
|
||
import io.quarkus.bot.util.Strings; | ||
|
||
@Singleton | ||
public class GHIssueCommentService { | ||
private static final Logger LOG = Logger.getLogger(GHIssueCommentService.class); | ||
|
||
public void updateComment(GHIssueComment comment, String newText, int issueNumber, boolean isEditorialComment, | ||
boolean isDryRun) { | ||
if (!isDryRun) { | ||
try { | ||
String formattedComment = isEditorialComment ? Strings.editorialCommentByBot(newText) | ||
: Strings.commentByBot(newText); | ||
comment.update(formattedComment); | ||
LOG.debug("Pull request #" + issueNumber + " - Updated comment"); | ||
} catch (IOException e) { | ||
LOG.error(String.format("Pull Request #%s - Failed to update comment %d", | ||
issueNumber, comment.getId()), e); | ||
} | ||
} else { | ||
LOG.info(String.format("Pull Request #%s - Update comment %d with: %s", | ||
issueNumber, comment.getId(), newText)); | ||
} | ||
} | ||
|
||
public void deleteComment(GHIssueComment comment, int issueNumber, boolean isDryRun) { | ||
if (!isDryRun) { | ||
try { | ||
comment.delete(); | ||
LOG.debug("Pull request #" + issueNumber + " - Deleted comment"); | ||
} catch (IOException e) { | ||
LOG.error(String.format("Pull Request #%s - Failed to delete comment %d", | ||
issueNumber, comment.getId()), e); | ||
} | ||
} else { | ||
LOG.info(String.format("Pull Request #%s - Delete comment %d", | ||
issueNumber, comment.getId())); | ||
} | ||
} | ||
|
||
public Optional<GHIssueComment> findBotCommentInIssue(GHIssue GhIssue, String marker) throws IOException { | ||
List<GHIssueComment> comments = GhIssue.getComments(); | ||
if (comments == null || comments.isEmpty()) { | ||
return Optional.empty(); | ||
} | ||
|
||
return comments.stream() | ||
.filter(comment -> comment.getBody() != null) | ||
.filter(comment -> comment.getBody().contains(marker)) | ||
.findFirst(); | ||
} | ||
|
||
public void addComment(GHIssue ghIssue, String comment, boolean isEditorialComment, boolean isDryRun) { | ||
if (!isDryRun) { | ||
try { | ||
String formattedComment = isEditorialComment ? Strings.editorialCommentByBot(comment) | ||
: Strings.commentByBot(comment); | ||
ghIssue.comment(formattedComment); | ||
LOG.debugf("Pull request #%d - Added new comment", ghIssue.getNumber()); | ||
} catch (IOException e) { | ||
LOG.errorf(e, "Pull Request #%d - Failed to add comment", ghIssue.getNumber()); | ||
} | ||
} else { | ||
LOG.infof("Pull request #%d - Add comment (dry-run): %s", ghIssue.getNumber(), comment); | ||
} | ||
} | ||
} |
This file contains hidden or 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,30 @@ | ||
package io.quarkus.bot; | ||
|
||
import java.io.IOException; | ||
|
||
import jakarta.inject.Singleton; | ||
|
||
import org.jboss.logging.Logger; | ||
import org.kohsuke.github.GHIssue; | ||
|
||
import io.quarkus.bot.util.Strings; | ||
|
||
@Singleton | ||
public class GHIssueService { | ||
|
||
private static final Logger LOG = Logger.getLogger(GHIssueService.class); | ||
|
||
public void setIssueTitle(GHIssue issue, String newTitle, boolean isDryRun) { | ||
if (!isDryRun) { | ||
try { | ||
issue.setTitle(newTitle); | ||
LOG.debugf("Pull request #%d - Updated title to: %s", issue.getNumber(), newTitle); | ||
} catch (IOException e) { | ||
LOG.errorf(e, "Pull Request #%d - Failed to update title", issue.getNumber()); | ||
} | ||
} else { | ||
LOG.infof("Pull request #%d - Update title to (dry-run): %s", issue.getNumber(), newTitle); | ||
} | ||
} | ||
|
||
} |
This file contains hidden or 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,47 @@ | ||
package io.quarkus.bot; | ||
|
||
import java.io.IOException; | ||
import java.util.Optional; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.inject.Singleton; | ||
|
||
import org.kohsuke.github.GHIssueComment; | ||
import org.kohsuke.github.GHPullRequest; | ||
|
||
import io.quarkus.bot.config.QuarkusGitHubBotConfig; | ||
|
||
/** | ||
* This class handles all GitHub operations related to bot actions. | ||
* It provides methods for adding, updating, and removing comments on pull requests, | ||
* as well as setting pull request titles. | ||
*/ | ||
@Singleton | ||
class GitHubBotActions { | ||
@Inject | ||
QuarkusGitHubBotConfig quarkusBotConfig; | ||
@Inject | ||
GHIssueService issueService; | ||
@Inject | ||
GHIssueCommentService commentService; | ||
|
||
public void addComment(GHPullRequest pullRequest, String comment, boolean isEditorialComment) { | ||
commentService.addComment(pullRequest, comment, isEditorialComment, quarkusBotConfig.isDryRun()); | ||
} | ||
|
||
public void updateComment(GHIssueComment comment, String newText, int pullRequestNumber, boolean isEditorialComment) { | ||
commentService.updateComment(comment, newText, pullRequestNumber, isEditorialComment, quarkusBotConfig.isDryRun()); | ||
} | ||
|
||
public void deleteComment(GHIssueComment comment, int pullRequestNumber) { | ||
commentService.deleteComment(comment, pullRequestNumber, quarkusBotConfig.isDryRun()); | ||
} | ||
|
||
public void setPullRequestTitle(GHPullRequest pullRequest, String newTitle) { | ||
issueService.setIssueTitle(pullRequest, newTitle, quarkusBotConfig.isDryRun()); | ||
} | ||
|
||
public Optional<GHIssueComment> findBotComment(GHPullRequest pullRequest, String marker) throws IOException { | ||
return commentService.findBotCommentInIssue(pullRequest, marker); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.