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 #115

Merged
merged 8 commits into from Sep 15, 2023
Merged

v3 #115

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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"
}
}
1 change: 1 addition & 0 deletions .github/comment-body-addition.md
@@ -0,0 +1 @@
This is still the second line.
2 changes: 2 additions & 0 deletions .github/comment-body.md
@@ -0,0 +1,2 @@
This is a multi-line test comment read from a file.
This is the second line.
45 changes: 41 additions & 4 deletions .github/workflows/ci.yml
Expand Up @@ -18,17 +18,17 @@ permissions:
jobs:
build:
runs-on: ubuntu-latest
outputs:
sha: ${{ steps.vars.outputs.sha }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 16.x
node-version: 20.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 @@ -60,13 +60,50 @@ jobs:

- name: Test create commit comment
uses: ./
id: cc
with:
body: |
This is a multi-line test comment
- With GitHub **Markdown** :sparkles:
- Created by [commit-comment][1]

[1]: https://github.com/peter-evans/commit-comment
reactions: '+1'

- name: Test update commit comment
uses: ./
with:
comment-id: ${{ steps.cc.outputs.comment-id }}
body: |
**Edit:** Some additional info
reactions: eyes
reactions-edit-mode: replace

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

- name: Test create commit comment from file
uses: ./
id: cc2
with:
body-path: .github/comment-body.md
reactions: |
+1

- name: Test update commit comment from file
uses: ./
with:
comment-id: ${{ steps.cc2.outputs.comment-id }}
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
31 changes: 31 additions & 0 deletions .github/workflows/update-major-version.yml
@@ -0,0 +1,31 @@
name: Update Major Version
run-name: Update ${{ github.event.inputs.main_version }} to ${{ github.event.inputs.target }}

on:
workflow_dispatch:
inputs:
target:
description: The target tag or reference
required: true
main_version:
type: choice
description: The major version tag to update
options:
- v3

jobs:
tag:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
fetch-depth: 0
- name: Git config
run: |
git config user.name actions-bot
git config user.email actions-bot@users.noreply.github.com
- name: Tag new target
run: git tag -f ${{ github.event.inputs.main_version }} ${{ github.event.inputs.target }}
- name: Push new tag
run: git push origin ${{ github.event.inputs.main_version }} --force
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"
}
103 changes: 78 additions & 25 deletions README.md
Expand Up @@ -8,16 +8,46 @@ A GitHub action to create a comment for a commit on GitHub.

## Usage

### Add a comment to the current context's commit SHA

The SHA defaults to `github.sha` OR, for `pull_request` events `github.event.pull_request.head.sha`.

```yml
- name: Create commit comment
uses: peter-evans/commit-comment@v2
uses: peter-evans/commit-comment@v3
with:
body: |
This is a multi-line test comment
- With GitHub **Markdown** :sparkles:
- Created by [commit-comment][1]

[1]: https://github.com/peter-evans/commit-comment
reactions: '+1'
```

### Update a commit comment

```yml
- name: Update commit comment
uses: peter-evans/commit-comment@v3
with:
comment-id: 557858210
body: |
**Edit:** Some additional info
reactions: eyes
```

### Add commit comment reactions

```yml
- name: Add reactions
uses: peter-evans/commit-comment@v3
with:
comment-id: 557858210
reactions: |
heart
hooray
laugh
```

## Action inputs
Expand All @@ -27,51 +57,74 @@ A GitHub action to create a comment for a commit on GitHub.
| `token` | `GITHUB_TOKEN` or a `repo` scoped [PAT](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token). | `GITHUB_TOKEN` |
| `repository` | The full name of the target repository. | `github.repository` (current repository) |
| `sha` | The commit SHA. | `github.sha` OR, for `pull_request` events `github.event.pull_request.head.sha` |
| `body` | (**required**) The contents of the comment. | |
| `path` | Relative path of the file to comment on. | |
| `position` | Line index in the diff to comment on. | |
| `comment-id` | The id of the comment to update. | |
| `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` |
| `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`.
This is due to token restrictions put in place by GitHub Actions. Private repositories can be configured to [enable workflows](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/enabling-features-for-your-repository/managing-github-actions-settings-for-a-repository#enabling-workflows-for-forks-of-private-repositories) from forks to run without restriction. See [here](https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#restrictions-on-repository-forks) for further explanation. Alternatively, use the [`pull_request_target`](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target) event to comment on pull request commits.

## Example
#### Outputs

Here is an example setting optional input parameters.
The ID of the created comment will be output for use in later steps.
Note that in order to read the step output the action step must have an id.

```yml
- name: Create commit comment
uses: peter-evans/commit-comment@v2
uses: peter-evans/commit-comment@v3
id: cc
with:
sha: 843dea1cc2e721163c20a5c876b5b155f7f3aa75
body: |
This is a multi-line test comment
- With GitHub **Markdown** :sparkles:
- Created by [commit-comment][1]

[1]: https://github.com/peter-evans/commit-comment
path: path/to/file.txt
position: 1
My comment
- name: Check outputs
run: |
echo "Comment ID - ${{ steps.cc.outputs.comment-id }}"
```

### Setting the comment body from a file

This example shows how file content can be read into a variable and passed to the action.
```yml
- name: Create commit comment
uses: peter-evans/commit-comment@v3
with:
body-path: 'comment-body.md'
```

### Using a markdown template

In this example, a markdown template file is added to the repository at `.github/comment-template.md` with the following content.
```
This is a test comment template
Render template variables such as {{ .foo }} and {{ .bar }}.
```

The template is rendered using the [render-template](https://github.com/chuhlomin/render-template) action and the result is used to create the comment.
```yml
- id: get-comment-body
run: |
body="$(cat comment-body.txt)"
delimiter="$(openssl rand -hex 8)"
echo "body<<$delimiter" >> $GITHUB_OUTPUT
echo "$body" >> $GITHUB_OUTPUT
echo "$delimiter" >> $GITHUB_OUTPUT
- name: Render template
id: template
uses: chuhlomin/render-template@v1.4
with:
template: .github/comment-template.md
vars: |
foo: this
bar: that

- name: Create commit comment
uses: peter-evans/commit-comment@v2
uses: peter-evans/commit-comment@v3
with:
body: ${{ steps.get-comment-body.outputs.body }}
body: ${{ steps.template.outputs.result }}
```

### Accessing commits in other repositories
### Accessing commits and comments in other repositories

You can create a commit comment in another repository by using a [PAT](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) instead of `GITHUB_TOKEN`.
You can create and update commit comments in another repository by using a [PAT](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) instead of `GITHUB_TOKEN`.
The user associated with the PAT must have write access to the repository.

## License
Expand Down
25 changes: 21 additions & 4 deletions action.yml
Expand Up @@ -9,15 +9,32 @@ inputs:
default: ${{ github.repository }}
sha:
description: 'The commit SHA.'
body:
description: 'The contents of the comment.'
required: true
path:
description: 'Relative path of the file to comment on.'
position:
description: 'Line index in the diff to comment on.'
comment-id:
description: 'The id of the comment to update.'
body:
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`.'
edit-mode:
description: 'The mode when updating a comment, "replace" or "append".'
default: 'append'
append-separator:
description: 'The separator to use when appending to an existing comment. (`newline`, `space`, `none`)'
default: 'newline'
reactions:
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 commit comment'
runs:
using: 'node16'
using: 'node20'
main: 'dist/index.js'
branding:
icon: 'message-square'
Expand Down