Skip to content

Commit 6c2bf2f

Browse files
authored
feat: add option to skip internal verifications (#336)
Add a `skip-verification` (boolean) option: - If `true`, the action will not validate the user or the commit verification status - Defaults to `false` Allows for scenarios where users want to add or amend commits on the Dependabot PR, and those commits will not come from the :dependabot: user. There's a fair bit of discussion on this use case and also why this isn't the default behavior, see: * #336 * #332
1 parent 684ca1c commit 6c2bf2f

File tree

6 files changed

+50
-18
lines changed

6 files changed

+50
-18
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ Supported inputs are:
4848
- `skip-commit-verification` (boolean)
4949
- If `true`, then the action will not expect the commits to have a verification signature. **It is required to set this to 'true' in GitHub Enterprise Server**
5050
- Defaults to `false`
51+
- `skip-verification` (boolean)
52+
- If `true`, the action will not validate the user or the commit verification status
53+
- Defaults to `false`
5154

5255
Subsequent actions will have access to the following outputs:
5356

action.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ inputs:
1515
default: ${{ github.token }}
1616
skip-commit-verification:
1717
type: boolean
18-
description: 'If true, the action will not expect Dependabot commits to be verified. This should be set as `true` in GHES environments.'
18+
description: 'If true, the action will not expect Dependabot commits to be verified. This should be set as `true` in GHES environments'
19+
default: false
20+
skip-verification:
21+
type: boolean
22+
description: 'If true, the action will not validate the user or the commit verification status'
1923
default: false
2024
outputs:
2125
dependency-names:

dist/index.js

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

src/dependabot/verified_commits.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,25 @@ test('it returns the message if the commit is has no verification payload but ve
8787
expect(await getMessage(mockGitHubClient, mockGitHubPullContext(), true)).toEqual('Bump lodash from 1.0.0 to 2.0.0')
8888
})
8989

90+
test('it returns the message when skip-verification is enabled', async () => {
91+
jest.spyOn(core, 'getInput').mockReturnValue('true')
92+
93+
nock('https://api.github.com').get('/repos/dependabot/dependabot/pulls/101/commits')
94+
.reply(200, [
95+
{
96+
author: {
97+
login: 'myUser'
98+
},
99+
commit: {
100+
message: 'Bump lodash from 1.0.0 to 2.0.0',
101+
verification: false
102+
}
103+
}
104+
])
105+
106+
expect(await getMessage(mockGitHubClient, mockGitHubPullContext(), false, true)).toEqual('Bump lodash from 1.0.0 to 2.0.0')
107+
})
108+
90109
test('it returns false if the commit is not verified', async () => {
91110
nock('https://api.github.com').get('/repos/dependabot/dependabot/pulls/101/commits')
92111
.reply(200, [

src/dependabot/verified_commits.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ import https from 'https'
66

77
const DEPENDABOT_LOGIN = 'dependabot[bot]'
88

9-
export async function getMessage (client: InstanceType<typeof GitHub>, context: Context, skipCommitVerification = false): Promise<string | false> {
10-
core.debug('Verifying the job is for an authentic Dependabot Pull Request')
9+
export async function getMessage (client: InstanceType<typeof GitHub>, context: Context, skipCommitVerification = false, skipVerification = false): Promise<string | false> {
10+
if (skipVerification) {
11+
core.debug('Skipping pull request verification')
12+
} else {
13+
core.debug('Verifying the job is for an authentic Dependabot Pull Request')
14+
}
1115

1216
const { pull_request: pr } = context.payload
1317

@@ -19,14 +23,12 @@ export async function getMessage (client: InstanceType<typeof GitHub>, context:
1923
return false
2024
}
2125

22-
// Don't bother hitting the API if the PR author isn't Dependabot
23-
if (pr.user.login !== DEPENDABOT_LOGIN) {
26+
// Don't bother hitting the API if the PR author isn't Dependabot unless verification is disabled
27+
if (!skipVerification && pr.user.login !== DEPENDABOT_LOGIN) {
2428
core.debug(`PR author '${pr.user.login}' is not Dependabot.`)
2529
return false
2630
}
2731

28-
core.debug('Verifying the Pull Request contents are from Dependabot')
29-
3032
const { data: commits } = await client.rest.pulls.listCommits({
3133
owner: context.repo.owner,
3234
repo: context.repo.repo,
@@ -35,15 +37,15 @@ export async function getMessage (client: InstanceType<typeof GitHub>, context:
3537

3638
const { commit, author } = commits[0]
3739

38-
if (author?.login !== DEPENDABOT_LOGIN) {
40+
if (!skipVerification && author?.login !== DEPENDABOT_LOGIN) {
3941
// TODO: Promote to setFailed
4042
core.warning(
4143
'It looks like this PR was not created by Dependabot, refusing to proceed.'
4244
)
4345
return false
4446
}
4547

46-
if (!skipCommitVerification && !commit.verification?.verified) {
48+
if (!skipVerification && !skipCommitVerification && !commit.verification?.verified) {
4749
// TODO: Promote to setFailed
4850
core.warning(
4951
"Dependabot's commit signature is not verified, refusing to proceed."

src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export async function run (): Promise<void> {
2222
const githubClient = github.getOctokit(token)
2323

2424
// Validate the job
25-
const commitMessage = await verifiedCommits.getMessage(githubClient, github.context, core.getBooleanInput('skip-commit-verification'))
25+
const commitMessage = await verifiedCommits.getMessage(githubClient, github.context, core.getBooleanInput('skip-commit-verification'), core.getBooleanInput('skip-verification'))
2626
const branchNames = util.getBranchNames(github.context)
2727
let alertLookup: updateMetadata.alertLookup | undefined
2828
if (core.getInput('alert-lookup')) {

0 commit comments

Comments
 (0)