Skip to content

Commit 7869db0

Browse files
committed
fix: address Copilot review feedback on translation workflow
- Gate issue_comment re-sync to OWNER/MEMBER/COLLABORATOR only - Verify comment is on a PR (not a plain issue) - Resolve the merged PR's commit SHA for correct checkout on re-sync - Verify the PR is actually merged before proceeding
1 parent 4dc07cb commit 7869db0

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

.github/workflows/sync-translations-zh-cn.yml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,40 @@ jobs:
1717
sync:
1818
if: >
1919
(github.event_name == 'pull_request' && github.event.pull_request.merged == true) ||
20-
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '\translate-resync'))
20+
(
21+
github.event_name == 'issue_comment' &&
22+
github.event.issue.pull_request &&
23+
contains(github.event.comment.body, '\translate-resync') &&
24+
(
25+
github.event.comment.author_association == 'OWNER' ||
26+
github.event.comment.author_association == 'MEMBER' ||
27+
github.event.comment.author_association == 'COLLABORATOR'
28+
)
29+
)
2130
runs-on: ubuntu-latest
2231

2332
steps:
33+
- name: Resolve merged PR commit for re-sync
34+
if: github.event_name == 'issue_comment'
35+
id: resolve_pr
36+
env:
37+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
run: |
39+
pr_json="$(gh api repos/${{ github.repository }}/pulls/${{ github.event.issue.number }})"
40+
merged="$(jq -r '.merged' <<<"$pr_json")"
41+
merge_commit_sha="$(jq -r '.merge_commit_sha // empty' <<<"$pr_json")"
42+
43+
if [ "$merged" != "true" ] || [ -z "$merge_commit_sha" ]; then
44+
echo "The referenced pull request is not merged or has no merge commit SHA."
45+
exit 1
46+
fi
47+
48+
echo "merge_commit_sha=$merge_commit_sha" >> "$GITHUB_OUTPUT"
49+
2450
- uses: actions/checkout@v6
2551
with:
2652
fetch-depth: 2
53+
ref: ${{ steps.resolve_pr.outputs.merge_commit_sha || github.sha }}
2754

2855
- uses: QuantEcon/action-translation@v0.14.1
2956
with:

0 commit comments

Comments
 (0)