github-merge-pr: doc: Install extra git-filter-repo
[maintainer-tools.git] / update_git_source_package.sh
index 1d7f8abb378e1c9a951c5d478f01b5236c6ee5de..d7f823755d6ed7573aa15f703859f01a9017b016 100755 (executable)
@@ -74,7 +74,8 @@ grep -sq BuildPackage "$MAKEFILE" || {
        }
 }
 
-export TOPDIR
+export TOPDIR=$(cd "$TOPDIR"; pwd)
+export PATH="$TOPDIR/staging_dir/host/bin:$PATH"
 
 eval $(
        "$MAKE" --no-print-directory -C "$(dirname "$MAKEFILE")" \
@@ -135,6 +136,48 @@ 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/*)
+                               repourl=${PKG_SOURCE_URL%/}
+                               repourl=${repourl%.git}
+                               echo "${repourl}/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% *}#" \
@@ -151,7 +194,7 @@ eval $(
                var.PKG_SOURCE
 )
 
-"$MAKE" -C "$(dirname "$MAKEFILE")" download || {
+"$MAKE" -C "$(dirname "$MAKEFILE")" download CONFIG_SRC_TREE_OVERRIDE= || {
        echo "Unable to download and pack updated Git sources." >&2
        exit 1
 }
@@ -169,6 +212,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 || {