Skip to content

Commit

Permalink
Don't run bug actions on closed issues
Browse files Browse the repository at this point in the history
Signed-off-by: stianst <[email protected]>
  • Loading branch information
stianst committed Mar 7, 2024
1 parent 4e825b2 commit 10ec09c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
16 changes: 12 additions & 4 deletions src/main/java/org/keycloak/gh/bot/BugActionsOnComment.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
import org.keycloak.gh.bot.labels.Kind;
import org.keycloak.gh.bot.utils.Labels;
import org.kohsuke.github.GHEventPayload;
import org.kohsuke.github.GHIssue;
import org.kohsuke.github.GHIssueComment;
import org.kohsuke.github.GHIssueState;
import org.kohsuke.github.GHOrganization;
import org.kohsuke.github.GHUser;

import java.io.IOException;
Expand All @@ -19,12 +23,16 @@ public class BugActionsOnComment {
BugActions bugActions;

void onCommentCreated(@IssueComment.Created GHEventPayload.IssueComment payload) throws IOException {
if (Labels.hasLabel(payload.getIssue(), Kind.BUG.toLabel())) {
Action action = getAction(payload.getComment().getBody());
GHIssue issue = payload.getIssue();

if (issue.getState().equals(GHIssueState.OPEN) && Labels.hasLabel(issue, Kind.BUG.toLabel())) {
GHIssueComment comment = payload.getComment();
Action action = getAction(comment.getBody());
if (action != null) {
GHUser sender = payload.getSender();
if (sender.getType().equals("User") && sender.isMemberOf(payload.getOrganization())) {
bugActions.runAction(action, payload.getIssue());
GHOrganization organization = payload.getOrganization();
if (sender.getType().equals("User") && sender.isMemberOf(organization)) {
bugActions.runAction(action, issue);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/keycloak/gh/bot/BugActionsOnLabel.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.keycloak.gh.bot.labels.Action;
import org.kohsuke.github.GHEventPayload;
import org.kohsuke.github.GHIssue;
import org.kohsuke.github.GHIssueState;

import java.io.IOException;

Expand All @@ -17,7 +18,7 @@ void onLabeled(@Issue.Labeled GHEventPayload.Issue payload) throws IOException {
String label = payload.getLabel().getName();
GHIssue issue = payload.getIssue();

if (Action.isInstance(label)) {
if (issue.getState().equals(GHIssueState.OPEN) && Action.isInstance(label)) {
Action action = Action.fromLabel(label);
bugActions.runAction(action, issue);
}
Expand Down

0 comments on commit 10ec09c

Please sign in to comment.