diff --git a/.gitea/workflows/auto-pr.yml b/.gitea/workflows/auto-pr.yml index cdd89b5..99ac8f7 100644 --- a/.gitea/workflows/auto-pr.yml +++ b/.gitea/workflows/auto-pr.yml @@ -33,6 +33,21 @@ jobs: echo "API status: $HTTP_CODE" if [ "$HTTP_CODE" = "201" ]; then 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 echo "PR not created (possibly exists). Response:"; cat /tmp/pr_resp.json || true + # Find existing open PR for this 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 + PR_NUMBER=$(cat /tmp/pr_list.json | awk -v b="$HEAD_BRANCH" 'BEGIN{RS="},"} {if($0~"\"head\":\{[^}]*\"ref\":\""b"\""){match($0,/\"number\":([0-9]+)/,m); if(m[1]!=""){print m[1]; exit}}}') + fi + 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; skipping label add" fi