Giter VIP home page Giter VIP logo

create-or-update-comment's Introduction

Create or Update Comment

CI GitHub Marketplace

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

This action was created to help facilitate a GitHub Actions "ChatOps" solution in conjunction with slash-command-dispatch action.

Usage

Add a comment to an issue or pull request

      - name: Create comment
        uses: peter-evans/create-or-update-comment@v1
        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@v1
        with:
          comment-id: 557858210
          body: |
            **Edit:** Some additional info
          reactions: eyes

Add comment reactions

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

Action inputs

Name Description Default
token GITHUB_TOKEN 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.
edit-mode The mode when updating a comment, replace or append. append
reactions A comma separated list of reactions to add to the comment. (+1, -1, laugh, confused, heart, hooray, rocket, eyes)

Note: In public repositories this action does not work in pull_request workflows when triggered by forks. 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@v1
        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@v1
        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. In this case, the comment will be updated instead of being created.

    - name: Find Comment
      uses: peter-evans/find-comment@v1
      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 == 0 }}
      uses: peter-evans/create-or-update-comment@v1
      with:
        issue-number: ${{ github.event.pull_request.number }}
        body: |
          This comment was written by a bot!
        reaction-type: "rocket"

    - name: Update comment
      if: ${{ steps.fc.outputs.comment-id != 0 }}
      uses: peter-evans/create-or-update-comment@v1
      with:
        comment-id: ${{ steps.fc.outputs.comment-id }}
        body: |
          This comment has been updated!
        reaction-type: "rocket"

Setting the comment body from a file

This example shows how file content can be read into a variable and passed to the action. The content must be escaped to preserve newlines.

      - id: get-comment-body
        run: |
          body=$(cat comment-body.txt)
          body="${body//'%'/'%25'}"
          body="${body//$'\n'/'%0A'}"
          body="${body//$'\r'/'%0D'}" 
          echo ::set-output name=body::$body

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

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

create-or-update-comment's People

Contributors

actions-bot avatar danielhabenicht avatar dependabot[bot] avatar larshp avatar peter-evans avatar renovate-bot avatar robdodson avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.