Skip to content

Commit 5d07c9f

Browse files
authored
Merge pull request #2 from adamzolyak/patching
Patching and Actions YAML
2 parents 8fd0025 + e4d7c1f commit 5d07c9f

6 files changed

Lines changed: 1267 additions & 1171 deletions

File tree

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export GITHUB_TOKEN="12345"
2929
export GITHUB_REPOSITORY="adamzolyak/actions-playground"
3030
export GITHUB_EVENT_PATH="/commit-issue-commenter-action/tests/fixtures/actionTrigger.json"
3131

32-
node index.js
32+
node app.js
3333
```
3434

3535
3. modify contents of [/tests/fixtures/actionTrigger.json](./tests/fixtures/actionTrigger.json) as needed for test data

README.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,22 @@ To use this GitHub Action, you must have access to [GitHub Actions](https://gith
2525

2626
To setup this action:
2727

28-
1. Create a `.github/main.workflow` in your GitHub repo.
29-
2. Add the following code to the `main.workflow` file and commit it to the repo's `master` branch.
30-
31-
```
32-
workflow "Commit Issue Commenter" {
33-
resolves = ["Comment From Commit"]
34-
on = "push"
35-
}
36-
37-
action "Comment From Commit" {
38-
uses = "adamzolyak/commit-issue-commenter-action@master"
39-
secrets = ["GITHUB_TOKEN"]
40-
}
28+
1. Create a `.github/worksflows/main.yml` in your GitHub repo ([more info](https://help.github.com/en/articles/configuring-a-workflow)).
29+
2. Add the following code to the `main.yml` file and commit it to the repo's `master` branch.
30+
31+
```yaml
32+
name: Commit Issue Commenter
33+
34+
on: push
35+
36+
jobs:
37+
checkCommit:
38+
name: Comment From Commit
39+
runs-on: ubuntu-latest
40+
steps:
41+
- uses: adamzolyak/commit-issue-commenter-action@master
42+
env:
43+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4144
```
4245
4346
3. Whenever you push changes to GitHub, the action will run!
@@ -48,4 +51,4 @@ If you have suggestions for how this GitHub Action could be improved, or want to
4851
4952
## License
5053
51-
[ISC](LICENSE) © 2018 Adam Zolyak <adam@tinkurlab.com> (www.tinkurlab.com)
54+
[ISC](LICENSE) © 2019 Adam Zolyak <adam@tinkurlab.com> (www.tinkurlab.com)

dev.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ export GITHUB_TOKEN="12345"
33
export GITHUB_REPOSITORY="adamzolyak/actions-playground"
44
export GITHUB_EVENT_PATH="/commit-issue-commenter-action/tests/fixtures/actionTrigger.json"
55

6-
node index.js
6+
node app.js

helpers.js

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,67 @@
11
const fs = require('fs')
22

33
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)
118
})
9+
}).catch(err => {
10+
console.log(err)
11+
})
1212
}
1313

1414
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)
1717
}
1818

1919
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)
2222
}
2323

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)
2727

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+
}
3434
}
3535

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)
3939

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+
}
4545
}
4646

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)
5766
})
5867
}

0 commit comments

Comments
 (0)