npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@dr3/create-or-update-comment

v4.0.0

Published

Create or update an issue or pull request comment

Downloads

3

Readme

Create or Update Comment

CI GitHub Marketplace

A GitHub action to create or update an issue or pull request comment.

Usage

Add a comment to an issue or pull request

      - name: Create comment
        uses: peter-evans/create-or-update-comment@v4
        with:
          issue-number: 1
          body: |
            This is a multi-line test comment
            - With GitHub **Markdown** :sparkles:
            - Created by [create-or-update-comment][1]

            [1]: https://github.com/peter-evans/create-or-update-comment
          reactions: '+1'

Update a comment

      - name: Update comment
        uses: peter-evans/create-or-update-comment@v4
        with:
          comment-id: 557858210
          body: |
            **Edit:** Some additional info
          reactions: eyes

Add comment reactions

      - name: Add reactions
        uses: peter-evans/create-or-update-comment@v4
        with:
          comment-id: 557858210
          reactions: |
            heart
            hooray
            laugh

Action inputs

| Name | Description | Default | | --- | --- | --- | | token | GITHUB_TOKEN (issues: write, pull-requests: write) or a repo scoped PAT. | GITHUB_TOKEN | | repository | The full name of the repository in which to create or update a comment. | Current repository | | issue-number | The number of the issue or pull request in which to create a comment. | | | comment-id | The id of the comment to update. | | | body | The comment body. Cannot be used in conjunction with body-path. | | | body-path | The path to a file containing the comment body. Cannot be used in conjunction with body. | | | edit-mode | The mode when updating a comment, replace or append. | append | | append-separator | The separator to use when appending to an existing comment. (newline, space, none) | newline | | reactions | A comma or newline separated list of reactions to add to the comment. (+1, -1, laugh, confused, heart, hooray, rocket, eyes) | | | reactions-edit-mode | The mode when updating comment reactions, replace or append. | append |

Note: In public repositories this action does not work in pull_request workflows when triggered by forks. Any attempt will be met with the error, Resource not accessible by integration. This is due to token restrictions put in place by GitHub Actions. Private repositories can be configured to enable workflows from forks to run without restriction. See here for further explanation. Alternatively, use the pull_request_target event to comment on pull requests.

Outputs

The ID of the created comment will be output for use in later steps. Note that in order to read the step output the action step must have an id.

      - name: Create comment
        uses: peter-evans/create-or-update-comment@v4
        id: couc
        with:
          issue-number: 1
          body: |
            My comment
      - name: Check outputs
        run: |
          echo "Comment ID - ${{ steps.couc.outputs.comment-id }}"

Where to find the id of a comment

How to find the id of a comment will depend a lot on the use case. Here is one example where the id can be found in the github context during an issue_comment event.

on:
  issue_comment:
    types: [created]
jobs:
  commentCreated:
    runs-on: ubuntu-latest
    steps:
      - name: Add reaction
        uses: peter-evans/create-or-update-comment@v4
        with:
          comment-id: ${{ github.event.comment.id }}
          reactions: eyes

Some use cases might find the find-comment action useful. This will search an issue or pull request for the first comment containing a specified string, and/or by a specified author. See the repository for detailed usage.

In the following example, find-comment is used to determine if a comment has already been created on a pull request. If the find-comment action output comment-id returns an empty string, a new comment will be created. If it returns a value, the comment already exists and the content is replaced.

    - name: Find Comment
      uses: peter-evans/find-comment@v3
      id: fc
      with:
        issue-number: ${{ github.event.pull_request.number }}
        comment-author: 'github-actions[bot]'
        body-includes: Build output

    - name: Create or update comment
      uses: peter-evans/create-or-update-comment@v4
      with:
        comment-id: ${{ steps.fc.outputs.comment-id }}
        issue-number: ${{ github.event.pull_request.number }}
        body: |
          Build output
          ${{ steps.build.outputs.build-log }}
        edit-mode: replace

If required, the create and update steps can be separated for greater control.

    - name: Find Comment
      uses: peter-evans/find-comment@v3
      id: fc
      with:
        issue-number: ${{ github.event.pull_request.number }}
        comment-author: 'github-actions[bot]'
        body-includes: This comment was written by a bot!

    - name: Create comment
      if: steps.fc.outputs.comment-id == ''
      uses: peter-evans/create-or-update-comment@v4
      with:
        issue-number: ${{ github.event.pull_request.number }}
        body: |
          This comment was written by a bot!
        reactions: rocket

    - name: Update comment
      if: steps.fc.outputs.comment-id != ''
      uses: peter-evans/create-or-update-comment@v4
      with:
        comment-id: ${{ steps.fc.outputs.comment-id }}
        body: |
          This comment has been updated!
        reactions: hooray

Setting the comment body from a file

      - name: Create comment
        uses: peter-evans/create-or-update-comment@v4
        with:
          issue-number: 1
          body-path: 'comment-body.md'

Using a markdown template

In this example, a markdown template file is added to the repository at .github/comment-template.md with the following content.

This is a test comment template
Render template variables such as {{ .foo }} and {{ .bar }}.

The template is rendered using the render-template action and the result is used to create the comment.

      - name: Render template
        id: template
        uses: chuhlomin/[email protected]
        with:
          template: .github/comment-template.md
          vars: |
            foo: this
            bar: that

      - name: Create comment
        uses: peter-evans/create-or-update-comment@v4
        with:
          issue-number: 1
          body: ${{ steps.template.outputs.result }}

Accessing issues and comments in other repositories

You can create and update comments in another repository by using a PAT instead of GITHUB_TOKEN. The user associated with the PAT must have write access to the repository.

License

MIT