Skip to content

Create and update PR comment. Comment can contain sections.

License

Notifications You must be signed in to change notification settings

jupier/powerful-pr-comment

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

Powerful pull request comment

GitHub Super-Linter CI Check dist/ CodeQL Coverage

Summary

Powerful Pull Request Comment is a GitHub Action that allows you to easily create/update pull request comments. It provides useful features such as:

  • creating sticky comments: a comment that is created only the first time and then then updated for the next runs
  • creating comments with updatable sections
  • ... more to come (appending content instead of replacing, deleting a comment...)

Usage

Prerequisites

You need to add this permission

permissions:
  pull-requests: write

Create and update a pr comment

- uses: jupier/[email protected]
  id: comment-created
  with:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    body: |
      # The content of this comment will be overwritten

# ...

- uses: jupier/[email protected]
  with:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    commentId: ${{steps.test-action.outputs.commentId}}
    body: |
      # Hello world
      **Text in bold**

Create/update a sticky comment

- uses: jupier/[email protected]
  with:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    sticky: true
    body: |
      # This comment is sticky
      This means it's created the first time 
      and then updated for the subsequent runs.

Create and update a comment with sections

- uses: jupier/[email protected]
  with:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    sticky: true
    body: |
      I'm a comment containing multiple sections.
      Each section can be updated separately.
      # First section
      <!-- POWERFUL PR SECTION START: firstSection -->
      This content will be updated...
      <!-- POWERFUL PR SECTION END: firstSection -->
      # Second section
      <!-- POWERFUL PR SECTION START: secondSection -->
      This content can be updated...
      <!-- POWERFUL PR SECTION END: secondSection -->

# ...

- uses: jupier/[email protected]
  with:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    section: firstSection
    sticky: true
    body: |
      The content of the first section has been updated
      **Well done 🤗**

Other examples

Find more examples in our CI workflow

Setup

Action created using typescript-action.

After you've cloned the repository to your local machine or codespace, you'll need to perform some initial setup steps before you can develop your action.

Note

You'll need to have a reasonably modern version of Node.js handy (20.x or later should work!). If you are using a version manager like nodenv or nvm, this template has a .node-version file at the root of the repository that will be used to automatically switch to the correct version when you cd into the repository. Additionally, this .node-version file is used by GitHub Actions in any actions/setup-node actions.

  1. 🛠️ Install the dependencies

    npm install
  2. 🏗️ Package the TypeScript for distribution

    npm run bundle
  3. ✅ Run the tests

    $ npm test
    
    PASS  ./index.test.js
      ✓ throws invalid number (3ms)
      ✓ wait 500 ms (504ms)
      ✓ test runs (95ms)
    
    ...

Publishing a New Release

This project includes a helper script, script/release designed to streamline the process of tagging and pushing new releases for GitHub Actions.

GitHub Actions allows users to select a specific version of the action to use, based on release tags. This script simplifies this process by performing the following steps:

  1. Retrieving the latest release tag: The script starts by fetching the most recent release tag by looking at the local data available in your repository.
  2. Prompting for a new release tag: The user is then prompted to enter a new release tag. To assist with this, the script displays the latest release tag and provides a regular expression to validate the format of the new tag.
  3. Tagging the new release: Once a valid new tag is entered, the script tags the new release.
  4. Pushing the new tag to the remote: Finally, the script pushes the new tag to the remote repository. From here, you will need to create a new release in GitHub and users can easily reference the new tag in their workflows.