-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathget-code-scanning-alerts.js
53 lines (46 loc) · 1.54 KB
/
get-code-scanning-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
#!/usr/bin/env node
require('dotenv').config()
const pReduce = require('./lib/p-reduce');
const delay = require('delay');
const {Octokit} = require('@octokit/rest')
const octokit = new Octokit({
auth: process.env.GH_AUTH_TOKEN,
previews: ['dorian-preview']
})
var buffer = ""
const [, , ...args] = process.argv
const owner = args[0]
console.log("org,repo,tool,rule_id,severity,open,created_at,closed_by,closed_at,url,closed_reason")
octokit
.paginate(octokit.repos.listForOrg, {
org: owner,
})
.then(repositories =>
pReduce(repositories, (repository) => {
if (repository.archived) {
return Promise.resolve();
}
const repo = repository.name
return octokit
.paginate("GET /repos/:owner/:repo/code-scanning/alerts?per_page=100", {
owner: owner,
repo: repo
})
.then(alerts => {
if (alerts.length > 0) {
pReduce(alerts, (alert) => {
console.log(`${owner},${repo},${alert.tool.name},${alert.rule.id},${alert.rule.severity},${alert.state},${alert.created_at},${alert.dismissed_by},${alert.dismissed_at},${alert.html_url},${alert.dismissed_reason}`)
})
}
delay(300);
})
.catch(error => {
// console.error(`Failed for ${owner}/${repo}\n${error.message}\n${error.documentation_url}`)
})
})
)
.catch(error => {
console.error(`Getting repositories for organization ${owner} failed.
${error.message} (${error.status})
${error.documentation_url}`)
})