-
Notifications
You must be signed in to change notification settings - Fork 200
Expand file tree
/
Copy pathvariables.js
More file actions
71 lines (63 loc) · 1.98 KB
/
variables.js
File metadata and controls
71 lines (63 loc) · 1.98 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
const Diffable = require('./diffable')
const NopCommand = require('../nopcommand')
module.exports = class Variables extends Diffable {
constructor (...args) {
super(...args)
if (this.entries) {
this.entries.forEach((variable) => {
variable.name = variable.name.toUpperCase()
})
}
}
find () {
this.log.debug(`Finding repo vars for ${this.repo.owner}/${this.repo.repo}`)
return this.github.request('GET /repos/:org/:repo/actions/variables', {
org: this.repo.owner,
repo: this.repo.repo
}).then(({ data: { variables } }) => variables.map(({ name, value }) => ({ name, value })))
}
comparator (existing, attrs) {
return existing.name === attrs.name
}
changed (existing, attrs) {
return existing.value !== attrs.value
}
update (existing, attrs) {
if (this.nop) {
return Promise.resolve([
new NopCommand(this.constructor.name, this.repo, null, `Update variable ${attrs.name}`)
])
}
return this.github.request('PATCH /repos/:org/:repo/actions/variables/:variable_name', {
org: this.repo.owner,
repo: this.repo.repo,
variable_name: attrs.name.toUpperCase(),
value: attrs.value.toString()
})
}
add (attrs) {
if (this.nop) {
return Promise.resolve([
new NopCommand(this.constructor.name, this.repo, null, `Add variable ${attrs.name}`)
])
}
return this.github.request('POST /repos/:org/:repo/actions/variables', {
org: this.repo.owner,
repo: this.repo.repo,
name: attrs.name.toUpperCase(),
value: attrs.value.toString()
})
}
remove (existing) {
if (this.nop) {
return Promise.resolve([
new NopCommand(this.constructor.name, this.repo, null, `Remove variable ${existing.name}`)
])
}
return this.github.request('DELETE /repos/:org/:repo/actions/variables/:variable_name', {
org: this.repo.owner,
repo: this.repo.repo,
variable_name: existing.name.toUpperCase()
})
}
}