[PATCH infra/githooks] local/postrecv-bugs: only close bugs when pushing to specific branches

Thomas Bracht Laumann Jespersen <[email protected]>
Newsgroups gmane.linux.gentoo.devel
Message-ID <[email protected]>
Introduce a "gentoo.bugs.close-branches" config option, similar to the
existing "gentoo.bugs.allowed-branches". When a commit with a
"Closes:" trailer lands on an allowed branch, a comment is posted on
the referenced bug, but only on "close-branches" will the bug be
closed. Essentially, we treat "Closes:" like "Bug:" unless the branch
being pushed to is on the "close-branches" list.

Closes: https://bugs.gentoo.org/980503
Signed-off-by: Thomas Bracht Laumann Jespersen <[email protected]>
---

I don't think this is the final version, but I'd like some feedback on
this idea. Ideally, "close-branches" is a subset of
"allowed-branches", maybe it would make sense to have "close-branches"
default to the value of "allowed-branches".

 local/postrecv-bugs | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/local/postrecv-bugs b/local/postrecv-bugs
index 37a52f5..04aa591 100755
--- a/local/postrecv-bugs
+++ b/local/postrecv-bugs
@@ -1,6 +1,6 @@
 #!/bin/bash
 # gentoo-infra: infra/githooks.git:postrecv-bugs
-# Copyright 2017-2024 Gentoo Authors
+# Copyright 2017-2026 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2 or later

 # Author: Michał Górny <[email protected]>
@@ -12,6 +12,7 @@ export TZ=UTC
 shopt -o -s noglob

 ALLOWED_BRANCHES=$(git config --get gentoo.bugs.allowed-branches)
+CLOSE_BRANCHES=$(git config --get gentoo.bugs.close-branches)

 declare -A COMMENT_BUGS=()
 declare -A CLOSE_BUGS=()
@@ -30,6 +31,14 @@ while read -r oldrev newrev refname; do
     done
     [[ ${allowed} == 0 ]] && continue

+    close_allowed=0
+    for close_branch in ${CLOSE_BRANCHES:-master}; do
+        if [[ ${refname#refs/heads/} == ${close_branch} ]]; then
+            close_allowed=1
+            break
+        fi
+    fi
+
     while read -r commithash; do
         while read -r l; do
             is_fixes=0
@@ -40,7 +49,11 @@ while read -r oldrev newrev refname; do
                 # 3. we have to scan the whole commit message because
                 # developers still fail to have just one footer.
                 Closes:*|Resolves:*)
-                    close=1;;
+                    if [[ ${close_allowed} == 1 ]]; then
+                        close=1
+                    else
+                        close=0
+                    fi;;
                 # normally used to reference commit ids
                 Fixes:*)
                     is_fixes=1
--
2.54.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.