From 365367136938c189ee6ec683d6a263e117a4564a Mon Sep 17 00:00:00 2001 From: Ludwig Nussel Date: Wed, 16 Nov 2022 15:01:09 +0100 Subject: [PATCH] start --- updatemodules | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100755 updatemodules diff --git a/updatemodules b/updatemodules new file mode 100755 index 0000000..88905f3 --- /dev/null +++ b/updatemodules @@ -0,0 +1,80 @@ +#!/bin/bash +pushurl="gitea@gitea.opensuse.org:lnussel/core.git" +prsrcusr="lnussel" +prtarget="https://gitea.opensuse.org/api/v1/repos/mold/core/pulls" + +modules=($@) +origin="$(git config --get remote.origin.url)" +#now="$(date "+%s %z")" +# FIXME: hardcoded to avoid changing commits for now +now="1668592380 +0100" +export GIT_AUTHOR_NAME="Auto" +export GIT_AUTHOR_EMAIL="auto@suse.de" +export GIT_AUTHOR_DATE="$now" +export GIT_COMMITTER_NAME="Auto" +export GIT_COMMITTER_EMAIL="auto@suse.de" +export GIT_COMMITTER_DATE="$now" + +tmpfile=$(mktemp updatemodules.XXXXXX) +cleanup() +{ + rm -f "$tmpfile" +} +trap cleanup EXIT + +read token < token || exit 1 + +declare -A revs +while read m t cid p; do + [ "$t" = "commit" ] || continue + revs["$p"]="$cid" +done < <(git cat-file -p HEAD^{tree}) + +if [ -z "$modules" ]; then + modules=("${!revs[@]}") +fi + +declare -A commits +for m in "${modules[@]}"; do + path="$(git config -f .gitmodules --get "submodule.$m.path")" + url="$(git config -f .gitmodules --get "submodule.$m.url")" + branch="$(git config -f .gitmodules --get "submodule.$m.branch")" + if [ -z "$path" -o -z "$url" ]; then + echo "$m unknown" >&2 + continue + fi + if [ "${url:0:3}" = '../' ]; then + url="$origin/$url" + fi + read cid _d < <(git ls-remote "$url" "${branch:-HEAD}") + if [ -z "${revs[$path]}" ]; then + echo "$path unknown" >&2 + continue + fi + if [ "${revs[$path]}" != "$cid" ]; then + echo "Needs update: $path@${revs[$path]} -> $cid" + newtree="$(git cat-file -p HEAD^{tree} | sed -e "s/${revs[$path]}\t$path/$cid\t$path/" | git mktree)" + newcid="$(git commit-tree -p HEAD -m "Update $m" "$newtree")" + commits["$m"]="$newcid" + fi +done + +for m in "${!commits[@]}"; do + if git send-pack --force "$pushurl" "${commits[$m]}:refs/heads/update_$m"; then + #https://github.com/go-gitea/gitea/issues/18842 + if curl -s -f "$prtarget" \ + -H "accept: application/json" \ + -H "Authorization: token $token" \ + -H "Content-Type: application/json" \ + -d "{ \"base\": \"main\", \"head\": \"$prsrcusr:update_$m\", \"title\": \"Update $m\"}" > "$tmpfile"; then + prid=$(jq .id < "$tmpfile") + echo "filed pr #$prid for $m" + else + echo "failed to file pr for $m" + jq .message < "$tmpfile" + fi + else + echo "failed to push $m update" >&2 + jq .message < "$tmpfile" + fi +done