Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3 #161

Merged
merged 17 commits into from
Apr 5, 2023
3 changes: 3 additions & 0 deletions .eslintignore
@@ -0,0 +1,3 @@
dist/
lib/
node_modules/
33 changes: 17 additions & 16 deletions .eslintrc.json
@@ -1,17 +1,18 @@
{
"env": {
"commonjs": true,
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018
},
"rules": {
}
}
"env": { "node": true, "jest": true },
"parser": "@typescript-eslint/parser",
"parserOptions": { "ecmaVersion": 9, "sourceType": "module" },
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
"plugin:prettier/recommended"
],
"plugins": ["@typescript-eslint"],
"rules": {
"@typescript-eslint/camelcase": "off"
}
}
2 changes: 1 addition & 1 deletion .github/comment-body-addition.md
@@ -1 +1 @@
**Edit:** Some additional info
This is still the second line.
5 changes: 1 addition & 4 deletions .github/comment-body.md
@@ -1,5 +1,2 @@
This is a multi-line test comment read from a file.
- With GitHub **Markdown** :sparkles:
- Created by [create-or-update-comment][1]

[1]: https://github.com/peter-evans/create-or-update-comment
This is the second line.
21 changes: 15 additions & 6 deletions .github/workflows/ci.yml
Expand Up @@ -28,8 +28,10 @@ jobs:
node-version: 16.x
cache: npm
- run: npm ci
- run: npm run build
- run: npm run format-check
- run: npm run lint
- run: npm run test
- run: npm run package
- uses: actions/upload-artifact@v3
with:
name: dist
Expand Down Expand Up @@ -86,27 +88,34 @@ jobs:
body: |
**Edit:** Some additional info
reactions: eyes
reactions-edit-mode: replace

- name: Test add reactions
uses: ./
with:
comment-id: ${{ steps.couc.outputs.comment-id }}
reactions: heart, hooray, laugh
reactions: |
heart
hooray
laugh

- name: Test create comment from file
uses: ./
id: couc2
with:
issue-number: ${{ needs.build.outputs.issue-number }}
body-file: .github/comment-body.md
reactions: '+1'
body-path: .github/comment-body.md
reactions: |
+1

- name: Test update comment from file
uses: ./
with:
comment-id: ${{ steps.couc2.outputs.comment-id }}
body-file: .github/comment-body-addition.md
reactions: eyes
body-path: .github/comment-body-addition.md
append-separator: space
reactions: eyes, rocket
reactions-edit-mode: replace

package:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
Expand Down
17 changes: 9 additions & 8 deletions .github/workflows/test-command.yml
Expand Up @@ -45,6 +45,7 @@ jobs:
body: |
**Edit:** Some additional info
reactions: eyes
reactions-edit-mode: replace

# Test add reactions
- name: Add reactions
Expand All @@ -53,19 +54,12 @@ jobs:
comment-id: ${{ steps.couc.outputs.comment-id }}
reactions: heart, hooray, laugh

- name: Add reaction
uses: peter-evans/create-or-update-comment@v2
with:
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
reactions: hooray

# Test create with body from file
- name: Create comment
uses: ./
with:
issue-number: 1
body-file: .github/comment-body.md
body-path: .github/comment-body.md

# Test create from template
- name: Render template
Expand All @@ -82,3 +76,10 @@ jobs:
with:
issue-number: 1
body: ${{ steps.template.outputs.result }}

- name: Add reaction
uses: peter-evans/create-or-update-comment@v2
with:
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
reactions: hooray
1 change: 1 addition & 0 deletions .github/workflows/update-major-version.yml
Expand Up @@ -12,6 +12,7 @@ on:
description: The major version tag to update
options:
- v2
- v3

jobs:
tag:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
@@ -1 +1,2 @@
node_modules
lib/
node_modules/
3 changes: 3 additions & 0 deletions .prettierignore
@@ -0,0 +1,3 @@
dist/
lib/
node_modules/
11 changes: 11 additions & 0 deletions .prettierrc.json
@@ -0,0 +1,11 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": false,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": false,
"arrowParens": "avoid",
"parser": "typescript"
}
41 changes: 22 additions & 19 deletions README.md
Expand Up @@ -4,15 +4,13 @@

A GitHub action to create or update an issue or pull request comment.

