From 8eca86393a4f78cde3eb348fd15f209c85153809 Mon Sep 17 00:00:00 2001 From: George Gastaldi Date: Thu, 9 Jun 2022 17:59:14 -0300 Subject: [PATCH] Affect `triage/needs-rebase` on Pull Requests with merge conflicts This adds the `triage/needs-rebase` label (or removes it) on opened pull-requests, making it easier to find pull-requests that require a rebase to be merged --- .../bot/MarkPullRequestAsNeedsRebase.java | 27 +++++++++++++++++++ src/main/java/io/quarkus/bot/util/Labels.java | 1 + 2 files changed, 28 insertions(+) create mode 100644 src/main/java/io/quarkus/bot/MarkPullRequestAsNeedsRebase.java diff --git a/src/main/java/io/quarkus/bot/MarkPullRequestAsNeedsRebase.java b/src/main/java/io/quarkus/bot/MarkPullRequestAsNeedsRebase.java new file mode 100644 index 00000000..67c2b01d --- /dev/null +++ b/src/main/java/io/quarkus/bot/MarkPullRequestAsNeedsRebase.java @@ -0,0 +1,27 @@ +package io.quarkus.bot; + +import io.quarkiverse.githubapp.event.Push; +import io.quarkus.bot.util.Labels; +import org.kohsuke.github.GHEventPayload; +import org.kohsuke.github.GHIssueState; +import org.kohsuke.github.GHPullRequest; +import org.kohsuke.github.GHRepository; + +import java.io.IOException; + +public class MarkPullRequestAsNeedsRebase { + + void maintainNeedsRebaseLabel(@Push GHEventPayload.Push pushRequestPayload) throws IOException { + GHRepository repository = pushRequestPayload.getRepository(); + for (GHPullRequest pullRequest : repository.getPullRequests(GHIssueState.OPEN)) { + Boolean mergeable = pullRequest.getMergeable(); + if (mergeable != null) { + if (mergeable) { + pullRequest.removeLabels(Labels.TRIAGE_NEEDS_REBASE); + } else { + pullRequest.addLabels(Labels.TRIAGE_NEEDS_REBASE); + } + } + } + } +} diff --git a/src/main/java/io/quarkus/bot/util/Labels.java b/src/main/java/io/quarkus/bot/util/Labels.java index 083cb45c..bc71b8e2 100644 --- a/src/main/java/io/quarkus/bot/util/Labels.java +++ b/src/main/java/io/quarkus/bot/util/Labels.java @@ -14,6 +14,7 @@ public class Labels { public static final String AREA_PREFIX = "area/"; public static final String AREA_INFRA = "area/infra"; public static final String TRIAGE_INVALID = "triage/invalid"; + public static final String TRIAGE_NEEDS_REBASE = "triage/needs-rebase"; public static final String TRIAGE_NEEDS_TRIAGE = "triage/needs-triage"; public static final String TRIAGE_WAITING_FOR_CI = "triage/waiting-for-ci"; public static final String TRIAGE_QE = "triage/qe?";