-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathget-dependabot-alerts.js
81 lines (70 loc) · 2.09 KB
/
get-dependabot-alerts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env node
require('dotenv').config()
const [, , org, repo] = process.argv
let { graphql } = require('@octokit/graphql')
graphql = graphql.defaults({
headers: {
authorization: `token ${process.env.GITHUB_TOKEN}`
}
})
DumpDependabotAlerts()
async function DumpDependabotAlerts() {
let pagination = null
const query =
`query ($org: String! $repo: String! $cursor: String){
repository(owner: $org name: $repo) {
name
vulnerabilityAlerts(first: 100 after: $cursor) {
pageInfo {
hasNextPage
endCursor
}
totalCount
nodes {
id
securityAdvisory {
...advFields
}
securityVulnerability {
package {
...pkgFields
}
vulnerableVersionRange
}
vulnerableManifestFilename
vulnerableManifestPath
vulnerableRequirements
}
}
}
}
fragment advFields on SecurityAdvisory {
ghsaId
permalink
severity
description
summary
}
fragment pkgFields on SecurityAdvisoryPackage {
name
ecosystem
}`
try {
console.log("org,repo,package,ecosystem,summary,severity,permalink")
let hasNextPage = false
do {
const getVulnResult = await graphql({ query, org: org, repo: repo, cursor: pagination })
hasNextPage = getVulnResult.repository.vulnerabilityAlerts.pageInfo.hasNextPage
const vulns = getVulnResult.repository.vulnerabilityAlerts.nodes
for (const vuln of vulns) {
console.log(`${org},${repo},${vuln.securityVulnerability.package.name},${vuln.securityVulnerability.package.ecosystem},"${vuln.securityAdvisory.summary}",${vuln.securityAdvisory.severity},${vuln.securityAdvisory.permalink}`)
}
if (hasNextPage) {
pagination = getVulnResult.repository.vulnerabilityAlerts.pageInfo.endCursor
}
} while (hasNextPage)
} catch (error) {
console.log('Request failed:', error.request)
console.log(error.message)
}
}