-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhelpers.js
72 lines (63 loc) · 1.78 KB
/
helpers.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
const fs = require('fs')
module.exports.readFilePromise = function (filename) {
return new Promise((resolve, reject) => {
fs.readFile(filename, 'utf8', (err, data) => {
if (err) reject(err)
else resolve(data)
})
}).catch((err) => {
console.log(err)
})
}
module.exports.getOwner = function (eventOwnerAndRepo) {
const slicePos1 = eventOwnerAndRepo.indexOf('/')
return eventOwnerAndRepo.slice(0, slicePos1)
}
module.exports.getRepo = function (eventOwnerAndRepo) {
const slicePos1 = eventOwnerAndRepo.indexOf('/')
return eventOwnerAndRepo.slice(slicePos1 + 1, eventOwnerAndRepo.length)
}
module.exports.getBulkLabels = function (eventIssueBody) {
const regex = RegExp(/^\[(.*){3}\]/m)
const matches = regex.exec(eventIssueBody)
if (matches) {
return matches[0].slice(1, matches[0].length - 1).split(', ')
} else {
return matches
}
}
module.exports.addLabel = function (octokit, eventOwner, eventRepo, eventIssueNumber, label) {
octokit.issues
.addLabels({
owner: eventOwner,
repo: eventRepo,
issue_number: eventIssueNumber,
labels: [label], // ['Incomplete Tasks']
})
.then(({ data, headers, status }) => {
// handle data
})
.catch((err) => {
console.log(err)
})
}
module.exports.getRepoLabels = async function (octokit, eventOwner, eventRepo) {
return octokit.issues
.listLabelsForRepo({
owner: eventOwner,
repo: eventRepo,
})
.then(({ data, headers, status }) => {
return data
})
.catch((err) => {
console.log(err)
})
}
module.exports.addShortLabelName = async function (repoLabels) {
repoLabel = await repoLabels.map((repoLabel) => {
repoLabel.shortLabelName = repoLabel.name.slice(0, 3)
return repoLabel
})
return repoLabel
}