-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlabel.js
120 lines (105 loc) · 3.33 KB
/
label.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//
// handle label creation and mgmt
//
const { request } = require('@octokit/request');
const flawLabels = [
{
'name': 'VeracodeFlaw: Very High',
'color': 'd92b85',
'description': 'A Veracode Flaw, Very High severity',
'severity': 5
},
{
'name': 'VeracodeFlaw: High',
'color': 'e61f25',
'description': 'A Veracode Flaw, High severity',
'severity': 4
},
{
'name': 'VeracodeFlaw: Medium',
'color': 'fd7333',
'description': 'A Veracode Flaw, Medium severity',
'severity': 3
},
{
'name': 'VeracodeFlaw: Low',
'color': 'ffcc33',
'description': 'A Veracode Flaw, Low severity',
'severity': 2
},
{
'name': 'VeracodeFlaw: Very Low',
'color': 'c9da2c',
'description': 'A Veracode Flaw, Very Low severity',
'severity': 1
},
{
'name': 'VeracodeFlaw: Informational',
'color': '8dbd3e',
'description': 'A Veracode Flaw, Informational severity',
'severity': 0
}
];
// https://www.color-hex.com
const otherLabels = [
{
'id': 'pipeline',
'name': 'Veracode Pipeline Scan',
'color': '76a6b6',
'description': 'A Veracode Flaw found during a Pipeline Scan'
},
{
'id': 'policy',
'name': 'Veracode Policy Scan',
'color': '666698',
'description': 'A Veracode Flaw found during a Policy or Sandbox Scan'
}
];
// create the labels we need to tag issues with
async function createLabels(options) {
const githubOwner = options.githubOwner;
const githubRepo = options.githubRepo;
const githubToken = options.githubToken;
// create label, accept error code if it already exists
console.log('Creating VeracodeFlaw labels');
var authToken = 'token ' + githubToken;
for(const element of flawLabels.concat(otherLabels) ) {
await request('POST /repos/{owner}/{repo}/labels', {
headers: {
authorization: authToken
},
owner: githubOwner,
repo: githubRepo,
data: {
"name": element.name,
"color": element.color,
"description": element.description
}
})
.then( result => {
console.log(`VeracodeFlaw label \"${element.name}\" successfully created, result: ${result.status}`);
})
.catch( error => {
// 422 (Unprocessable Entity) = label exists
if(error.status == 422) {
console.warn(`VeracodeFlaw label \"${element.name}\" probably exists, (Error: ${error.message})`);
} else {
throw new Error (`Error ${error.status} creating VeracodeFlaw label \"${element.name}\": ${error.message}`);
}
});
}
}
var severityXref = new Map(); // for faster lookups, map severity # to text string
function buildSeverityXref() {
flawLabels.forEach( element => {
severityXref.set(element.severity, element.name)
})
}
function severityToLabel(sevNumber) {
return severityXref.get(sevNumber);
}
// function setupLabels(options) {
// createLabels(options);
// buildSeverityXref();
// }
module.exports = { flawLabels, otherLabels, createLabels, buildSeverityXref, severityToLabel };