-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
60 lines (49 loc) · 1.55 KB
/
index.ts
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
#!/usr/bin/env node
import yargs from 'yargs/yargs';
import axios from 'axios';
import { sonarIssue, convert } from './src/converter';
import fs from 'fs';
const parser = yargs(process.argv.slice(2)).options({
host: { type: 'string', default: 'https://sonarqube.com' },
token: { type: 'string', default: '' },
project: { type: 'string', default: '' }
});
(async() => {
const argv = await parser.argv;
if (argv.token === '' || argv.project === '') {
console.log('Please provide a token and project name');
process.exit(1);
}
let authToken = Buffer.from(argv.token + ':').toString('base64');
console.log(authToken);
let config = {
method: 'get',
url: `${argv.host}/api/server/version`,
headers: {
'Authorization': `Basic ${authToken}`
}
}
let response = await axios(config);
const version = response.data;
console.log(`Version: ${response.data}`);
config = {
method: 'get',
url: `${argv.host}/api/issues/search?componentKeys=${argv.project}`,
headers: {
'Authorization': `Basic ${authToken}`,
}
};
try {
response = await axios(config);
// console.log(response.data);
let sonarIssues: sonarIssue[] = await response.data.issues;
fs.writeFile('gl-sast-report.json', JSON.stringify(convert(sonarIssues, version)) , function (err) {
if (err) return console.log(err);
console.log('Saved!');
}
);
}
catch (error) {
console.log(error);
}
})();