Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check that the author is defined when comparing it with dependab… #258

Merged
merged 2 commits into from Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/index.js
Expand Up @@ -10463,7 +10463,7 @@ module.exports = async function run() {

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

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

Expand Down
2 changes: 1 addition & 1 deletion src/action.js
Expand Up @@ -56,7 +56,7 @@ module.exports = async function run() {

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

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

Expand Down
61 changes: 34 additions & 27 deletions test/action.test.js
Expand Up @@ -134,38 +134,45 @@ tap.test('should skip non-dependabot PR', async () => {
sinon.assert.notCalled(stubs.mergeStub)
})

tap.test('should skip PR with non dependabot commit', async () => {
const PR_NUMBER = Math.random()
const { action, stubs } = buildStubbedAction({
payload: {
pull_request: {
user: {
login: BOT_NAME,
const prCommitsStubs = [
{
author: {
login: 'not dependabot',
},
},
{
author: undefined,
},
]

for (const prCommitsStub of prCommitsStubs) {
tap.test('should skip PR with non dependabot commit', async () => {
const PR_NUMBER = Math.random()
const { action, stubs } = buildStubbedAction({
payload: {
pull_request: {
user: {
login: BOT_NAME,
},
number: PR_NUMBER,
},
number: PR_NUMBER,
},
},
inputs: { PR_NUMBER },
})
inputs: { PR_NUMBER },
})

stubs.prCommitsStub.resolves([
{
author: {
login: 'not dependabot',
},
},
])
stubs.prCommitsStub.resolves([prCommitsStub])

await action()
await action()

sinon.assert.calledOnce(stubs.prCommitsStub)
sinon.assert.calledWithExactly(
stubs.logStub.logWarning,
'PR contains non dependabot commits, skipping.'
)
sinon.assert.notCalled(stubs.approveStub)
sinon.assert.notCalled(stubs.mergeStub)
})
sinon.assert.calledOnce(stubs.prCommitsStub)
sinon.assert.calledWithExactly(
stubs.logStub.logWarning,
'PR contains non dependabot commits, skipping.'
)
sinon.assert.notCalled(stubs.approveStub)
sinon.assert.notCalled(stubs.mergeStub)
})
}

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