forked from pass-culture-github-actions/comment-pull-request
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: first commit with documentation
- Loading branch information
Showing
9 changed files
with
20,902 additions
and
58,726 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
# Comment Pull Request - GitHub Actions | ||
# Changed ArgoCD app - GitHub Actions | ||
|
||
## What is it ? | ||
|
||
A GitHub action that comments with a given message the pull request linked to the pushed branch. | ||
You can even put dynamic data thanks to [Contexts and expression syntax](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions). | ||
GitHub action to retrieve argocd app edited in a PR. | ||
|
||
## Usage | ||
|
||
|
@@ -13,177 +12,56 @@ You can even put dynamic data thanks to [Contexts and expression syntax](https:/ | |
on: pull_request | ||
|
||
jobs: | ||
example_comment_pr: | ||
argocd-apps: | ||
runs-on: ubuntu-latest | ||
name: An example job to comment a PR | ||
name: An example job that return argocd list of app with changes | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Comment PR | ||
uses: pass-culture-github-actions/[email protected] | ||
uses: actions/checkout@v4 | ||
- name: Get changed files | ||
id: changed-files | ||
uses: tj-actions/changed-files@v42 | ||
- name: Get argocd app list concerned by changes | ||
uses: pass-culture-github-actions/[email protected] | ||
with: | ||
message: | | ||
Hello world ! :wave: | ||
``` | ||
### Comment max length | ||
Thanks to the `cutDelimiter` input, a comment can have any length behond the actual github comment limit (65536 characters) | ||
|
||
It will use the closest delimiter prior the limit and truncate the message as much as necessary. | ||
|
||
```yml | ||
- name: PR comment with file | ||
uses: pass-culture-github-actions/comment-pull-request@v2 | ||
with: | ||
cutDelimiter: '<!-- cut-delimiter -->' # this is default delimiter, you can change it using cutDelimiter input | ||
filePath: /path/to/file.txt | ||
``` | ||
|
||
### Comment a file content | ||
|
||
Thanks to the `filePath` input, a file content can be commented. | ||
You can either pass an absolute filePath or a relative one that will be by default retrieved from `GITHUB_WORKSPACE`. | ||
(Note that if both a `message` and `filePath` are provided, `message` will take precedence.) | ||
|
||
```yml | ||
- name: PR comment with file | ||
uses: pass-culture-github-actions/comment-pull-request@v2 | ||
with: | ||
filePath: /path/to/file.txt | ||
``` | ||
|
||
|
||
### Setting reactions | ||
|
||
You can also set some reactions on your comments through the `reactions` input. | ||
It takes only valid reactions and adds it to the comment you've just created. (See https://docs.github.com/en/rest/reactions#reaction-types) | ||
|
||
```yml | ||
- name: PR comment with reactions | ||
uses: pass-culture-github-actions/comment-pull-request@v2 | ||
with: | ||
message: | | ||
Hello world ! :wave: | ||
reactions: eyes, rocket | ||
``` | ||
|
||
### Specifying which pull request to comment on | ||
|
||
You can explicitly input which pull request should be commented on by passing the `pr_number` input. | ||
That is particularly useful for manual workflow for instance (`workflow_run`). | ||
|
||
```yml | ||
... | ||
- name: Comment PR | ||
uses: pass-culture-github-actions/comment-pull-request@v2 | ||
with: | ||
message: | | ||
Hello world ! :wave: | ||
pr_number: 123 # This will comment on pull request #123 | ||
all_modified_files: ${{ steps.changed-files.outputs.all_modified_files }} # From tj-actions/changed-files | ||
``` | ||
### Update a comment | ||
|
||
Editing an existing comment is also possible thanks to the `comment_tag` input. | ||
|
||
Thanks to this parameter, it will be possible to identify your comment and then to upsert on it. | ||
If the comment is not found at first, it will create a new comment. | ||
|
||
_That is particularly interesting while committing multiple times in a PR and that you just want to have the last execution report printed. It avoids flooding the PR._ | ||
|
||
```yml | ||
... | ||
- name: Comment PR with execution number | ||
uses: pass-culture-github-actions/comment-pull-request@v2 | ||
with: | ||
message: | | ||
_(execution **${{ github.run_id }}** / attempt **${{ github.run_attempt }}**)_ | ||
comment_tag: execution | ||
``` | ||
|
||
Note: the input `mode` can be used to either `upsert` (by default) or `recreate` the comment (= delete and create) | ||
|
||
### Delete a comment | ||
|
||
Deleting an existing comment is also possible thanks to the `comment_tag` input combined with `mode: delete`. | ||
|
||
This will delete the comment at the end of the job. | ||
|
||
```yml | ||
... | ||
- name: Write a comment that will be deleted at the end of the job | ||
uses: pass-culture-github-actions/comment-pull-request@v2 | ||
with: | ||
message: | | ||
The PR is being built... | ||
comment_tag: to_delete | ||
mode: delete | ||
``` | ||
|
||
## Inputs | ||
## Inputs | ||
### Action inputs | ||
| Name | Description | Required | Default | | ||
| --- | --- | --- | --- | | ||
| `GITHUB_TOKEN` | Token that is used to create comments. Defaults to ${{ github.token }} | ✅ | | | ||
| `message` | Comment body | | | | ||
| `filePath` | Path of the file that should be commented | | | | ||
| `reactions` | List of reactions for the comment (comma separated). See https://docs.github.com/en/rest/reactions#reaction-types | | | | ||
| `pr_number` | The number of the pull request where to create the comment | | current pull-request/issue number (deduced from context) | | ||
| `comment_tag` | A tag on your comment that will be used to identify a comment in case of replacement | | | | ||
| `mode` | Mode that will be used to update comment (upsert/recreate/delete) | | upsert | | ||
| `create_if_not_exists` | Whether a comment should be created even if `comment_tag` is not found | | true | | ||
| `all_modified_files` | From tj-actions/changed-files: Returns all changed files i.e. a combination of all added, copied, modified and renamed files (ACMR) | ✅ | | | ||
|
||
|
||
|
||
## Outputs | ||
## Outputs | ||
|
||
### Action outputs | ||
|
||
You can get some outputs from this actions : | ||
You can get some outputs from this actions : | ||
|
||
| Name | Description | | ||
| --- | --- | | ||
| `id` | Comment id that was created or updated | | ||
| `body` | Comment body | | ||
| `html_url` | URL of the comment created or updated | | ||
| Name | Description | | ||
| ------ | ----------------------------------- | | ||
| `apps` | The list of ArgoCD app with changes | | ||
|
||
### Example output | ||
|
||
```yaml | ||
- name: Comment PR | ||
uses: pass-culture-github-actions/comment-pull-request@v2 | ||
id: hello | ||
- uses: pass-culture-github-actions/[email protected] | ||
id: argocd-apps | ||
with: | ||
message: | | ||
Hello world ! :wave: | ||
- name: Check outputs | ||
all_modified_files: ${{ steps.changed-files.outputs.all_modified_files }} # From tj-actions/changed-files | ||
- name: Check apps | ||
run: | | ||
echo "id : ${{ steps.hello.outputs.id }}" | ||
echo "body : ${{ steps.hello.outputs.body }}" | ||
echo "html_url : ${{ steps.hello.outputs.html_url }}" | ||
echo "${{ steps.argocd-apps.outputs.apps }}" | ||
# With `steps.argocd-apps.outputs.apps='posthog clickhouse external-dns'` | ||
# Outputs : `posthog clickhouse external-dns` | ||
``` | ||
|
||
## Permissions | ||
|
||
Depending on the permissions granted to your token, you may lack some rights. | ||
To run successfully, this actions needs at least : | ||
|
||
```yaml | ||
permissions: | ||
pull-requests: write | ||
``` | ||
|
||
Add this in case you get `Resource not accessible by integration` error. | ||
See [jobs.<job_id>.permissions](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idpermissions) for more information. | ||
|
||
|
||
> Note that, if the PR comes from a fork, it will have only read permission despite the permissions given in the action for the `pull_request` event. | ||
> In this case, you may use the `pull_request_target` event. With this event, permissions can be given without issue (the difference is that it will execute the action from the target branch and not from the origin PR). | ||
|
||
## Contributing | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,12 @@ | ||
name: 'Comment Pull Request' | ||
branding: | ||
icon: 'message-circle' | ||
color: 'blue' | ||
description: 'Comments a pull request with the provided message' | ||
name: 'Argocd apps edited in PR' | ||
description: 'GitHub action to retrieve argocd app edited in a PR' | ||
inputs: | ||
message: | ||
description: 'Message that should be printed in the pull request' | ||
filePath: | ||
description: 'Path of the file that should be commented' | ||
GITHUB_TOKEN: | ||
description: 'Github token of the repository (automatically created by Github)' | ||
default: ${{ github.token }} | ||
required: false | ||
reactions: | ||
description: 'You can set some reactions on your comments through the `reactions` input.' | ||
pr_number: | ||
description: 'Manual pull request number' | ||
comment_tag: | ||
description: 'A tag on your comment that will be used to identify a comment in case of replacement.' | ||
mode: | ||
description: 'Mode that will be used to update comment (upsert/recreate)' | ||
default: 'upsert' | ||
create_if_not_exists: | ||
description: 'Whether a comment should be created even if comment_tag is not found.' | ||
default: 'true' | ||
cutDelimiter: | ||
description: 'If comment length is greater than 65536 (max is 65536), it will create multiple comments splitting on delimiter close to limit' | ||
required: false | ||
default: '<!-- cut-delimiter -->' | ||
cutMessage: | ||
description: 'If set, otheride the default splitting message when a message is cut' | ||
required: false | ||
default: '<b>Warning:</b> Output length greater than max comment size. Continued in next comment.' | ||
all_modified_files: | ||
description: 'From tj-actions/changed-files: Returns all changed files i.e. a combination of all added, copied, modified and renamed files (ACMR)' | ||
required: true | ||
outputs: | ||
apps: | ||
description: 'The list of ArgoCD app with changes' | ||
runs: | ||
using: 'node16' | ||
main: 'lib/index.js' | ||
post: 'lib/cleanup/index.js' |
Oops, something went wrong.