Skip to content

Commit 64a2b98

Browse files
fix: check that the author is defined when comparing it with dependab… (#258)
* fix: check that the author is defined when comparing it with dependabot author * fix: added unkown commit author test case
1 parent 5ff5a73 commit 64a2b98

File tree

3 files changed

+36
-29
lines changed

3 files changed

+36
-29
lines changed

dist/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10463,7 +10463,7 @@ module.exports = async function run() {
1046310463

1046410464
const commits = await client.getPullRequestCommits(pr.number)
1046510465

10466-
if (!commits.every(commit => commit.author.login === dependabotAuthor)) {
10466+
if (!commits.every(commit => commit.author?.login === dependabotAuthor)) {
1046710467
return logWarning('PR contains non dependabot commits, skipping.')
1046810468
}
1046910469

src/action.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ module.exports = async function run() {
5656

5757
const commits = await client.getPullRequestCommits(pr.number)
5858

59-
if (!commits.every(commit => commit.author.login === dependabotAuthor)) {
59+
if (!commits.every(commit => commit.author?.login === dependabotAuthor)) {
6060
return logWarning('PR contains non dependabot commits, skipping.')
6161
}
6262

test/action.test.js

+34-27
Original file line numberDiff line numberDiff line change
@@ -134,38 +134,45 @@ tap.test('should skip non-dependabot PR', async () => {
134134
sinon.assert.notCalled(stubs.mergeStub)
135135
})
136136

137-
tap.test('should skip PR with non dependabot commit', async () => {
138-
const PR_NUMBER = Math.random()
139-
const { action, stubs } = buildStubbedAction({
140-
payload: {
141-
pull_request: {
142-
user: {
143-
login: BOT_NAME,
137+
const prCommitsStubs = [
138+
{
139+
author: {
140+
login: 'not dependabot',
141+
},
142+
},
143+
{
144+
author: undefined,
145+
},
146+
]
147+
148+
for (const prCommitsStub of prCommitsStubs) {
149+
tap.test('should skip PR with non dependabot commit', async () => {
150+
const PR_NUMBER = Math.random()
151+
const { action, stubs } = buildStubbedAction({
152+
payload: {
153+
pull_request: {
154+
user: {
155+
login: BOT_NAME,
156+
},
157+
number: PR_NUMBER,
144158
},
145-
number: PR_NUMBER,
146159
},
147-
},
148-
inputs: { PR_NUMBER },
149-
})
160+
inputs: { PR_NUMBER },
161+
})
150162

151-
stubs.prCommitsStub.resolves([
152-
{
153-
author: {
154-
login: 'not dependabot',
155-
},
156-
},
157-
])
163+
stubs.prCommitsStub.resolves([prCommitsStub])
158164

159-
await action()
165+
await action()
160166

161-
sinon.assert.calledOnce(stubs.prCommitsStub)
162-
sinon.assert.calledWithExactly(
163-
stubs.logStub.logWarning,
164-
'PR contains non dependabot commits, skipping.'
165-
)
166-
sinon.assert.notCalled(stubs.approveStub)
167-
sinon.assert.notCalled(stubs.mergeStub)
168-
})
167+
sinon.assert.calledOnce(stubs.prCommitsStub)
168+
sinon.assert.calledWithExactly(
169+
stubs.logStub.logWarning,
170+
'PR contains non dependabot commits, skipping.'
171+
)
172+
sinon.assert.notCalled(stubs.approveStub)
173+
sinon.assert.notCalled(stubs.mergeStub)
174+
})
175+
}
169176

170177
tap.test(
171178
'should skip PR if dependabot commit signatures cannot be verified',

0 commit comments

Comments
 (0)