Skip to content

Commit

Permalink
Merge pull request #89 from glefloch/fix/33
Browse files Browse the repository at this point in the history
Remove invalid label when issues or pull requests are reopen
  • Loading branch information
gsmet authored Apr 23, 2021
2 parents 2d8b82a + 5473e86 commit 3dfd399
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/main/java/io/quarkus/bot/RemoveInvalidLabelOnReopenAction.java
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);
}
}
}

}
16 changes: 16 additions & 0 deletions src/main/java/io/quarkus/bot/util/GHPullRequests.java
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;
}
}

0 comments on commit 3dfd399

Please sign in to comment.