update_git_source_package: add fixed issues to commit message
authorJo-Philipp Wich <jo@mein.io>
Tue, 14 Nov 2023 14:36:08 +0000 (15:36 +0100)
committerJo-Philipp Wich <jo@mein.io>
Tue, 14 Nov 2023 14:36:53 +0000 (15:36 +0100)
Add some heuristics to map `Fixes:` tags in commit messages to issue URLs.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
update_git_source_package.sh

index 1d7f8abb378e1c9a951c5d478f01b5236c6ee5de..7f6645e453ccd72455a813802b5c7db55ef44f3d 100755 (executable)
@@ -135,6 +135,46 @@ GIT_DATE_COMMIT=$(git -C "$TEMP_GIT_DIR" log \
        exit 1
 }
 
+GIT_FIXES="$(
+       IFS=$', \t\n'
+       for issue in $(
+               git -C "$TEMP_GIT_DIR" log \
+                       --format="%b" \
+                       "$PKG_SOURCE_VERSION..$COMMIT" \
+               | sed -rne 's%^Fixes:(([ ,]*([[:alnum:]_]*#[0-9]+|https?://[^[:space:]]+))+)$%\1%p'
+       ); do
+               case "$issue" in
+               http://*|https://*)
+                       echo "$issue"
+               ;;
+               GH#[0-9]*|openwrt#[0-9]*)
+                       echo "https://github.com/openwrt/openwrt/issues/${issue#*#}"
+               ;;
+               FS#[0-9]*)
+                       echo "https://bugs.openwrt.org/?task_id=${issue#FS#}"
+               ;;
+               [a-zA-Z0-9_]*#[0-9]*)
+                       echo "https://github.com/openwrt/${issue%#*}/issues/${issue#*#}"
+               ;;
+               '#'[0-9]*)
+                       case "$PKG_SOURCE_URL" in
+                       *://github.com/*)
+                               echo "${PKG_SOURCE_URL%/}/issues/${issue#\#}"
+                       ;;
+                       *://git.openwrt.org/project/*)
+                               project=${PKG_SOURCE_URL#*://git.openwrt.org/project/}
+                               project=${project%.git}
+                               echo "https://github.com/openwrt/${project}/issues/${issue#\#}"
+                       ;;
+                       esac
+               ;;
+               esac
+       done \
+       | sort --version-sort \
+       | uniq \
+       | sed -e 's#^#Fixes: #'
+)"
+
 sed -i -r \
        -e "/PKG_SOURCE_VERSION/s#\<$PKG_SOURCE_VERSION\>#${GIT_DATE_COMMIT#* }#" \
        -e "/PKG_SOURCE_DATE/s#\<$PKG_SOURCE_DATE\>#${GIT_DATE_COMMIT% *}#" \
@@ -169,6 +209,7 @@ git -C "$(dirname "$MAKEFILE")" commit \
        --signoff --no-edit \
        --message "$PKG_NAME: update to Git $COMMIT (${GIT_DATE_COMMIT% *})" \
        --message "$GIT_LOG" \
+       ${GIT_FIXES:+--message "$GIT_FIXES"} \
        "$(basename "$MAKEFILE")"
 
 "$MAKE" --no-print-directory -C "$(dirname "$MAKEFILE")" check || {