-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathconfig.js
More file actions
73 lines (62 loc) · 2.17 KB
/
config.js
File metadata and controls
73 lines (62 loc) · 2.17 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
65
66
67
68
69
70
71
72
73
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')
this.projectName = core.getInput('project-name')
this.autoCreateProject = core.getInput('auto-create-project')
this.baseBranchName = core.getInput('base-branch-name')
this.targetBranchName = core.getInput('target-branch-name')
this.inputGlobs = core.getInput('source-and-binaries-glob')
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, 'autoCreateProject')
fixBoolean(this, 'waitForCompletion')
fixBoolean(this, 'dryRun')
this.inputGlobs = this.inputGlobs.trim()
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))
}
}
this.projectName = this.projectName.trim()
}
}
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
}
}