#!/bin/bash tmpfile=$(mktemp pusher.XXXXXX) cleanup() { rm -f "$tmpfile" } trap cleanup EXIT . .settings needed=(PUSH_URL PR_SRC_USER PR_TARGET TOKEN) for i in "${needed[@]}"; do eval test -n "\$$i" || { echo "The following settings are mandatory: ${needed[*]}"; exit 1; } done declare -A commits for m in "${!commits[@]}"; do if git send-pack --force "$PUSH_URL" "${commits[$m]}:refs/heads/update_$m"; then #https://github.com/go-gitea/gitea/issues/18842 if curl -s -f "$PR_TARGET" \ -H "accept: application/json" \ -H "Authorization: token $TOKEN" \ -H "Content-Type: application/json" \ -d "{ \"base\": \"main\", \"head\": \"$PR_SRC_USER: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