This action was created to help facilitate a GitHub Actions "ChatOps" solution in conjunction with [slash-command-dispatch](https://github.com/peter-evans/slash-command-dispatch) action.

## Usage

### Add a comment to an issue or pull request

```yml
- name: Create comment
uses: peter-evans/create-or-update-comment@v2
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: 1
body: |
Expand All @@ -28,7 +26,7 @@ This action was created to help facilitate a GitHub Actions "ChatOps" solution i

```yml
- name: Update comment
uses: peter-evans/create-or-update-comment@v2
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: 557858210
body: |
Expand All @@ -40,10 +38,13 @@ This action was created to help facilitate a GitHub Actions "ChatOps" solution i

```yml
- name: Add reactions
uses: peter-evans/create-or-update-comment@v2
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: 557858210
reactions: heart, hooray, laugh
reactions: |
heart
hooray
laugh
```

### Action inputs
Expand All @@ -54,10 +55,12 @@ This action was created to help facilitate a GitHub Actions "ChatOps" solution i
| `repository` | The full name of the repository in which to create or update a comment. | Current repository |
| `issue-number` | The number of the issue or pull request in which to create a comment. | |
| `comment-id` | The id of the comment to update. | |
| `body` | The comment body. Cannot be used in conjunction with `body-file`. | |
| `body-file` | The path to a file containing the comment body. Cannot be used in conjunction with `body`. | |
| `body` | The comment body. Cannot be used in conjunction with `body-path`. | |
| `body-path` | The path to a file containing the comment body. Cannot be used in conjunction with `body`. | |
| `edit-mode` | The mode when updating a comment, `replace` or `append`. | `append` |
| `reactions` | A comma separated list of reactions to add to the comment. (`+1`, `-1`, `laugh`, `confused`, `heart`, `hooray`, `rocket`, `eyes`) | |
| `append-separator` | The separator to use when appending to an existing comment. (`newline`, `space`, `none`) | `newline` |
| `reactions` | A comma or newline separated list of reactions to add to the comment. (`+1`, `-1`, `laugh`, `confused`, `heart`, `hooray`, `rocket`, `eyes`) | |
| `reactions-edit-mode` | The mode when updating comment reactions, `replace` or `append`. | `append` |

Note: In *public* repositories this action does not work in `pull_request` workflows when triggered by forks.
Any attempt will be met with the error, `Resource not accessible by integration`.
Expand All @@ -70,7 +73,7 @@ Note that in order to read the step output the action step must have an id.

```yml
- name: Create comment
uses: peter-evans/create-or-update-comment@v2
uses: peter-evans/create-or-update-comment@v3
id: couc
with:
issue-number: 1
Expand All @@ -95,7 +98,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Add reaction
uses: peter-evans/create-or-update-comment@v2
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ github.event.comment.id }}
reactions: eyes
Expand All @@ -110,15 +113,15 @@ If the find-comment action output `comment-id` returns an empty string, a new co
If it returns a value, the comment already exists and the content is replaced.
```yml
- name: Find Comment
uses: peter-evans/find-comment@v2
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: Build output

- name: Create or update comment
uses: peter-evans/create-or-update-comment@v2
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
Expand All @@ -131,7 +134,7 @@ If it returns a value, the comment already exists and the content is replaced.
If required, the create and update steps can be separated for greater control.
```yml
- name: Find Comment
uses: peter-evans/find-comment@v2
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
Expand All @@ -140,7 +143,7 @@ If required, the create and update steps can be separated for greater control.

- name: Create comment
if: steps.fc.outputs.comment-id == ''
uses: peter-evans/create-or-update-comment@v2
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
Expand All @@ -149,7 +152,7 @@ If required, the create and update steps can be separated for greater control.

- name: Update comment
if: steps.fc.outputs.comment-id != ''
uses: peter-evans/create-or-update-comment@v2
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
body: |
Expand All @@ -161,10 +164,10 @@ If required, the create and update steps can be separated for greater control.

```yml
- name: Create comment
uses: peter-evans/create-or-update-comment@v2
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: 1
body-file: 'comment-body.md'
body-path: 'comment-body.md'
```

### Using a markdown template
Expand All @@ -187,7 +190,7 @@ The template is rendered using the [render-template](https://github.com/chuhlomi
bar: that

- name: Create comment
uses: peter-evans/create-or-update-comment@v2
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: 1
body: ${{ steps.template.outputs.result }}
Expand Down
18 changes: 13 additions & 5 deletions action.yml
Expand Up @@ -6,20 +6,28 @@ inputs:
default: ${{ github.token }}
repository:
description: 'The full name of the repository in which to create or update a comment.'
default: ${{ github.repository }}
issue-number:
description: 'The number of the issue or pull request in which to create a comment.'
comment-id:
description: 'The id of the comment to update.'
body:
description: 'The comment body. Cannot be used in conjunction with `body-file`.'
body-file:
description: 'The comment body. Cannot be used in conjunction with `body-path`.'
body-path:
description: 'The path to a file containing the comment body. Cannot be used in conjunction with `body`.'
body-file:
description: 'Deprecated in favour of `body-path`.'
edit-mode:
description: 'The mode when updating a comment, "replace" or "append".'
reaction-type:
description: 'Deprecated in favour of `reactions`'
default: 'append'
append-separator:
description: 'The separator to use when appending to an existing comment. (`newline`, `space`, `none`)'
default: 'newline'
reactions:
description: 'A comma separated list of reactions to add to the comment.'
description: 'A comma or newline separated list of reactions to add to the comment.'
reactions-edit-mode:
description: 'The mode when updating comment reactions, "replace" or "append".'
default: 'append'
outputs:
comment-id:
description: 'The id of the created comment'
Expand Down