-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove invalid label when issues or pull requests are reopen
- Loading branch information
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
src/main/java/io/quarkus/bot/RemoveInvalidLabelOnReopenAction.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,47 @@ | ||
package io.quarkus.bot; | ||
|
||
import io.quarkiverse.githubapp.event.Issue; | ||
import io.quarkiverse.githubapp.event.PullRequest; | ||
import io.quarkus.bot.config.QuarkusBotConfig; | ||
import io.quarkus.bot.util.GHIssues; | ||
import io.quarkus.bot.util.GHPullRequests; | ||
import io.quarkus.bot.util.Labels; | ||
import org.jboss.logging.Logger; | ||
import org.kohsuke.github.GHEventPayload; | ||
import org.kohsuke.github.GHIssue; | ||
import org.kohsuke.github.GHPullRequest; | ||
|
||
import javax.inject.Inject; | ||
import java.io.IOException; | ||
|
||
class RemoveInvalidLabelOnReopenAction { | ||
private static final Logger LOG = Logger.getLogger(RemoveInvalidLabelOnReopenAction.class); | ||
|
||
@Inject | ||
QuarkusBotConfig quarkusBotConfig; | ||
|
||
public void onIssueReopen(@Issue.Reopened GHEventPayload.Issue issuePayload) throws IOException { | ||
GHIssue issue = issuePayload.getIssue(); | ||
|
||
if (GHIssues.hasLabel(issue, Labels.TRIAGE_INVALID)) { | ||
if (!quarkusBotConfig.isDryRun()) { | ||
issue.removeLabel(Labels.TRIAGE_INVALID); | ||
} else { | ||
LOG.info("Issue #" + issue.getNumber() + " - Remove label: " + Labels.TRIAGE_INVALID); | ||
} | ||
} | ||
} | ||
|
||
public void onPullRequestReopen(@PullRequest.Reopened GHEventPayload.PullRequest pullRequestPayload) throws IOException { | ||
GHPullRequest pullRequest = pullRequestPayload.getPullRequest(); | ||
|
||
if (GHPullRequests.hasLabel(pullRequest, Labels.TRIAGE_INVALID)) { | ||
if (!quarkusBotConfig.isDryRun()) { | ||
pullRequest.removeLabel(Labels.TRIAGE_INVALID); | ||
} else { | ||
LOG.info("Pull request #" + pullRequest.getNumber() + " - Remove label: " + Labels.TRIAGE_INVALID); | ||
} | ||
} | ||
} | ||
|
||
} |
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,16 @@ | ||
package io.quarkus.bot.util; | ||
|
||
import org.kohsuke.github.GHLabel; | ||
import org.kohsuke.github.GHPullRequest; | ||
|
||
public final class GHPullRequests { | ||
|
||
public static boolean hasLabel(GHPullRequest pullRequest, String labelName) { | ||
for (GHLabel label : pullRequest.getLabels()) { | ||
if (labelName.equals(label.getName())) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |