From 48e9003a27d8fb5a706a50ea4b1a477923ae905f Mon Sep 17 00:00:00 2001 From: Jack Date: Mon, 19 Aug 2024 17:12:41 +0100 Subject: [PATCH 1/2] Prevent triggering builds on closed PRs Skips all kind of event triggers for closed PRs, rather than just for comments as per https://github.com/jenkinsci/ghprb-plugin/pull/54. Fixes: https://github.com/jenkinsci/ghprb-plugin/issues/865 --- .../org/jenkinsci/plugins/ghprb/GhprbRootAction.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/jenkinsci/plugins/ghprb/GhprbRootAction.java b/src/main/java/org/jenkinsci/plugins/ghprb/GhprbRootAction.java index 9a8d39fc..66b5c220 100644 --- a/src/main/java/org/jenkinsci/plugins/ghprb/GhprbRootAction.java +++ b/src/main/java/org/jenkinsci/plugins/ghprb/GhprbRootAction.java @@ -137,16 +137,14 @@ private void handleAction(String event, try { GitHub gh = GitHub.connectAnonymously(); - if (StringUtils.equalsIgnoreCase("issue_comment", event)) { + if (state == GHIssueState.CLOSED) { + LOGGER.log(Level.INFO, "Skip ''{0}'' event on closed PR", event); + return; + } else if (StringUtils.equalsIgnoreCase("issue_comment", event)) { comment = getIssueComment(payload, gh); GHIssueState state = comment.getIssue().getState(); - if (state == GHIssueState.CLOSED) { - LOGGER.log(Level.INFO, "Skip comment on closed PR"); - return; - } - if (!comment.getIssue().isPullRequest()) { LOGGER.log(Level.INFO, "Skip comment on Issue"); return; From 373a6b8fef4853bda73c403ec18fa12d8fa53412 Mon Sep 17 00:00:00 2001 From: Jack Date: Mon, 19 Aug 2024 17:24:51 +0100 Subject: [PATCH 2/2] Fix compile issue --- .../plugins/ghprb/GhprbRootAction.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/jenkinsci/plugins/ghprb/GhprbRootAction.java b/src/main/java/org/jenkinsci/plugins/ghprb/GhprbRootAction.java index 66b5c220..39570952 100644 --- a/src/main/java/org/jenkinsci/plugins/ghprb/GhprbRootAction.java +++ b/src/main/java/org/jenkinsci/plugins/ghprb/GhprbRootAction.java @@ -137,14 +137,16 @@ private void handleAction(String event, try { GitHub gh = GitHub.connectAnonymously(); - if (state == GHIssueState.CLOSED) { - LOGGER.log(Level.INFO, "Skip ''{0}'' event on closed PR", event); - return; - } else if (StringUtils.equalsIgnoreCase("issue_comment", event)) { + if (StringUtils.equalsIgnoreCase("issue_comment", event)) { comment = getIssueComment(payload, gh); GHIssueState state = comment.getIssue().getState(); + if (state == GHIssueState.CLOSED) { + LOGGER.log(Level.INFO, "Skip comment on closed PR"); + return; + } + if (!comment.getIssue().isPullRequest()) { LOGGER.log(Level.INFO, "Skip comment on Issue"); return; @@ -159,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()});