{"id":15748818,"url":"https://github.com/grantbirki/comment","last_synced_at":"2025-05-13T01:24:09.098Z","repository":{"id":39867944,"uuid":"495574442","full_name":"GrantBirki/comment","owner":"GrantBirki","description":"GitHub Action to create, update, or add a reaction to any issue or pull request","archived":false,"fork":false,"pushed_at":"2025-05-11T06:00:30.000Z","size":3303,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-12T02:10:02.239Z","etag":null,"topics":["actions","automation","comment","github"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GrantBirki.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-23T21:09:47.000Z","updated_at":"2025-05-11T05:54:49.000Z","dependencies_parsed_at":"2023-01-04T12:19:43.065Z","dependency_job_id":"4071a139-3e44-45f0-b5fc-bad06d5cb1aa","html_url":"https://github.com/GrantBirki/comment","commit_stats":{"total_commits":47,"total_committers":2,"mean_commits":23.5,"dds":"0.021276595744680882","last_synced_commit":"1e9986de26cf23e6c4350276234c91705c540fef"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GrantBirki%2Fcomment","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GrantBirki%2Fcomment/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GrantBirki%2Fcomment/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GrantBirki%2Fcomment/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GrantBirki","download_url":"https://codeload.github.com/GrantBirki/comment/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253852003,"owners_count":21973837,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["actions","automation","comment","github"],"created_at":"2024-10-04T06:00:57.069Z","updated_at":"2025-05-13T01:24:09.081Z","avatar_url":"https://github.com/GrantBirki.png","language":"JavaScript","readme":"# Comment Action 💬\n\n[![package-check](https://github.com/GrantBirki/comment/actions/workflows/package-check.yml/badge.svg)](https://github.com/GrantBirki/comment/actions/workflows/package-check.yml) [![lint](https://github.com/GrantBirki/comment/actions/workflows/lint.yml/badge.svg)](https://github.com/GrantBirki/comment/actions/workflows/lint.yml)\n\nGitHub Action to create, update, or add a reaction to any issue or pull request\n\n## Features 🌟\n\n- Create a comment\n- Update a comment\n- Add a reaction to a comment\n- Create or update a comment from a markdown file\n- Create or update a comment from a markdown file with template variable rendering\n\n## Usage 💻\n\nThe section below will contain a few common examples for how you can use this Action\n\n### Create a Comment ✏️\n\n```yml\n    - name: Create comment\n      uses: GrantBirki/comment@vX.X.X\n      with:\n        body: |\n          This is a multi-line test comment\n\n          - With GitHub **Markdown** ✨\n          - Cool!\n        reactions: '+1'\n```\n\n\u003e This will create a brand new comment on an issue/pr with the comment body seen above. It will also add a 👍 reaction\n\n### Update a Comment 📝\n\n```yml\n    - name: Update comment\n      uses: GrantBirki/comment@vX.X.X\n      with:\n        comment-id: 123456789\n        body: |\n          **Edit:** Some additional info\n        reactions: eyes\n```\n\n\u003e This will update the comment with the comment body seen above in the default `append` mode. It will also add a 👀 reaction\n\n### Add Comment Reactions 👍\n\n```yml\n    - name: Add reactions\n      uses: GrantBirki/comment@vX.X.X\n      with:\n        comment-id: 123456789\n        reactions: heart, hooray, laugh\n```\n\n\u003e This will add three reactions to the comment specified by the comment-id\n\n### Use a File as the Comment Body 📂\n\n```yml\n    - name: Create comment from markdown file\n      uses: GrantBirki/comment@vX.X.X\n      with:\n        file: demo/plain-sample.md\n```\n\n\u003e This will create a comment and use the markdown file contents as the comment body\n\n### Use a File as the Comment Body with Template Variables 📜\n\n```yml\n    - name: Create comment from markdown file with variables\n      uses: GrantBirki/comment@vX.X.X\n      with:\n        file: demo/render-sample.md\n        vars: |\n          sha: ${{ github.sha }}\n          environment: production\n          app: cool-app\n```\n\n\u003e This will create a comment and use the markdown file contents as the comment body with the variables specified in the vars section for template rendering\n\nFor more information about **templating**, be sure to check out the [templating](#templating) section below\n\n### Inputs 📥\n\n| Name | Description | Required | Default |\n| --- | --- | --- | --- |\n| `token` | `GITHUB_TOKEN` (`issues: write`, `pull-requests: write`) or a `repo` scoped [PAT](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) | true | `${{ github.token }}` |\n| `repository` | The full name of the repository in which to create or update a comment | true | `${{ github.repository }}` |\n| `issue-number` | The number of the issue or pull request in which to create a comment | true | `${{ github.event.number }}` |\n| `comment-id` | The id of the comment to update | false |  |\n| `body` | The comment body (string) | false | |\n| `file` | The path to a file to use as a comment body | false | |\n| `vars` | Template variables in yaml format for rendering with a provided file | false | |\n| `edit-mode` | The mode when updating a comment, `replace` or `append` | false | `append` |\n| `reactions` | A comma separated list of reactions to add to the comment (`+1`, `-1`, `laugh`, `confused`, `heart`, `hooray`, `rocket`, `eyes`) | false | |\n\n#### Outputs 📤\n\n| Name | Description |\n| --- | --- |\n| `comment-id` | The ID of the created comment |\n\nThe ID of the created comment will be output for use in later steps\nNote that in order to read the step output the action step must have an id.\n\n```yml\n    - name: Create comment\n      uses: GrantBirki/comment@vX.X.X\n      id: comment\n      with:\n        body: hello world\n\n    - name: Check outputs\n      run: echo \"Comment ID - ${{ steps.comment.outputs.comment-id }}\"\n```\n\n### Issue Number 🔢\n\n\u003e Common error: `Missing either 'issue-number' or 'comment-id'`\n\nThe `issue-number` field can be omitted depending on the type of workflow you are using and it will attempt to find the PR/issue number from the event context automatically\n\nThe fallback value is as follows: `${{ github.event.number }}`\n\nYou can always pass in an exact value for the `issue-number` field if you wish to override the automatic lookup. The example below obtains the issue number from the event context in a specific way:\n\n```yaml\n  with:\n    issue-number: ${{ github.event.issue.number }}\n```\n\n\u003e Note: Pull Requests are just Issues under the hood, so when we refer to the `issue-number` that could also be exchanged for a PR number\n\n### Templating\n\nThere are two ways to leverage templates using this Action:\n\n- Simple Template - Just pass in a `file: \u003cpath\u003e` to the Action\n- Template Rendering - Pass in a `file: \u003cpath\u003e` and `vars: \u003cvalues\u003e` to the Action\n\n\u003e ⚠️ Important: Make sure to run the [action/checkout](https://github.com/actions/checkout) Action *before* this Action if using the `file:` input so the action can actually read files from your repo\n\n`file` and `vars` explained:\n\n- `file` is the path to a markdown file in your repository to load as a template\n- `vars` are template variables to use when rendering your markdown file template\n\nThe `vars` input is a yaml string that will be parsed and converted to a map of key/value pairs. An example can be seen below\n\nActions workflow:\n\n```yml\n  with:\n    file: demo/render-sample.md\n    vars: |\n      sha: ${{ github.sha }}\n      environment: production\n      app: cool-app\n```\n\nMarkdown Template:\n\n```markdown\n# Deployment Status 🚀\n\n**{{ app }}** has been successfully deployed to **{{ environment }}**\n\n- SHA: `{{ sha }}`\n```\n\nThis Action uses [nunjucks](https://github.com/mozilla/nunjucks) to render template files with the `vars` variables provided. You can fully leverage all the features nunjucks has to offer to custimize templates to your heart's content.\n\nAn example of a markdown template file can be seen [here](demo/render-sample.md). When this Action runs, it will render the `demo/render-sample.md` file with the `vars` provided to dynamically generate the comment body!\n\nYou can even pass in GitHub Actions context variables as seen above (ex: `${{ github.sha }}`)\n\n\u003e Checkout a sample workflow file [here](demo/sample-workflow.yml) to see this in action\n\n#### Iterating Over Arrays in Templates\n\nThis example shows how you can iterate over an array of values and populate a template with them:\n\n```yaml\njobs:\n  example:\n    runs-on: ubuntu-latest\n    steps:\n      - id: run\n        run:  echo \"files=a,b,c\" \u003e\u003e \"$GITHUB_OUTPUT\"\n\n      - uses: GrantBirki/comment@vX.X.X\n        with:\n          # other config\n          vars: |\n            files: ${{ steps.run.outputs.files }}\n          body: |\n            # Files\n            {% for file in files.split(\",\") %}\n            - `{{ file }}`\n            {% else %}\n            - No file\n            {% endfor %}\n```\n\nYou can also put the iteration logic in the template file itself rather than using the `body` input in the workflow file:\n\n```markdown\n# Files\n{% for file in files.split(\",\") %}\n- `{{ file }}`\n{% else %}\n- No file\n{% endfor %}\n```\n\n\u003e Source: [#11](https://github.com/GrantBirki/comment/issues/11)\n\n### Where to Find the ID of a Comment 🔍\n\n\u003e How to find the id of a comment will depend a lot on the use case\n\nHere is one example where the id can be found in the `github` context during an `issue_comment` event:\n\n```yml\non:\n  issue_comment:\n    types: [created]\njobs:\n  commentCreated:\n    runs-on: ubuntu-latest\n    steps:\n      - name: Add reaction\n        uses: GrantBirki/comment@vX.X.X\n        with:\n          comment-id: ${{ github.event.comment.id }}\n          reactions: eyes\n```\n\n\u003e You can also use the [find-comment](https://github.com/peter-evans/find-comment) Action to locate the comment id in many different ways\n\n### Error: Repository Not Found 🚫\n\nIf you are trying to use this Action with its template features, you will need to checkout the repository first before calling this Action. This ensure the proper files are available to be read by the Action. If your `actions/checkout` job fails with `Repository Not Found`, it is likely due to missing permissions. Try adding this at the top of your Actions workflow file:\n\n```yml\npermissions:\n  issues: write # needed for creating comments on issues\n  pull-requests: write # needed for creating comments on pull requests\n  contents: read # bingo!\n```\n\nAssigning `read` to the `contents` permission will allow Actions to checkout your repository\n\n### Error: Resource not Accessible by Integration ❌\n\nCommon causes can be seen below\n\n#### Workflow triggered from a fork\n\nIn *public* repositories this action does not work in `pull_request` workflows when triggered by forks\n\nAny attempt will be met with the error, `Resource not accessible by integration`\n\n#### Insufficient Permissions\n\nThis Action needs `write` access to issue, pull requests, or both depending on how you are using it:\n\n```yml\npermissions:\n  issues: write\n  pull-requests: write\n```\n\n### Accessing Issues and Comments in other Repositories 🧑‍🤝‍🧑\n\nYou can create and update comments 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`.\n\nThe user associated with the PAT must have write access to the repository\n\n### Inspiration 🌠\n\nThis Action was largely inspired by the [create-or-update-comment](https://github.com/peter-evans/create-or-update-comment) Action by [@peter-evans](https://github.com/peter-evans). In fact, it shared the majority of the code with that Action. The reason this Action was created was because a comment Action was needed that supported template rendering and was not available in the `create-or-update-comment`. It was suggested to use a second Action [render-template](https://github.com/chuhlomin/render-template) and pass the outputs of that Action into the `create-or-update-comment` Action.\n\nThis Action solves that problem by using the [nunjucks](https://github.com/mozilla/nunjucks) package for full template rendering\n\n## License\n\n[MIT](LICENSE)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrantbirki%2Fcomment","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgrantbirki%2Fcomment","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrantbirki%2Fcomment/lists"}