Skip to content
Open
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
3 changes: 2 additions & 1 deletion dist/index.js

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

35 changes: 34 additions & 1 deletion src/dependabot/verified_commits.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,38 @@ test('it returns the commit message for a PR authored exclusively by Dependabot
expect(await getMessage(mockGitHubClient, mockGitHubPullContext())).toEqual('Bump lodash from 1.0.0 to 2.0.0')
})

test('it returns the current head commit message when a Dependabot PR has been updated', async () => {
nock('https://api.github.com').get('/repos/dependabot/dependabot/pulls/101/commits')
.reply(200, [
{
sha: 'initial-commit',
author: {
login: 'dependabot[bot]'
},
commit: {
message: 'Bump lodash from 1.0.0 to 2.0.0',
verification: {
verified: true
}
}
},
{
sha: 'updated-commit',
author: {
login: 'dependabot[bot]'
},
commit: {
message: 'Bump lodash from 1.0.0 to 3.0.0',
verification: {
verified: true
}
}
}
])

expect(await getMessage(mockGitHubClient, mockGitHubPullContext('dependabot[bot]', 'updated-commit'))).toEqual('Bump lodash from 1.0.0 to 3.0.0')
})

const query = '{"query":"\\n {\\n repository(owner: \\"dependabot\\", name: \\"dependabot\\") { \\n vulnerabilityAlerts(first: 100) {\\n nodes {\\n vulnerableManifestFilename\\n vulnerableManifestPath\\n vulnerableRequirements\\n state\\n securityVulnerability { \\n package { name } \\n }\\n securityAdvisory { \\n cvss { score }\\n ghsaId \\n }\\n }\\n }\\n }\\n }"}'

const response = {
Expand Down Expand Up @@ -313,11 +345,12 @@ function mockGitHubOtherContext (): Context {
return ctx
}

function mockGitHubPullContext (author = 'dependabot[bot]'): Context {
function mockGitHubPullContext (author = 'dependabot[bot]', headSha?: string): Context {
const ctx = new Context()
ctx.payload = {
pull_request: {
number: 101,
...(headSha ? { head: { sha: headSha } } : {}),
user: {
login: author
}
Expand Down
5 changes: 4 additions & 1 deletion src/dependabot/verified_commits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ export async function getMessage (client: InstanceType<typeof GitHub>, context:
pull_number: pr.number
})

const { commit, author } = commits[0]
const headCommit = pr.head?.sha
? commits.find(({ sha }) => sha === pr.head.sha)
: undefined
const { commit, author } = headCommit ?? commits[0]

if (!skipVerification && author?.login !== DEPENDABOT_LOGIN) {
// TODO: Promote to setFailed
Expand Down
Loading