• Stars
    star
    431
  • Rank 100,866 (Top 2 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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@v3
        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@v3
        with:
          comment-id: 557858210
          body: |
            **Edit:** Some additional info
          reactions: eyes

Add comment reactions

      - name: Add reactions
        uses: peter-evans/create-or-update-comment@v3
        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@v3
        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@v3
        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@v2
      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@v3
      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@v2
      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@v3
      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@v3
      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@v3
        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@v3
        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

More Repositories

1

create-pull-request

A GitHub action to create a pull request for changes to your repository in the actions workspace
TypeScript
1,480
star
2

repository-dispatch

A GitHub action to create a repository dispatch event
TypeScript
721
star
3

docker-compose-healthcheck

How to wait for container X before starting Y using docker-compose healthcheck
623
star
4

slash-command-dispatch

A GitHub action that facilitates "ChatOps" by creating repository dispatch events for slash commands
TypeScript
475
star
5

swagger-github-pages

How to host Swagger API documentation with GitHub Pages
HTML
289
star
6

dockerhub-description

A GitHub action to update a Docker Hub repository description from README.md
TypeScript
258
star
7

docker-compose-actions-workflow

GitHub Actions workflow example using Docker Compose to build and test a multi-container stack
Python
248
star
8

find-comment

A GitHub action to find an issue or pull request comment
TypeScript
108
star
9

create-issue-from-file

A GitHub action to create an issue using content from a file
TypeScript
103
star
10

lightweight-architecture-decision-records

Lightweight Architecture Decision Records
89
star
11

commit-comment

A GitHub action to create a comment for a commit on GitHub
JavaScript
86
star
12

autopep8

A GitHub action for autopep8, a tool that automatically formats Python code to conform to the PEP 8 style guide.
Python
76
star
13

enable-pull-request-automerge

A GitHub action to enable auto-merge on a pull request
72
star
14

nominatim-k8s

Nominatim for Kubernetes on Google Container Engine (GKE).
Shell
60
star
15

s3-backup

A GitHub action to mirror a repository to S3 compatible object storage
Shell
56
star
16

create-or-update-project-card

A GitHub action to create or update a project card
TypeScript
54
star
17

link-checker

A GitHub action for link checking repository Markdown and HTML files
Shell
48
star
18

rebase

A GitHub action to rebase pull requests in a repository
TypeScript
38
star
19

smoke-testing

Smoke testing Docker containers with CircleCI
Kotlin
35
star
20

osrm-backend-k8s

Open Source Routing Machine (OSRM) osrm-backend for Kubernetes on Google Container Engine (GKE).
Shell
35
star
21

sendgrid-action

A GitHub Action to send email with SendGrid
Dockerfile
26
star
22

close-issue

A GitHub action to close an issue
23
star
23

locust-docker

Docker image for the Locust load testing tool and sample Kubernetes configuration files for distributed deployment.
Shell
19
star
24

vegeta-docker

Docker image for the Vegeta HTTP load testing tool
Dockerfile
18
star
25

kotlin-jib

Containerising Kotlin with Jib
Kotlin
17
star
26

kdef

Declarative resource management for Kafka
Go
17
star
27

close-pull

A GitHub action to close a pull request and optionally delete its branch.
16
star
28

osrm-backend-docker

Docker image for the Open Source Routing Machine (OSRM) osrm-backend
Dockerfile
14
star
29

kong-oauth2-consent-app

A consent application for OAuth 2.0 Authorization Code Grant flow with Kong
Go
13
star
30

rust-wasm-action

Rust-generated WebAssembly GitHub action template
Rust
12
star
31

paseto-lua

PASETO (Platform-Agnostic Security Tokens) for Lua
Lua
11
star
32

postman-pre-request

Postman Pre-request script for HMAC Authentication with Kong
JavaScript
11
star
33

mutation-testing

Mutation Testing – featuring an example using Stryker, a framework for the JavaScript ecosystem
JavaScript
10
star
34

slash-command-dispatch-processor

A command processor for slash-command-dispatch, a GitHub action that facilitates "ChatOps"
8
star
35

close-fork-pulls

A GitHub action to close pull requests from forks
TypeScript
6
star
36

duplicati-action

A GitHub action for Duplicati - Store securely encrypted backups in the cloud!
Dockerfile
5
star
37

gradle-auto-dependency-updates

How to automate Gradle dependency updates with GitHub Actions
Kotlin
5
star
38

erc20-token-wallet

A simple Ethereum blockchain ERC20 token wallet interface
JavaScript
5
star
39

patience

Go implementation of the Patience Diff algorithm
Go
4
star
40

kong-plugin-paseto

Kong plugin for PASETO (Platform-Agnostic Security Tokens)
Lua
4
star
41

python-action

A template to bootstrap the creation of a multi-platform Python GitHub action
JavaScript
4
star
42

blog

The blog of Peter Evans
CSS
3
star
43

create-pull-request-tests

Tests for create-pull-request action
3
star
44

gaps-and-islands

Gaps and islands: Merging contiguous ranges
1
star
45

soft-thresholding

Candidate selection using an iterative soft-thresholding algorithm
Python
1
star
46

create-pull-request-tests-remote

Remote repository for create-pull-request action tests
1
star
47

kong-hmac-python

Python module for HMAC Authentication with Kong
Python
1
star
48

curl-jq-docker

An alpine based Docker image with curl and jq
Dockerfile
1
star
49

kubernetes-travis-template

A template project for Kubernetes services development and integration testing
Shell
1
star