logo

overlay

My own overlay for experimentations, use with caution, no support is provided git clone https://hacktivis.me/git/overlay.git

post-receive.bugs (4304B)


  1. #!/bin/bash
  2. # gentoo-infra: infra/githooks.git:postrecv-bugs
  3. # Copyright 2017 Gentoo Foundation
  4. # Distributed under the terms of the GNU General Public License v2 or later
  5. # Author: Michał Górny <mgorny@gentoo.org>
  6. export LANG=en_US.UTF-8
  7. export LC_MESSAGES=C
  8. export TZ=UTC
  9. shopt -o -s noglob
  10. ALLOWED_BRANCHES=$(git config --get gentoo.bugs.allowed-branches)
  11. declare -A COMMENT_BUGS=()
  12. declare -A CLOSE_BUGS=()
  13. while read -r oldrev newrev refname; do
  14. # operate only on branches in gentoo.bugs.allowed-branches
  15. # (or 'master' if unset)
  16. allowed=0
  17. for allowed_branch in ${ALLOWED_BRANCHES:-master}; do
  18. if [[ ${refname#refs/heads/} == ${allowed_branch} ]]; then
  19. allowed=1
  20. break
  21. fi
  22. done
  23. [[ ${allowed} == 0 ]] && continue
  24. while read -r commithash; do
  25. while read -r l; do
  26. is_fixes=0
  27. case ${l} in
  28. # kinda-like github/gitlab/bitbucket but:
  29. # 1. we accept only -s forms for simplicity,
  30. # 2. we accept only footer-style to avoid false positives,
  31. # 3. we have to scan the whole commit message because
  32. # developers still fail to have just one footer.
  33. Closes:*|Resolves:*)
  34. close=1;;
  35. # normally used to reference commit ids
  36. Fixes:*)
  37. is_fixes=1
  38. close=1;;
  39. # alternate form to ref without closing
  40. Bug:*)
  41. close=0;;
  42. *)
  43. continue;;
  44. esac
  45. # strip whitespace, split words
  46. bugref=( ${l#*:} )
  47. if [[ ${is_fixes} == 1 ]]; then
  48. case ${bugref} in
  49. # commit ref
  50. [0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]*)
  51. continue;;
  52. *)
  53. echo "WARNING: 'Fixes' tag should reference commit id, not: ${bugref[*]}"
  54. ;;
  55. esac
  56. fi
  57. for bug in "${bugref[@]}"; do
  58. case ${bug} in
  59. # long bugzilla URL
  60. http://bugs.gentoo.org/show_bug.cgi\?*|https://bugs.gentoo.org/show_bug.cgi\?*)
  61. bugno=${bug#*[?&]id=}
  62. bugno=${bugno%%[&#]*}
  63. ;;
  64. # short bugzilla URL
  65. http://bugs.gentoo.org/[0-9]*|https://bugs.gentoo.org/[0-9]*)
  66. bugno=${bug##*/}
  67. bugno=${bugno%%[?#]*}
  68. ;;
  69. # silently ignore github, mirror hook will handle it
  70. http://github.com/*|https://github.com/*)
  71. continue;;
  72. *)
  73. echo "WARNING: invalid/unsupported bug ref: ${bug}"
  74. continue;;
  75. esac
  76. if [[ -n ${bugno//[0-9]} ]]; then
  77. echo "WARNING: invalid Gentoo Bugzilla URL: ${bug}"
  78. continue
  79. fi
  80. newmsg="
  81. https://hacktivis.me/git/overlay/commit/${commithash}.html
  82. $(git show --pretty=fuller --date=iso-local --stat "${commithash}")"
  83. # TODO: --show-signature with some nice short output
  84. if [[ ${close} == 1 ]]; then
  85. CLOSE_BUGS[${bugno}]+=${newmsg}
  86. else
  87. COMMENT_BUGS[${bugno}]+=${newmsg}
  88. fi
  89. done
  90. done < <(git show -q --pretty=format:'%B' "${commithash}")
  91. done < <(git rev-list "${oldrev}..${newrev}")
  92. done
  93. for bug in "${!CLOSE_BUGS[@]}"; do
  94. msg="The bug has been closed via the following commit(s):${CLOSE_BUGS[${bug}]}"
  95. if [[ -n ${COMMENT_BUGS[${bug}]} ]]; then
  96. msg+="
  97. Additionally, it has been referenced in the following commit(s):${COMMENT_BUGS[${bug}]}"
  98. fi
  99. bugz modify -s RESOLVED -r FIXED -c "${msg}" "${bug}"
  100. done
  101. for bug in "${!COMMENT_BUGS[@]}"; do
  102. [[ -n ${CLOSE_BUGS[${bug}]} ]] && continue
  103. msg="The bug has been referenced in the following commit(s):${COMMENT_BUGS[${bug}]}"
  104. bugz modify -c "${msg}" "${bug}"
  105. done
  106. exit 0