-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathissue.js
49 lines (39 loc) · 1.4 KB
/
issue.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
//
// GitHub issue importer
//
const { request } = require('@octokit/request');
// add the flaw to GitHub as an Issue
async function addVeracodeIssue(options, issue) {
const label = require('./label');
const ApiError = require('./util').ApiError;
const githubOwner = options.githubOwner;
const githubRepo = options.githubRepo;
const githubToken = options.githubToken;
console.debug(`Adding Issue for ${issue.title}`);
var authToken = 'token ' + githubToken;
await request('POST /repos/{owner}/{repo}/issues', {
headers: {
authorization: authToken
},
owner: githubOwner,
repo: githubRepo,
data: {
"title": issue.title,
"labels": [label.severityToLabel(issue.severity), issue.label],
"body": issue.body
}
})
.then( result => {
console.log(`Issue successfully created, result: ${result.status}`);
})
.catch( error => {
// 403 possible rate-limit error
if((error.status == 403) && (error.message.indexOf('abuse detection') > 0) ) {
console.warn(`GitHub rate limiter tripped, ${error.message}`);
throw new ApiError('Rate Limiter tripped');
} else {
throw new Error (`Error ${error.status} creating Issue for \"${issue.title}\": ${error.message}`);
}
});
}
module.exports = { addVeracodeIssue };