Skip to content

Commit 3db675d

Browse files
authored
Remove pull_request support (#1109)
1 parent 645422c commit 3db675d

File tree

7 files changed

+15
-40
lines changed

7 files changed

+15
-40
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
name: 'build-test'
22
on:
3-
pull_request:
4-
branches:
5-
- main
63
pull_request_target:
74
branches:
85
- main

README.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,12 @@ The action has the following inputs:
3636
If not provided or set to `false`, the action will fail if a pattern match is found.
3737

3838
> [!IMPORTANT]
39-
> This Action supports pull_request and pull_request_target events only.
40-
41-
> [!CAUTION]
42-
> If you are using the pull_request event, users can manipulate your workflow and add themselves as trusted authors,
43-
> change the pattern, or manipulate the protecting workflow otherwise.
44-
>
45-
> pull_request_target always relies on the action of the target branch.
46-
> Please be aware that the protecting workflow should follow GitHub's security recommendations for pull_request_target.
47-
> You can find more information in the [docs](https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#pull_request_target)
48-
> or [this blog post](https://securitylab.github.com/resources/github-actions-preventing-pwn-requests/).
39+
> This Action supports `pull_request_target` events exclusively. Supporting `pull_request` events would enable users to
40+
> manipulate the workflow by potentially adding themselves as trusted authors, modifying the pattern, or otherwise
41+
> compromising the protective workflow. Please ensure that your protective workflow adheres to GitHub's security
42+
> recommendations for `pull_request_target`. For more detailed information, refer to the
43+
> [official documentation](https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#pull_request_target)
44+
> or this [security blog post](https://securitylab.github.com/resources/github-actions-preventing-pwn-requests/).
4945
5046
## GITHUB_TOKEN permissions
5147

__tests__/main.test.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe('main', () => {
4646
})
4747

4848
isTrustedAuthorSpy = jest.spyOn(authorChecker, 'isTrustedAuthor').mockResolvedValue(false)
49-
context.eventName = 'pull_request'
49+
context.eventName = 'pull_request_target'
5050
context.payload = {
5151
pull_request: {
5252
number: 1
@@ -90,25 +90,14 @@ describe('main', () => {
9090
expect(core.setFailed).not.toHaveBeenCalled()
9191
})
9292

93-
it('Should support pull_request_target event', async () => {
94-
context.eventName = 'pull_request_target'
95-
96-
await run()
97-
98-
expect(getChangedFilesSpy).toHaveBeenCalled()
99-
expect(core.setFailed).not.toHaveBeenCalled()
100-
})
101-
102-
it('Should fail when event name is not pull_request or pull_request_target', async () => {
93+
it('Should fail when event name is not pull_request_target', async () => {
10394
context.eventName = 'push'
10495

10596
await run()
10697

10798
expect(getChangedFilesSpy).not.toHaveBeenCalled()
10899
expect(checkChangedFilesAgainstPatternSpy).not.toHaveBeenCalled()
109-
expect(core.setFailed).toHaveBeenCalledWith(
110-
'Only pull_request and pull_request_targets events are supported. Event was: push'
111-
)
100+
expect(core.setFailed).toHaveBeenCalledWith('Only pull_request_target events are supported. Event was: push')
112101
})
113102

114103
it('Should fail when pull request payload is missing', async () => {

dist/index.js

Lines changed: 2 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"lint-check": "eslint --max-warnings 0",
1313
"package": "ncc build src/index.ts -o dist --source-map --license LICENSE",
1414
"test": "jest",
15+
"test-watch": "jest --watchAll",
1516
"all": "npm run build && npm run format-check && npm run lint-check && npm run package && npm test"
1617
},
1718
"repository": {

src/main.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@ export async function run(): Promise<void> {
1212
core.debug(`Event='${eventName}', Author='${pullRequestAuthor}', Trusted Authors='${trustedAuthors}'`)
1313
if (await isTrustedAuthor(pullRequestAuthor, trustedAuthors)) {
1414
core.info(`${pullRequestAuthor} is a trusted author and is allowed to modify any matching files.`)
15-
} else if (eventName === 'pull_request' || eventName === 'pull_request_target') {
16-
if (eventName === 'pull_request') {
17-
core.warning(
18-
"pull_request support is deprecated because it allows bypassing this action's checks when modifying the corresponding workflow within a pull request. Please switch to pull_request_target."
19-
)
20-
}
15+
} else if (eventName === 'pull_request_target') {
2116
const githubToken: string = core.getInput('githubToken', {required: true})
2217
const gitHubService = new GitHubService(githubToken)
2318
const pullRequestNumber: number = context.payload.pull_request?.number || 0
@@ -44,7 +39,7 @@ export async function run(): Promise<void> {
4439
core.setFailed('Pull request number is missing in github event payload')
4540
}
4641
} else {
47-
core.setFailed(`Only pull_request and pull_request_targets events are supported. Event was: ${eventName}`)
42+
core.setFailed(`Only pull_request_target events are supported. Event was: ${eventName}`)
4843
}
4944
} catch (error: unknown) {
5045
if (error instanceof Error) {

0 commit comments

Comments
 (0)