ci: PAT via extraHeader + --data@file

This commit is contained in:
gitea-bot
2026-07-30 23:01:38 +08:00
parent 7bbaa37802
commit 15af529bc0
+6 -4
View File
@@ -18,7 +18,7 @@ jobs:
IS_SANDBOX: "1" # CI 容器以 root 运行,需此项才能用 --dangerously-skip-permissions
steps:
- name: 检出代码
# 手动克隆,避免从 github.com 下载 actions/checkout(内网不可达
# 用 http.extraHeader 传凭据,避免 PAT 出现在 clone URL(防日志/报错泄漏
env:
REVIEW_PAT: ${{ secrets.REVIEW_PAT }}
run: |
@@ -27,7 +27,8 @@ jobs:
echo "SKIP_REVIEW=1" >> "$GITHUB_ENV"
exit 0
fi
git clone "http://oauth2:${REVIEW_PAT}@gitea:3000/${{ gitea.repository }}.git" .
git config --global http.extraHeader "Authorization: Basic $(printf 'oauth2:%s' "$REVIEW_PAT" | base64 -w0)"
git clone "http://gitea:3000/${{ gitea.repository }}.git" .
git checkout "${{ gitea.event.pull_request.head.ref }}"
- name: 生成 PR diff
@@ -66,11 +67,12 @@ jobs:
PR: ${{ gitea.event.pull_request.number }}
run: |
if [ -s review.md ]; then
BODY=$(node -e 'let d="";process.stdin.on("data",c=>d+=c).on("end",()=>process.stdout.write(JSON.stringify({body:d})))' < review.md)
# 写到临时文件再 --data @,避免超长 review 触发 ARG_MAX
node -e 'let d="";process.stdin.on("data",c=>d+=c).on("end",()=>process.stdout.write(JSON.stringify({body:d})))' < review.md > /tmp/body.json
curl -fsS -X POST "$API/repos/$REPO/issues/$PR/comments" \
-H "Authorization: token $REVIEW_PAT" \
-H "Content-Type: application/json" \
-d "$BODY"
--data @/tmp/body.json
else
echo "review.md 为空,跳过评论"
fi