Skip to content

Commit cfb7274

Browse files
authored
Merge pull request #225 from dependabot/brrygrdn/skip-commit-verification
Add 'skip-commit-verification' as an input for GitHub Enterprise Server users
2 parents a7c13a8 + 6c87543 commit cfb7274

File tree

7 files changed

+31
-6
lines changed

7 files changed

+31
-6
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ Supported inputs are:
4141
- `compat-lookup` (boolean)
4242
- If `true`, then populate the `compatibility-score` output.
4343
- Defaults to `false`
44+
- `skip-commit-verification` (boolean)
45+
- 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**
46+
- Defaults to `false`
4447

4548
Subsequent actions will have access to the following outputs:
4649

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ inputs:
1313
github-token:
1414
description: 'The GITHUB_TOKEN secret'
1515
default: ${{ github.token }}
16+
skip-commit-verification:
17+
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.'
19+
default: false
1620
outputs:
1721
dependency-names:
1822
description: 'A comma-separated list of all package names updated.'

dist/index.js

Lines changed: 3 additions & 3 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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,23 @@ test('it returns false if the commit is has no verification payload', async () =
7070
expect(await getMessage(mockGitHubClient, mockGitHubPullContext())).toBe(false)
7171
})
7272

73+
test('it returns the message if the commit is has no verification payload but verification is skipped', async () => {
74+
nock('https://api.github.com').get('/repos/dependabot/dependabot/pulls/101/commits')
75+
.reply(200, [
76+
{
77+
author: {
78+
login: 'dependabot[bot]'
79+
},
80+
commit: {
81+
message: 'Bump lodash from 1.0.0 to 2.0.0',
82+
verification: null
83+
}
84+
}
85+
])
86+
87+
expect(await getMessage(mockGitHubClient, mockGitHubPullContext(), true)).toEqual('Bump lodash from 1.0.0 to 2.0.0')
88+
})
89+
7390
test('it returns false if the commit is not verified', async () => {
7491
nock('https://api.github.com').get('/repos/dependabot/dependabot/pulls/101/commits')
7592
.reply(200, [

src/dependabot/verified_commits.ts

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

77
const DEPENDABOT_LOGIN = 'dependabot[bot]'
88

9-
export async function getMessage (client: InstanceType<typeof GitHub>, context: Context): Promise<string | false> {
9+
export async function getMessage (client: InstanceType<typeof GitHub>, context: Context, skipCommitVerification = false): Promise<string | false> {
1010
core.debug('Verifying the job is for an authentic Dependabot Pull Request')
1111

1212
const { pull_request: pr } = context.payload
@@ -43,7 +43,7 @@ export async function getMessage (client: InstanceType<typeof GitHub>, context:
4343
return false
4444
}
4545

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

src/main.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ beforeEach(() => {
1010
jest.spyOn(core, 'info').mockImplementation(jest.fn())
1111
jest.spyOn(core, 'setFailed').mockImplementation(jest.fn())
1212
jest.spyOn(core, 'startGroup').mockImplementation(jest.fn())
13+
jest.spyOn(core, 'getBooleanInput').mockReturnValue(false)
1314
})
1415

1516
test('it early exits with an error if github-token is not set', async () => {

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)
25+
const commitMessage = await verifiedCommits.getMessage(githubClient, github.context, core.getBooleanInput('skip-commit-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)