-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhelpers.js
More file actions
67 lines (59 loc) · 1.42 KB
/
helpers.js
File metadata and controls
67 lines (59 loc) · 1.42 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
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.getIssueFromBranch = function(pushRef) {
let regex1 = /refs\/heads\/(\d+)/i
let found = pushRef.match(regex1)
if (found) {
return found[1]
console.log('function: ' + found)
} else {
return false
}
}
module.exports.checkForCommitActions = function(commitMessage) {
let regex1 = /#comment (.*)/i
let found = commitMessage.match(regex1)
if (found) {
return found[1]
} else {
return false
}
}
module.exports.addComment = function(
octokit,
eventOwner,
eventRepo,
branchIssueNumber,
comment
) {
octokit.issues
.createComment({
owner: eventOwner,
repo: eventRepo,
issue_number: branchIssueNumber,
body: comment
})
.then(({ data, headers, status }) => {
// handle data
})
.catch(err => {
console.log(err)
})
}