mirror of
https://git.openapi.site/https://github.com/desirecore/market.git
synced 2026-12-05 09:39:21 +08:00
GitHub now restricts `pull_request_target` on public repositories by default, causing `i18n Auto-Translate` (required `translate` check) and `Auto-request Copilot review` to fail immediately with `startup_failure`. ### Changes - **`.github/workflows/i18n-translate.yml`**: - Switch trigger from `pull_request_target` to `pull_request`. - Explicitly check out `github.base_ref` on `pull_request` and keep the data-only overlay model (`skills/`, `manifest.json`, `categories.json`, symlink removal) so untrusted PR scripts are never executed. - Gate auto-translate, push, PR comment, and failure-label steps to same-repo PRs (`github.event.pull_request.head.repo.full_name == github.repository`) so fork PRs (which receive read-only tokens under `pull_request`) run `translate.py --check` and fail cleanly with local translation instructions instead of crashing with 403. - **`.github/workflows/auto-request-copilot-review.yml`**: - Switch trigger from `pull_request_target` to `pull_request` (keeping `opened`, `reopened`, `ready_for_review`). - Guard the `request` job to non-draft same-repo PRs so fork PRs do not fail with 403. - **`scripts/catalog/test_review_workflow.py`**: - Update assertions to require `pull_request` (and reject `pull_request_target`) plus verify the non-draft & same-repo job guard while preserving all no-checkout/no-code-execution assertions. ### Verification - `uv run --offline --quiet scripts/catalog/test_review_workflow.py` — passed - `pytest scripts/catalog/test_tracked_updates.py -q` — 64 passed - `uv run --offline --quiet scripts/i18n/validate-i18n.py` — passed - `uv run --offline --quiet scripts/catalog/validate_catalog_metadata.py --require-complete` — 0 errors
45 lines
1.9 KiB
YAML
45 lines
1.9 KiB
YAML
name: Auto-request Copilot review
|
|
|
|
on:
|
|
# 仅对主仓非草稿 PR 操作元数据;本流程不检出或执行 PR 代码。
|
|
# GitHub 公仓默认禁用 pull_request_target,改用 pull_request 并仅对同仓 PR 执行写操作。
|
|
pull_request:
|
|
types: [opened, reopened, ready_for_review]
|
|
|
|
permissions:
|
|
pull-requests: write
|
|
|
|
jobs:
|
|
request:
|
|
if: github.event.pull_request.draft == false && github.event.pull_request.head.repo.full_name == github.repository
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 2
|
|
steps:
|
|
- name: Request Copilot reviewer
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
PR_NUMBER: ${{ github.event.pull_request.number }}
|
|
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
|
|
run: |
|
|
set -e
|
|
if gh api "repos/${{ github.repository }}/pulls/$PR_NUMBER" \
|
|
--jq '.requested_reviewers[].login' \
|
|
| grep -qE '^(Copilot|copilot-pull-request-reviewer\[bot\])$'; then
|
|
echo "Copilot already requested as reviewer."
|
|
exit 0
|
|
fi
|
|
# 422 也可能是功能未启用等错误,必须核对真实审核记录,不能直接报成功。
|
|
if ! resp=$(gh api -X POST \
|
|
"repos/${{ github.repository }}/pulls/$PR_NUMBER/requested_reviewers" \
|
|
-f 'reviewers[]=copilot-pull-request-reviewer[bot]' 2>&1); then
|
|
echo "$resp"
|
|
if echo "$resp" | grep -q '"status":"422"'; then
|
|
if gh api "repos/${{ github.repository }}/pulls/$PR_NUMBER/reviews" --paginate \
|
|
| jq --arg head "$PR_HEAD_SHA" -r '.[] | select(.commit_id == $head) | .user.login' | grep -qE '^(Copilot|copilot-pull-request-reviewer\[bot\])$'; then
|
|
echo "Copilot review exists for the current head."
|
|
exit 0
|
|
fi
|
|
fi
|
|
exit 1
|
|
fi
|