/find-create-or-update-comment

A composite GitHub action that can be used to create or update a GitHub issue/pull request comment.

MIT LicenseMIT

Find, create or update comment GitHub action

Test GitHub action Test GitHub action from GH Marketplace Markdown link check GitHub Marketplace

License: MIT GitHub Sponsors LinkedIn

Description

A composite GitHub action that can be used to find a GitHub Issue or Pull Request comment by a specified value and then update the comment if found or create it if not found.

Why should you use this action ?

This is nothing more than a combination of the awesome work done by Peter Evans. I'm combining the find-comment and the create-or-update-comment because I found that I end up using those actions together a lot of the time.

This is a implementation of what is described in the docs for create-or-update-comment.

Usage

- name: Update PR with test results
  uses: edumserrano/find-create-or-update-comment@v2
  with:
    issue-number: ${{ github.event.pull_request.number }}
    body-includes: '<!-- some-unique-id -->'
    comment-author: 'github-actions[bot]'
    body: | # can be a single value or you can compose text with multi-line values
      <!-- some-unique-id -->
      My awesome comment
    edit-mode: replace

The above usage example is using a trick to uniquely identify a comment with some text.

The GitHub comment contains a markdown comment using the <!-- this is a comment --> syntax. The markdown comment text should then be a unique identifier that we can use to search for. This way we can set unique ids for the comments but don't make them visible to the user/whoever is reading the comment on GitHub.

Also note that you can pass input from other steps into the body param by doing something like:

body: |
  <!-- some-unique-id -->
  ${{ steps.some-step-id.outputs.some-step-output }}

Alternatively to using an inline body you can use the body-path to specify a file to use.

Action inputs

Name Description Required Default value
token GITHUB_TOKEN or a repo scoped PAT. yes github.token (job token)
repository The full name of the repository containing the issue or pull request where to find, create or update the comment. yes github.repository (current repository)
issue-number The number of the issue or pull request in which to find, create or update the comment. yes -
body-includes A string to search for in the body of comments. Cannot be used in conjunction with body-regex. yes, unless body-regex is used. -
body-regex A regular expression to search for in the body of comments. Cannot be used in conjunction with body-includes. yes, unless body-includes is used. -
direction Search direction, specified as first or last no first
nth 0-indexed number, specifying which comment to update if multiple are found . no 0
comment-author The GitHub user name of the comment author. false -
body The comment body. Cannot be used in conjunction with body-path. yes, unless body-path is used. -
body-path The path to a file containing the comment body. Cannot be used in conjunction with body. yes, unless body is used. -
edit-mode The mode when updating a comment, replace or append. false append
append-separator The separator to use when appending to an existing comment. (newline, space, none). false newline
reactions A comma separated list of reactions to add to the comment (+1, -1, laugh, confused, heart, hooray, rocket, eyes). false -
reactions-edit-mode The mode when updating comment reactions, replace or append. false append

Dev notes

For notes aimed at developers working on this repo or just trying to understand it go here.