From 513ae72e853d7605a440440f31f4a2f4f658d14a Mon Sep 17 00:00:00 2001 From: Archicratia Date: Mon, 16 Mar 2026 12:52:47 +0100 Subject: [PATCH] fix(actions): verify proposer issue closure after PR creation --- .gitea/workflows/proposer-apply-pr.yml | 91 ++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/.gitea/workflows/proposer-apply-pr.yml b/.gitea/workflows/proposer-apply-pr.yml index 125dbf8..08f6928 100644 --- a/.gitea/workflows/proposer-apply-pr.yml +++ b/.gitea/workflows/proposer-apply-pr.yml @@ -597,6 +597,97 @@ jobs: ); ' + echo "Creating proposer PR..." + PR_JSON="$(curl -fsS -X POST \ + -H "Authorization: token $FORGE_TOKEN" \ + -H "Content-Type: application/json" \ + "$API_BASE/api/v1/repos/$OWNER/$REPO/pulls" \ + --data-binary @/tmp/proposer.pr.json)" + + PR_URL="$(node --input-type=module -e 'const pr = JSON.parse(process.argv[1] || "{}"); console.log(pr.html_url || pr.url || "");' "$PR_JSON")" + + test -n "$PR_URL" || { + echo "PR URL missing. Raw: $PR_JSON" + exit 1 + } + + echo "PR created: $PR_URL" + + for ISSUE in $TARGET_ISSUES; do + export ISSUE PR_URL + + node --input-type=module -e ' + import fs from "node:fs"; + + const issue = process.env.ISSUE || ""; + const url = process.env.PR_URL || ""; + const msg = + `PR proposer créée pour le ticket #${issue} : ${url}\n\n` + + `Le ticket est clôturé automatiquement ; la discussion peut se poursuivre dans la PR.`; + + fs.writeFileSync( + "/tmp/proposer.issue.close.comment.json", + JSON.stringify({ body: msg }) + ); + ' + + echo "Commenting issue #$ISSUE ..." + COMMENT_HTTP="$(curl -sS -o /tmp/proposer.comment.out.json -w '%{http_code}' -X POST \ + -H "Authorization: token $FORGE_TOKEN" \ + -H "Content-Type: application/json" \ + "$API_BASE/api/v1/repos/$OWNER/$REPO/issues/$ISSUE/comments" \ + --data-binary @/tmp/proposer.issue.close.comment.json || true)" + echo "Issue #$ISSUE comment HTTP=$COMMENT_HTTP" + + if [[ ! "$COMMENT_HTTP" =~ ^2 ]]; then + echo "Failed to comment issue #$ISSUE" + cat /tmp/proposer.comment.out.json || true + exit 1 + fi + + echo "Closing issue #$ISSUE ..." + CLOSE_HTTP="$(curl -sS -o /tmp/proposer.close.out.json -w '%{http_code}' -X PATCH \ + -H "Authorization: token $FORGE_TOKEN" \ + -H "Content-Type: application/json" \ + "$API_BASE/api/v1/repos/$OWNER/$REPO/issues/$ISSUE" \ + --data-binary '{"state":"closed"}' || true)" + echo "Issue #$ISSUE close HTTP=$CLOSE_HTTP" + + if [[ ! "$CLOSE_HTTP" =~ ^2 ]]; then + echo "Failed to close issue #$ISSUE" + cat /tmp/proposer.close.out.json || true + exit 1 + fi + + echo "Verifying issue #$ISSUE state ..." + VERIFY_HTTP="$(curl -sS -o /tmp/proposer.verify.out.json -w '%{http_code}' \ + -H "Authorization: token $FORGE_TOKEN" \ + -H "Accept: application/json" \ + "$API_BASE/api/v1/repos/$OWNER/$REPO/issues/$ISSUE" || true)" + echo "Issue #$ISSUE verify HTTP=$VERIFY_HTTP" + + if [[ ! "$VERIFY_HTTP" =~ ^2 ]]; then + echo "Failed to re-read issue #$ISSUE after close" + cat /tmp/proposer.verify.out.json || true + exit 1 + fi + + ISSUE_STATE="$(node --input-type=module -e ' + import fs from "node:fs"; + const j = JSON.parse(fs.readFileSync("/tmp/proposer.verify.out.json", "utf8")); + console.log(String(j.state || "")); + ')" + + echo "Issue #$ISSUE state=$ISSUE_STATE" + [[ "$ISSUE_STATE" == "closed" ]] || { + echo "Issue #$ISSUE is not closed after PATCH" + cat /tmp/proposer.verify.out.json || true + exit 1 + } + done + + echo "PR: $PR_URL" + PR_JSON="$(curl -fsS -X POST \ -H "Authorization: token $FORGE_TOKEN" \ -H "Content-Type: application/json" \ -- 2.49.1