-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathhelpers.js
76 lines (64 loc) · 1.93 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
73
74
75
76
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.listFiles = async function (octokit, eventOwner, eventRepo, eventIssueNumber) {
const options = octokit.rest.pulls.listFiles.endpoint.merge({
owner: eventOwner,
repo: eventRepo,
pull_number: eventIssueNumber,
})
return await octokit
.paginate(options)
.then((data) => {
return data
})
.catch((err) => {
console.log(err)
})
}
module.exports.getMonorepo = function (baseDirectories, filePath) {
const regexPattern = `^${baseDirectories}(?![\.])([^/]*)/`
var regex = new RegExp(regexPattern)
var found = filePath.match(regex)
if (found) return found[1]
else return false
}
module.exports.addLabel = function (octokit, eventOwner, eventRepo, eventIssueNumber, label) {
octokit.rest.issues
.addLabels({
owner: eventOwner,
repo: eventRepo,
issue_number: eventIssueNumber,
labels: [label], // ['Label 1']
})
.then(({ data, headers, status }) => {
// handle data
})
.catch((err) => {
console.log(err)
})
}
module.exports.getLabel = function (repo) {
const prefix = process.env.INPUT_PREFIX || ''
const suffix = process.env.INPUT_SUFFIX || ''
const separator = process.env.INPUT_SEPARATOR || ''
repo = repo || ''
const label = `${prefix}${separator}${repo}${separator}${suffix}`.trim()
return label
}