Skip to content

Commit 289c176

Browse files
authored
Merge pull request #22 from TinkurLab/patching-2022-11
Patching 2022-11
2 parents f6a071f + b2f4379 commit 289c176

9 files changed

Lines changed: 322 additions & 614 deletions

File tree

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
21
export GITHUB_TOKEN="12345"
32
export GITHUB_REPOSITORY="tinkurlab/actions-playground"
4-
export GITHUB_EVENT_PATH="/commit-issue-commenter-action/tests/fixtures/actionTrigger.json"
5-
6-
node app.js
3+
export GITHUB_EVENT_PATH="/commit-issue-commenter-action/tests/fixtures/actionTrigger.json"

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
.DS_Store
3-
dev
3+
dev
4+
.env

CONTRIBUTING.md

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,14 @@ Tests are written in [Jest](https://jestjs.io/en/). Tests automatically run on c
1515
### To run tests locally
1616

1717
1. run `npm install` to install dependencies
18-
2. run `npm test` to run tests
18+
1. run `npm test` to run tests
1919

2020
### To run action locally
2121

2222
1. `npm install` to install dependencies
23-
2. create a `dev` file with the following contents:
24-
25-
```bash
26-
export GITHUB_TOKEN="12345"
27-
export GITHUB_REPOSITORY="tinkurlab/actions-playground"
28-
export GITHUB_EVENT_PATH="/commit-issue-commenter-action/tests/fixtures/actionTrigger.json"
29-
30-
node app.js
31-
```
32-
33-
3. modify contents of [/tests/fixtures/actionTrigger.json](./tests/fixtures/actionTrigger.json) as needed for test data
34-
4. run `bash dev` to run locally
23+
1. create a `.env` file similar to `.env.example`
24+
1. modify contents of [/tests/fixtures/actionTrigger.json](./tests/fixtures/actionTrigger.json) as needed for test data
25+
1. run `npm start` to run locally
3526

3627
## Debugging
3728

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:14
1+
FROM node:16
22

33
LABEL "com.github.actions.name"="Comment on Issue from Commit"
44
LABEL "com.github.actions.description"="Comment on issues from commit messages"

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,6 @@ If you have suggestions for how this GitHub Action could be improved, or want to
5151
5252
## License
5353
54-
[ISC](LICENSE) © 2021 Adam Zolyak <adam@tinkurlab.com> (www.tinkurlab.com)
54+
[ISC](LICENSE) © 2022 Adam Zolyak <adam@tinkurlab.com> (www.tinkurlab.com)
55+
56+
![analytics](https://grabify.link/HBSUPY)

app.js

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ const helpers = require('./helpers')
44

55
//require octokit rest.js
66
//more info at https://github.com/octokit/rest.js
7-
const Octokit = require('@octokit/rest')
7+
const { Octokit } = require('@octokit/rest')
88
const octokit = new Octokit({
9-
auth: `token ${process.env.GITHUB_TOKEN}`
9+
auth: `token ${process.env.GITHUB_TOKEN}`,
1010
})
1111

1212
//set eventOwner and eventRepo based on action's env variables
@@ -15,35 +15,34 @@ const eventOwner = helpers.getOwner(eventOwnerAndRepo)
1515
const eventRepo = helpers.getRepo(eventOwnerAndRepo)
1616

1717
async function commitChecker() {
18-
//read contents of action's event.json
19-
const eventData = await helpers.readFilePromise(
20-
'..' + process.env.GITHUB_EVENT_PATH
21-
)
22-
const eventJSON = JSON.parse(eventData)
23-
24-
//check if branch name starts with an issue number
25-
const branchIssueNumber = helpers.getIssueFromBranch(eventJSON.ref)
26-
27-
if (branchIssueNumber) {
28-
//for each commit, check commit message for comment
29-
eventJSON.commits.forEach(commit => {
30-
const commitComment = helpers.checkForCommitActions(commit.message)
31-
32-
//if comment in commit message, add comment to related issue
33-
if (commitComment) {
34-
const comment = `${commitComment} *from @${
35-
commit.author.username
36-
} in [${commit.id.substring(0, 6)}](${commit.url})*`
37-
38-
helpers.addComment(
39-
octokit,
40-
eventOwner,
41-
eventRepo,
42-
branchIssueNumber,
43-
comment
44-
)
18+
try {
19+
//read contents of action's event.json
20+
const eventData = await helpers.readFilePromise('..' + process.env.GITHUB_EVENT_PATH)
21+
22+
if (eventData) {
23+
const eventJSON = JSON.parse(eventData)
24+
25+
//check if branch name starts with an issue number
26+
const branchIssueNumber = helpers.getIssueFromBranch(eventJSON.ref)
27+
28+
if (branchIssueNumber) {
29+
//for each commit, check commit message for comment
30+
eventJSON.commits.forEach((commit) => {
31+
const commitComment = helpers.checkForCommitActions(commit.message)
32+
33+
//if comment in commit message, add comment to related issue
34+
if (commitComment) {
35+
const comment = `${commitComment} *from @${
36+
commit.author.username
37+
} in [${commit.id.substring(0, 6)}](${commit.url})*`
38+
39+
helpers.addComment(octokit, eventOwner, eventRepo, branchIssueNumber, comment)
40+
}
41+
})
4542
}
46-
})
43+
}
44+
} catch (error) {
45+
console.log(error)
4746
}
4847
}
4948

0 commit comments

Comments
 (0)