forked from codedx/codedx-github-action
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.js
More file actions
64 lines (55 loc) · 1.81 KB
/
config.js
File metadata and controls
64 lines (55 loc) · 1.81 KB
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
const core = require('@actions/core');
function isYamlTrue(value) {
value = value.toLowerCase().trim()
return ["yes", "on", "true"].indexOf(value) >= 0
}
function fixBoolean(target, field) {
const value = target[field]
if (typeof value == 'string') {
target[field] = isYamlTrue(value)
}
}
class Config {
constructor() {
this.serverUrl = core.getInput('server-url', { required: true })
this.apiKey = core.getInput('api-key', { required: true })
this.projectId = core.getInput('project-id', { required: true })
this.inputGlobs = core.getInput('source-and-binaries-glob', { required: true })
this.scanGlobs = core.getInput('tool-outputs-glob')
this.waitForCompletion = core.getInput('wait-for-completion')
this.caCert = core.getInput('ca-cert')
this.dryRun = core.getInput('dry-run')
// debug vars
this.tmpDir = ""
}
sanitize() {
fixBoolean(this, 'waitForCompletion')
fixBoolean(this, 'dryRun')
if (typeof this.projectId != 'number') {
try {
this.projectId = parseInt(this.projectId)
} catch (e) {
throw new Error("Invalid value for projectId, expected a number but got a " + (typeof this.projectId))
}
}
}
}
let usedConfig = null
module.exports = {
Config,
get: function() {
if (!usedConfig) {
usedConfig = new Config()
usedConfig.sanitize()
}
return usedConfig
},
set: function(customConfig) {
if (!customConfig instanceof Config) {
const realConfig = new Config()
Object.keys(customConfig).forEach(k => realConfig[k] = customConfig[k])
customConfig = realConfig
}
usedConfig = customConfig
}
}