|
1 | 1 | const fs = require('fs') |
2 | 2 |
|
3 | 3 | module.exports.readFilePromise = function(filename) { |
4 | | - return new Promise((resolve, reject) => { |
5 | | - fs.readFile(filename, 'utf8', (err, data) => { |
6 | | - if (err) reject(err); |
7 | | - else resolve(data); |
8 | | - }) |
9 | | - }).catch(err => { |
10 | | - console.log(err) |
| 4 | + return new Promise((resolve, reject) => { |
| 5 | + fs.readFile(filename, 'utf8', (err, data) => { |
| 6 | + if (err) reject(err) |
| 7 | + else resolve(data) |
11 | 8 | }) |
| 9 | + }).catch(err => { |
| 10 | + console.log(err) |
| 11 | + }) |
12 | 12 | } |
13 | 13 |
|
14 | 14 | module.exports.getOwner = function(eventOwnerAndRepo) { |
15 | | - const slicePos1 = eventOwnerAndRepo.indexOf("/") |
16 | | - return eventOwnerAndRepo.slice(0, slicePos1) |
| 15 | + const slicePos1 = eventOwnerAndRepo.indexOf('/') |
| 16 | + return eventOwnerAndRepo.slice(0, slicePos1) |
17 | 17 | } |
18 | 18 |
|
19 | 19 | module.exports.getRepo = function(eventOwnerAndRepo) { |
20 | | - const slicePos1 = eventOwnerAndRepo.indexOf("/") |
21 | | - return eventOwnerAndRepo.slice(slicePos1 + 1, eventOwnerAndRepo.length) |
| 20 | + const slicePos1 = eventOwnerAndRepo.indexOf('/') |
| 21 | + return eventOwnerAndRepo.slice(slicePos1 + 1, eventOwnerAndRepo.length) |
22 | 22 | } |
23 | 23 |
|
24 | | -module.exports.getIssueFromBranch = function(pushRef) { |
25 | | - let regex1 = /refs\/heads\/(\d+)/i |
26 | | - let found = pushRef.match(regex1) |
| 24 | +module.exports.getIssueFromBranch = function(pushRef) { |
| 25 | + let regex1 = /refs\/heads\/(\d+)/i |
| 26 | + let found = pushRef.match(regex1) |
27 | 27 |
|
28 | | - if(found) { |
29 | | - return found[1] |
30 | | - console.log('function: ' + found) |
31 | | - } else { |
32 | | - return false |
33 | | - } |
| 28 | + if (found) { |
| 29 | + return found[1] |
| 30 | + console.log('function: ' + found) |
| 31 | + } else { |
| 32 | + return false |
| 33 | + } |
34 | 34 | } |
35 | 35 |
|
36 | | -module.exports.checkForCommitActions = function(commitMessage) { |
37 | | - let regex1 = /#comment (.*)/i |
38 | | - let found = commitMessage.match(regex1) |
| 36 | +module.exports.checkForCommitActions = function(commitMessage) { |
| 37 | + let regex1 = /#comment (.*)/i |
| 38 | + let found = commitMessage.match(regex1) |
39 | 39 |
|
40 | | - if(found) { |
41 | | - return found[1] |
42 | | - } else { |
43 | | - return false |
44 | | - } |
| 40 | + if (found) { |
| 41 | + return found[1] |
| 42 | + } else { |
| 43 | + return false |
| 44 | + } |
45 | 45 | } |
46 | 46 |
|
47 | | -module.exports.addComment = function(octokit, eventOwner, eventRepo, branchIssueNumber, comment) { |
48 | | - octokit.issues.createComment({ |
49 | | - owner: eventOwner, |
50 | | - repo: eventRepo, |
51 | | - number: branchIssueNumber, |
52 | | - body: comment |
53 | | - }).then(({ data, headers, status }) => { |
54 | | - // handle data |
55 | | - }).catch(err => { |
56 | | - console.log(err) |
| 47 | +module.exports.addComment = function( |
| 48 | + octokit, |
| 49 | + eventOwner, |
| 50 | + eventRepo, |
| 51 | + branchIssueNumber, |
| 52 | + comment |
| 53 | +) { |
| 54 | + octokit.issues |
| 55 | + .createComment({ |
| 56 | + owner: eventOwner, |
| 57 | + repo: eventRepo, |
| 58 | + issue_number: branchIssueNumber, |
| 59 | + body: comment |
| 60 | + }) |
| 61 | + .then(({ data, headers, status }) => { |
| 62 | + // handle data |
| 63 | + }) |
| 64 | + .catch(err => { |
| 65 | + console.log(err) |
57 | 66 | }) |
58 | 67 | } |
0 commit comments