From 0d8b1fea1e8c8c65f7d654e5d954cce01d40a4b6 Mon Sep 17 00:00:00 2001 From: Jack Green Date: Wed, 4 Sep 2024 09:05:27 +0100 Subject: [PATCH] Prevent triggering builds on closed PRs [DI-248] (#40) Skips all kind of event triggers for closed PRs, rather than just for comments as per https://github.com/jenkinsci/ghprb-plugin/pull/54. I've not added a test to cover this, as there's no existing test coverage for `pull_request` events in `org.jenkinsci.plugins.ghprb.GhprbRootActionTest`, nor is there any example payloads in `org.jenkinsci.plugins.ghprb.GhprbTestUtil`. Fixes: https://github.com/jenkinsci/ghprb-plugin/issues/865, [DI-248](https://hazelcast.atlassian.net/browse/DI-248) Post-merge actions: - [ ] Deploy in Jenkins - [ ] Test - [ ] Raise upstream PR [DI-248]: https://hazelcast.atlassian.net/browse/DI-248?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ --- .../java/org/jenkinsci/plugins/ghprb/GhprbRootAction.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/org/jenkinsci/plugins/ghprb/GhprbRootAction.java b/src/main/java/org/jenkinsci/plugins/ghprb/GhprbRootAction.java index 9a8d39fc..39570952 100644 --- a/src/main/java/org/jenkinsci/plugins/ghprb/GhprbRootAction.java +++ b/src/main/java/org/jenkinsci/plugins/ghprb/GhprbRootAction.java @@ -161,6 +161,13 @@ private void handleAction(String event, } else if (StringUtils.equalsIgnoreCase("pull_request", event)) { pr = getPullRequest(payload, gh); + GHIssueState state = pr.getPullRequest().getState(); + + if (state == GHIssueState.CLOSED) { + LOGGER.log(Level.INFO, "Skip ''{0}'' event on closed PR", event); + return; + } + repoName = pr.getRepository().getFullName(); LOGGER.log(Level.INFO, "Checking PR #{1} for {0}", new Object[] {repoName, pr.getNumber()});