diff --git a/README.adoc b/README.adoc index 0f78f3f3..2e1ea089 100644 --- a/README.adoc +++ b/README.adoc @@ -167,6 +167,11 @@ The bot will automatically remove these labels when they are outdated: The bot enforces a specific color for any label created that starts with `area/` so that all these labels are consistent. +=== Include `triage/needs-rebase` on unmergeable pull-requests + +Pull requests may require a rebase when conflicts appear. The bot includes a `triage/needs-rebase` label on pull-requests that cannot be merged and removes it when the pull-request is in a mergeable state again. + + == Contributing To participate to the development of this GitHub App, create a playground project in your own org and 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?";