Skip to content

Commit

Permalink
Merge pull request #21 from peter-evans/pr-comment
Browse files Browse the repository at this point in the history
Default pull request events to the branch HEAD commit
  • Loading branch information
peter-evans authored Jun 19, 2020
2 parents 0b99e67 + d4050fe commit db40cd9
Show file tree
Hide file tree
Showing 7 changed files with 4,077 additions and 416 deletions.
10 changes: 1 addition & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ jobs:
with:
name: action.yml
path: action.yml
- id: vars
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then \
echo "::set-output name=sha::${{ github.event.pull_request.head.sha }}"; \
else \
echo "::set-output name=sha::${{ github.sha }}"; \
fi

test:
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository
Expand All @@ -62,10 +55,9 @@ jobs:
- name: Test create commit comment
uses: ./
with:
sha: ${{ needs.build.outputs.sha }}
body: |
This is a multi-line test comment
- With GitHub **Markdown**
- With GitHub **Markdown** :sparkles:
- Created by [commit-comment][1]
[1]: https://github.com/peter-evans/commit-comment
Expand Down
27 changes: 17 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,47 @@ A GitHub action to create a comment for a commit on GitHub.
with:
body: |
This is a multi-line test comment
- With GitHub **Markdown**
- With GitHub **Markdown** :sparkles:
- Created by [commit-comment][1]
[1]: https://github.com/peter-evans/commit-comment
```
## Parameters
## Action inputs
- `token` - The GitHub authentication token. Defaults to `GITHUB_TOKEN`.
- `sha` - The commit SHA. Defaults to the current commit.
- `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.
| Name | Description | Default |
| --- | --- | --- |
| `token` | `GITHUB_TOKEN` or a `repo` scoped [PAT](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line). | `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. | |

## Example

Here is an example setting all of the input parameters.
Here is an example setting optional input parameters.

```yml
- name: Create commit comment
uses: peter-evans/commit-comment@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
sha: 843dea1cc2e721163c20a5c876b5b155f7f3aa75
body: |
This is a multi-line test comment
- With GitHub **Markdown**
- With GitHub **Markdown** :sparkles:
- Created by [commit-comment][1]
[1]: https://github.com/peter-evans/commit-comment
path: path/to/file.txt
position: 1
```

### Accessing commits in other repositories

You can create a commit comment in another repository by using a [PAT](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line) instead of `GITHUB_TOKEN`.
The user associated with the PAT must have write access to the repository.

## License

[MIT](LICENSE)
6 changes: 4 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ inputs:
token:
description: 'The GitHub authentication token'
default: ${{ github.token }}
required: true
repository:
description: 'The full name of the target repository.'
default: ${{ github.repository }}
sha:
description: 'The commit SHA. Defaults to the current commit.'
description: 'The commit SHA.'
body:
description: 'The contents of the comment.'
required: true
Expand Down
Loading

2 comments on commit db40cd9

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a multi-line test comment

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a multi-line test comment

Please sign in to comment.