Skip to content

Commit 88cd6e7

Browse files
authored
fix: GHES support (#367)
* Fix GHES support * Remove unnecessary await * fixup! Fix GHES support * Test all boolean inputs
1 parent 3ce2ccd commit 88cd6e7

6 files changed

Lines changed: 80 additions & 25 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ _Optional_ A pull request number, only required if triggered from a workflow_dis
5656

5757
### `skip-commit-verification`
5858

59-
_Optional_ If true, then the [dependabot/fetch-metadata](https://github.com/dependabot/fetch-metadata) action will not expect the commits to have a verification signature. It is required to set this to true in GitHub Enterprise Server.
59+
_Optional_ 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.
6060

6161
## Usage
6262

dist/index.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2782,6 +2782,7 @@ module.exports = async function run({
27822782
USE_GITHUB_AUTO_MERGE,
27832783
TARGET,
27842784
PR_NUMBER,
2785+
SKIP_COMMIT_VERIFICATION,
27852786
} = getInputs(inputs)
27862787

27872788
try {
@@ -2808,12 +2809,14 @@ module.exports = async function run({
28082809
return logWarning('PR contains non dependabot commits, skipping.')
28092810
}
28102811

2811-
try {
2812-
await verifyCommits(commits)
2813-
} catch {
2814-
return logWarning(
2815-
'PR contains invalid dependabot commit signatures, skipping.'
2816-
)
2812+
if (!SKIP_COMMIT_VERIFICATION) {
2813+
try {
2814+
verifyCommits(commits)
2815+
} catch {
2816+
return logWarning(
2817+
'PR contains invalid dependabot commit signatures, skipping.'
2818+
)
2819+
}
28172820
}
28182821

28192822
if (
@@ -3108,6 +3111,7 @@ exports.getInputs = inputs => {
31083111
USE_GITHUB_AUTO_MERGE: /true/i.test(inputs['use-github-auto-merge']),
31093112
TARGET: mapUpdateType(inputs['target']),
31103113
PR_NUMBER: inputs['pr-number'],
3114+
SKIP_COMMIT_VERIFICATION: /true/i.test(inputs['skip-commit-verification']),
31113115
}
31123116
}
31133117

src/action.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ module.exports = async function run({
3131
USE_GITHUB_AUTO_MERGE,
3232
TARGET,
3333
PR_NUMBER,
34+
SKIP_COMMIT_VERIFICATION,
3435
} = getInputs(inputs)
3536

3637
try {
@@ -57,12 +58,14 @@ module.exports = async function run({
5758
return logWarning('PR contains non dependabot commits, skipping.')
5859
}
5960

60-
try {
61-
await verifyCommits(commits)
62-
} catch {
63-
return logWarning(
64-
'PR contains invalid dependabot commit signatures, skipping.'
65-
)
61+
if (!SKIP_COMMIT_VERIFICATION) {
62+
try {
63+
verifyCommits(commits)
64+
} catch {
65+
return logWarning(
66+
'PR contains invalid dependabot commit signatures, skipping.'
67+
)
68+
}
6669
}
6770

6871
if (

src/util.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,6 @@ exports.getInputs = inputs => {
4646
USE_GITHUB_AUTO_MERGE: /true/i.test(inputs['use-github-auto-merge']),
4747
TARGET: mapUpdateType(inputs['target']),
4848
PR_NUMBER: inputs['pr-number'],
49+
SKIP_COMMIT_VERIFICATION: /true/i.test(inputs['skip-commit-verification']),
4950
}
5051
}

test/action.test.js

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ function buildStubbedAction({ payload, inputs, dependabotMetadata }) {
7979
getPullRequestCommits: prCommitsStub.resolves([]),
8080
})
8181

82-
const verifyCommitsStub = sinon
83-
.stub(verifyCommits, 'verifyCommits')
84-
.returns(Promise.resolve())
82+
const verifyCommitsStub = sinon.stub(verifyCommits, 'verifyCommits')
8583

8684
const action = proxyquire('../src/action', {
8785
'@actions/core': coreStub,
@@ -231,7 +229,7 @@ tap.test(
231229
},
232230
])
233231

234-
stubs.verifyCommitsStub.rejects()
232+
stubs.verifyCommitsStub.throws()
235233

236234
await action()
237235

@@ -244,6 +242,44 @@ tap.test(
244242
}
245243
)
246244

245+
tap.test(
246+
'should review and merge even if commit signatures cannot be verified with skip-commit-verification',
247+
async () => {
248+
const PR_NUMBER = Math.random()
249+
const { action, stubs } = buildStubbedAction({
250+
payload: {
251+
pull_request: {
252+
user: {
253+
login: BOT_NAME,
254+
},
255+
number: PR_NUMBER,
256+
},
257+
},
258+
inputs: {
259+
'skip-commit-verification': true,
260+
},
261+
})
262+
263+
stubs.prCommitsStub.resolves([
264+
{
265+
author: {
266+
login: 'dependabot[bot]',
267+
},
268+
},
269+
])
270+
271+
await action()
272+
273+
sinon.assert.calledWithExactly(
274+
stubs.logStub.logInfo,
275+
'Dependabot merge completed'
276+
)
277+
sinon.assert.notCalled(stubs.coreStub.setFailed)
278+
sinon.assert.calledOnce(stubs.approveStub)
279+
sinon.assert.calledOnce(stubs.mergeStub)
280+
}
281+
)
282+
247283
tap.test('should ignore excluded package', async () => {
248284
const PR_NUMBER = Math.random()
249285
const { action, stubs } = buildStubbedAction({

test/util.test.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ tap.test('parseCommaOrSemicolonSeparatedValue', async t => {
3232
})
3333
})
3434

35+
const BOOLEAN_INPUTS = [
36+
{ input: 'approve-only', key: 'APPROVE_ONLY' },
37+
{ input: 'use-github-auto-merge', key: 'USE_GITHUB_AUTO_MERGE' },
38+
{
39+
input: 'skip-commit-verification',
40+
key: 'SKIP_COMMIT_VERIFICATION',
41+
},
42+
]
43+
3544
tap.test('getInputs', async t => {
3645
t.test('should fail if no inputs object is provided', async t => {
3746
t.throws(() => getInputs())
@@ -60,14 +69,16 @@ tap.test('getInputs', async t => {
6069
'test-merge-comment'
6170
)
6271
})
63-
t.test('APPROVE_ONLY', async t => {
64-
t.equal(getInputs({}).APPROVE_ONLY, false)
65-
t.equal(getInputs({ 'approve-only': 'false' }).APPROVE_ONLY, false)
66-
t.equal(getInputs({ 'approve-only': 'False' }).APPROVE_ONLY, false)
67-
t.equal(getInputs({ 'approve-only': 'FALSE' }).APPROVE_ONLY, false)
68-
t.equal(getInputs({ 'approve-only': 'true' }).APPROVE_ONLY, true)
69-
t.equal(getInputs({ 'approve-only': 'True' }).APPROVE_ONLY, true)
70-
t.equal(getInputs({ 'approve-only': 'TRUE' }).APPROVE_ONLY, true)
72+
t.test('BOOLEAN INPUTS', async t => {
73+
BOOLEAN_INPUTS.forEach(({ input, key }) => {
74+
t.equal(getInputs({})[key], false)
75+
t.equal(getInputs({ [input]: 'false' })[key], false)
76+
t.equal(getInputs({ [input]: 'False' })[key], false)
77+
t.equal(getInputs({ [input]: 'FALSE' })[key], false)
78+
t.equal(getInputs({ [input]: 'true' })[key], true)
79+
t.equal(getInputs({ [input]: 'True' })[key], true)
80+
t.equal(getInputs({ [input]: 'TRUE' })[key], true)
81+
})
7182
})
7283
t.test('TARGET', async t => {
7384
t.equal(

0 commit comments

Comments
 (0)