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

Allow fetch-metadata to run on a PR even if it has additional commits… #166

Merged
merged 2 commits into from
Feb 28, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 6 additions & 23 deletions src/dependabot/verified_commits.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,6 @@ test('it returns false for an event triggered by someone other than Dependabot',
)
})

test('it returns false if there is more than 1 commit', async () => {
nock('https://api.github.com').get('/repos/dependabot/dependabot/pulls/101/commits')
.reply(200, [
{
commit: {
message: 'Bump lodash from 1.0.0 to 2.0.0'
}
},
{
commit: {
message: 'Add some more things.'
}
}
])

expect(await getMessage(mockGitHubClient, mockGitHubPullContext())).toBe(false)

expect(core.warning).toHaveBeenCalledWith(
expect.stringContaining("It looks like this PR has contains commits that aren't part of a Dependabot update.")
)
})

test('it returns false if the commit was authored by someone other than Dependabot', async () => {
nock('https://api.github.com').get('/repos/dependabot/dependabot/pulls/101/commits')
.reply(200, [
Expand All @@ -71,7 +49,7 @@ test('it returns false if the commit was authored by someone other than Dependab
expect(await getMessage(mockGitHubClient, mockGitHubPullContext())).toBe(false)

expect(core.warning).toHaveBeenCalledWith(
expect.stringContaining("It looks like this PR has contains commits that aren't part of a Dependabot update.")
expect.stringContaining('It looks like this PR was not created by Dependabot, refusing to proceed.')
)
})

Expand Down Expand Up @@ -124,6 +102,11 @@ test('it returns the commit message for a PR authored exclusively by Dependabot
verified: true
}
}
},
{
commit: {
message: 'Add some more things.'
}
}
])

Expand Down
18 changes: 4 additions & 14 deletions src/dependabot/verified_commits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,13 @@ export async function getMessage (client: InstanceType<typeof GitHub>, context:
pull_number: pr.number
})

if (commits.length > 1) {
warnOtherCommits()
return false
}

const { commit, author } = commits[0]

if (author?.login !== DEPENDABOT_LOGIN) {
warnOtherCommits()
// TODO: Promote to setFailed
core.warning(
'It looks like this PR was not created by Dependabot, refusing to proceed.'
)
return false
}

Expand All @@ -55,14 +53,6 @@ export async function getMessage (client: InstanceType<typeof GitHub>, context:
return commit.message
}

function warnOtherCommits (): void {
core.warning(
"It looks like this PR has contains commits that aren't part of a Dependabot update. " +
"Try using '@dependabot rebase' to remove merge commits or '@dependabot recreate' to remove " +
'any non-Dependabot changes.'
)
}

export async function getAlert (name: string, version: string, directory: string, client: InstanceType<typeof GitHub>, context: Context): Promise<dependencyAlert> {
const alerts: any = await client.graphql(`
{
Expand Down