diff options
author | Michał Górny <mgorny@gentoo.org> | 2017-08-31 19:18:40 +0200 |
---|---|---|
committer | Michał Górny <mgorny@gentoo.org> | 2019-04-09 13:05:55 +0200 |
commit | 274990f4b124203b829c53068ee587670c0cf1f7 (patch) | |
tree | 51d280eca18cd7c2d405208803674e3a39952b06 | |
parent | Add an update hook to verify that commits conform to utf8 (diff) | |
download | githooks-274990f4b124203b829c53068ee587670c0cf1f7.tar.gz githooks-274990f4b124203b829c53068ee587670c0cf1f7.tar.bz2 githooks-274990f4b124203b829c53068ee587670c0cf1f7.zip |
Add a git hook to close Gentoo Bugzilla bug reports
Add a GitHub-like hook that recognizes 'Closes', 'Fixes' and 'Resolves'
footer tags to close bugs, and 'Bug' to reference them. If the tag
references a correct Gentoo Bugzilla URL, the hook will leave a nice
verbose comment with commit URL and close the bug if desired.
-rwxr-xr-x | local/update-05-bugs | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/local/update-05-bugs b/local/update-05-bugs new file mode 100755 index 0000000..65e1f23 --- /dev/null +++ b/local/update-05-bugs @@ -0,0 +1,79 @@ +#!/bin/bash +# Copyright 2017 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 or later + +# Author: Michał Górny <mgorny@gentoo.org> + +refname=$1 +oldrev=$2 +newrev=$3 + +export LC_MESSAGES=C +export TZ=UTC + +shopt -o -s noglob + +while read commithash; do + while read l; do + case ${l} in + # kinda-like github/gitlab/bitbucket but: + # 1. we accept only -s forms for simplicity, + # 2. we accept only footer-style to avoid false positives, + # 3. we have to scan the whole commit message because + # developers still fail to have just one footer. + Closes:*|Resolves:*|Fixes:*) + close=1;; + # alternate form to ref without closing + Bug:*) + close=0;; + *) + continue;; + esac + + # strip whitespace, split words + bugref=( ${l#*:} ) + for bug in "${bugref[@]}"; do + case ${bug} in + # long bugzilla URL + http://bugs.gentoo.org/show_bug.cgi\?*|https://bugs.gentoo.org/show_bug.cgi\?*) + bugno=${bug#*[?&]id=} + bugno=${bugno%%[&#]*} + ;; + # short bugzilla URL + http://bugs.gentoo.org/[0-9]*|https://bugs.gentoo.org/[0-9]*) + bugno=${bug##*/} + bugno=${bugno%%[?#]*} + ;; + # silently ignore github, mirror hook will handle it + http://github.com/*|https://github.com/*) + continue;; + *) + echo "WARNING: invalid/unsupported bug ref: ${bug}" + continue;; + esac + + if [[ -n ${bugno//[0-9]} ]]; then + echo "WARNING: invalid Gentoo Bugzilla URL: ${bug}" + continue + fi + + if [[ ${close} == 1 ]]; then + extra_args=( -s RESOLVED -r FIXED ) + newmsg="Bug has been closed via the following commit:" + else + extra_args=() + newmsg="Bug has been referenced in the following commit:" + fi + + newmsg+=" +https://gitweb.gentoo.org/${GL_REPO}.git/commit/?id=${commithash} + +$(git show --pretty=fuller --date=iso-local --stat "${commithash}")" +# TODO: --show-signature with some nice short output + + bugz modify "${extra_args[@]}" -c "${newmsg}" "${bugno}" + done + done < <(git show -q --pretty=format:'%B' "${commithash}") +done < <(git rev-list "${oldrev}..${newrev}") + +exit 0 |