From 6439cb98fc7af76ffab08898a5cd0fd8532f53e8 Mon Sep 17 00:00:00 2001 From: xjusko Date: Fri, 25 Apr 2025 14:28:20 +0200 Subject: [PATCH] Skip format and rules check on work-in-progress label. --- .../org/wildfly/bot/LifecycleProcessor.java | 3 ++- .../wildfly/bot/model/RuntimeConstants.java | 1 + .../org/wildfly/bot/util/GithubProcessor.java | 4 ++++ .../wildfly/bot/PRSkipPullRequestTest.java | 22 +++++++++++++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/wildfly/bot/LifecycleProcessor.java b/src/main/java/org/wildfly/bot/LifecycleProcessor.java index 5a68d08..af50e89 100644 --- a/src/main/java/org/wildfly/bot/LifecycleProcessor.java +++ b/src/main/java/org/wildfly/bot/LifecycleProcessor.java @@ -82,7 +82,8 @@ void onStart(@Observes StartupEvent event) { List problems = configFileChangeProcessor.validateFile(wildflyBotConfigFile, repository); githubProcessor.createLabelsIfMissing(repository, - Set.of(RuntimeConstants.LABEL_NEEDS_REBASE, RuntimeConstants.LABEL_FIX_ME)); + Set.of(RuntimeConstants.LABEL_NEEDS_REBASE, RuntimeConstants.LABEL_FIX_ME, + RuntimeConstants.LABEL_WIP)); if (problems.isEmpty()) { LOG.infof("The configuration file from the repository %s was parsed successfully.", diff --git a/src/main/java/org/wildfly/bot/model/RuntimeConstants.java b/src/main/java/org/wildfly/bot/model/RuntimeConstants.java index 2c6e445..7c807c5 100644 --- a/src/main/java/org/wildfly/bot/model/RuntimeConstants.java +++ b/src/main/java/org/wildfly/bot/model/RuntimeConstants.java @@ -13,6 +13,7 @@ public class RuntimeConstants { public static final String LABEL_NEEDS_REBASE = "rebase-this"; public static final String LABEL_FIX_ME = "fix-me"; + public static final String LABEL_WIP = "work-in-progress"; public static final String BOT_MESSAGE_DELIMINER = "\n\n____"; diff --git a/src/main/java/org/wildfly/bot/util/GithubProcessor.java b/src/main/java/org/wildfly/bot/util/GithubProcessor.java index 7216fe9..ba65c8f 100644 --- a/src/main/java/org/wildfly/bot/util/GithubProcessor.java +++ b/src/main/java/org/wildfly/bot/util/GithubProcessor.java @@ -279,6 +279,10 @@ public String skipPullRequest(GHPullRequest pullRequest) throws IOException { return "pull request being a draft"; } + if (pullRequest.getLabels().stream().anyMatch(ghLabel -> ghLabel.getName().equals(RuntimeConstants.LABEL_WIP))) { + return "work in progress label found"; + } + return null; } diff --git a/src/test/java/org/wildfly/bot/PRSkipPullRequestTest.java b/src/test/java/org/wildfly/bot/PRSkipPullRequestTest.java index a009577..aa690c8 100644 --- a/src/test/java/org/wildfly/bot/PRSkipPullRequestTest.java +++ b/src/test/java/org/wildfly/bot/PRSkipPullRequestTest.java @@ -4,6 +4,7 @@ import io.quarkus.test.junit.QuarkusTest; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.wildfly.bot.model.RuntimeConstants; import org.wildfly.bot.utils.TestConstants; import org.wildfly.bot.utils.WildflyGitHubBotTesting; import org.wildfly.bot.utils.mocking.Mockable; @@ -81,4 +82,25 @@ void testSkippingFormatCheckOnDraft() throws Throwable { verifyNoMoreInteractions(mocks.pullRequest(pullRequestJson.id())); }); } + + @Test + void testSkippingFormatCheckOnWipLabel() throws Throwable { + pullRequestJson = TestModel.setPullRequestJsonBuilder( + pullRequestJsonBuilder -> pullRequestJsonBuilder + .title(TestConstants.INVALID_TITLE)); + + mockedContext = MockedGHPullRequest.builder(pullRequestJson.id()).labels(RuntimeConstants.LABEL_WIP); + + TestModel.given(mocks -> WildflyGitHubBotTesting.mockRepo(mocks, wildflyConfigFile, pullRequestJson, mockedContext)) + .pullRequestEvent(pullRequestJson) + .then(mocks -> { + verify(mocks.pullRequest(pullRequestJson.id()), times(2)).getBody(); + verify(mocks.pullRequest(pullRequestJson.id())).listFiles(); + verify(mocks.pullRequest(pullRequestJson.id()), times(2)).isDraft(); + verify(mocks.pullRequest(pullRequestJson.id())).listComments(); + verify(mocks.pullRequest(pullRequestJson.id()), times(2)).getLabels(); // important for WIP skip check + // commit status should not be set + verifyNoMoreInteractions(mocks.pullRequest(pullRequestJson.id())); + }); + } }