Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8205215c17 | |||
| 36514286aa | |||
| cc271abedb | |||
| 25ed57da53 |
@@ -33,6 +33,34 @@ jobs:
|
|||||||
echo "API status: $HTTP_CODE"
|
echo "API status: $HTTP_CODE"
|
||||||
if [ "$HTTP_CODE" = "201" ]; then
|
if [ "$HTTP_CODE" = "201" ]; then
|
||||||
echo "PR created"; cat /tmp/pr_resp.json
|
echo "PR created"; cat /tmp/pr_resp.json
|
||||||
|
PR_NUMBER=$(cat /tmp/pr_resp.json | sed -n 's/.*"number":\([0-9]*\).*/\1/p' | head -n1)
|
||||||
else
|
else
|
||||||
echo "PR not created (possibly exists). Response:"; cat /tmp/pr_resp.json || true
|
echo "PR not created (possibly exists). Response:"; cat /tmp/pr_resp.json || true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Retry to resolve PR number by listing open PRs and matching head/base
|
||||||
|
i=0
|
||||||
|
while [ -z "${PR_NUMBER:-}" ] && [ $i -lt 10 ]; do
|
||||||
|
i=$((i+1))
|
||||||
|
echo "[retry $i] Resolving PR number for $HEAD_BRANCH -> $BASE_BRANCH"
|
||||||
|
curl -sS -o /tmp/pr_list.json -H "Authorization: token ${CI_TOKEN}" \
|
||||||
|
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/pulls?state=open" || true
|
||||||
|
# Extract PR number matching head.ref==HEAD_BRANCH and base.ref==BASE_BRANCH
|
||||||
|
PR_NUMBER=$(awk -v hb="$HEAD_BRANCH" -v bb="$BASE_BRANCH" 'BEGIN{RS="},"; pr=""} {
|
||||||
|
if($0 ~ /\"head\":\{[^}]*\"ref\":\"" hb "\"/ && $0 ~ /\"base\":\{[^}]*\"ref\":\"" bb "\"/){
|
||||||
|
if (match($0, /\"number\":([0-9]+)/, m)) { print m[1]; exit }
|
||||||
|
}
|
||||||
|
}' /tmp/pr_list.json)
|
||||||
|
if [ -z "${PR_NUMBER:-}" ]; then sleep 2; fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -n "${PR_NUMBER:-}" ]; then
|
||||||
|
echo "Adding 'automerge' label to PR #$PR_NUMBER"
|
||||||
|
curl -sS -X POST \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-H "Authorization: token ${CI_TOKEN}" \
|
||||||
|
"${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${NAME}/issues/${PR_NUMBER}/labels" \
|
||||||
|
-d '["automerge"]' || true
|
||||||
|
else
|
||||||
|
echo "PR number could not be determined after retries; skipping label add"
|
||||||
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user