Skip to content

Commit 1add093

Browse files
Copilotshenxianpeng
andcommitted
Fix fork PR comment issue with pull_request_target workflow
Co-authored-by: shenxianpeng <3353385+shenxianpeng@users.noreply.github.com>
1 parent 9e00834 commit 1add093

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

.github/workflows/commit-check.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Commit Check
22

33
on:
4-
pull_request:
4+
pull_request_target:
55
branches: 'main'
66
workflow_dispatch:
77

@@ -11,11 +11,13 @@ jobs:
1111
permissions: # use permissions because of use pr-comments
1212
contents: read
1313
pull-requests: write
14+
issues: write
1415
steps:
1516
- uses: actions/checkout@v5
1617
with:
17-
ref: ${{ github.event.pull_request.head.sha }} # checkout PR HEAD commit
18+
ref: ${{ format('refs/pull/{0}/head', github.event.pull_request.number) }} # checkout PR HEAD commit
1819
fetch-depth: 0 # fetch all history for all branches and tags
20+
persist-credentials: false
1921
- uses: ./ # self test
2022
env:
2123
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # use GITHUB_TOKEN because of use pr-comments
@@ -28,4 +30,4 @@ jobs:
2830
merge-base: true
2931
imperative: true
3032
job-summary: true
31-
pr-comments: ${{ github.event_name == 'pull_request' }}
33+
pr-comments: ${{ github.event_name == 'pull_request' || github.event_name == 'pull_request_target' }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
venv/
22
.venv/
3+
__pycache__/

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ name: Commit Check
2727

2828
on:
2929
push:
30-
pull_request:
30+
pull_request_target:
3131
branches: 'main'
3232

3333
jobs:
@@ -36,11 +36,13 @@ jobs:
3636
permissions: # use permissions because use of pr-comments
3737
contents: read
3838
pull-requests: write
39+
issues: write
3940
steps:
4041
- uses: actions/checkout@v4
4142
with:
42-
ref: ${{ github.event.pull_request.head.sha }} # checkout PR HEAD commit
43+
ref: ${{ format('refs/pull/{0}/head', github.event.pull_request.number) }} # checkout PR HEAD commit
4344
fetch-depth: 0 # required for merge-base check
45+
persist-credentials: false
4446
- uses: commit-check/commit-check-action@v1
4547
env:
4648
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # use GITHUB_TOKEN because use of pr-comments
@@ -53,7 +55,7 @@ jobs:
5355
merge-base: false
5456
imperative: false
5557
job-summary: true
56-
pr-comments: ${{ github.event_name == 'pull_request' }}
58+
pr-comments: ${{ github.event_name == 'pull_request' || github.event_name == 'pull_request_target' }}
5759
```
5860
5961
## Used By
@@ -136,9 +138,7 @@ jobs:
136138
- Default: `false`
137139

138140
> [!IMPORTANT]
139-
> `pr-comments` is an experimental feature. By default, it's disabled. To use it, you need to set `GITHUB_TOKEN` in the GitHub Action.
140-
>
141-
> This feature currently doesn’t work with forked repositories. For more details, refer to issue [#77](https://github.com/commit-check/commit-check-action/issues/77).
141+
> `pr-comments` is an experimental feature. By default, it's disabled. To use it, you need to set `GITHUB_TOKEN` in the GitHub Action and ensure your workflow has `issues: write` permission.
142142

143143
Note: the default rule of above inputs is following [this configuration](https://github.com/commit-check/commit-check/blob/main/.commit-check.yml). If you want to customize, just add your `.commit-check.yml` config file under your repository root directory.
144144

0 commit comments

Comments
 (0)