Git Product home page Git Product logo

actions-comment-pull-request's Introduction

Comment Pull Request - GitHub Actions

What is it ?

A GitHub action that comments with a given message the pull request linked to the pushed branch. You can even put dynamic data thanks to Contexts and expression syntax.

Usage

Classic usage

on: pull_request

jobs:
  example_comment_pr:
    runs-on: ubuntu-latest
    name: An example job to comment a PR
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Comment PR
        uses: thollander/actions-comment-pull-request@v1
        with:
          message: |
            Hello world ! :wave:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Setting reactions

You can also set some reactions on your comments through the reactions input. It takes only valid reactions and adds it to the comment you've just created. (See https://docs.github.com/en/rest/reactions#reaction-types)

- name: PR comment with reactions
  uses: thollander/actions-comment-pull-request@v1
  with:
    message: |
      Hello world ! :wave:
    reactions: eyes, rocket
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Specifying which pull request to comment on

You can explicitly input which pull request should be commented on by passing the pr_number input. That is particularly useful for manual workflow for instance (workflow_run).

...
- name: Comment PR
  uses: thollander/actions-comment-pull-request@v1
  with:
    message: |
      Hello world ! :wave:
    pr_number: 123 # This will comment on pull request #123
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Upsert a comment

Editing an existing comment is also possible thanks to the comment_includes input.

It will search through all the comments of the PR and get the first one that has the provided text in it. If the comment body is not found, it will create a new comment.

That is particularly interesting while committing multiple times in a PR and that you just want to have the last execution report printed. It avoids flooding the PR.

...
- name: Comment PR
  uses: thollander/actions-comment-pull-request@v1
  with:
    message: 'Loading ...'
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
...
- name: Edit PR comment
  uses: thollander/actions-comment-pull-request@v1
  with:
    message: 'Content loaded ! (edited)'
    comment_includes: 'Loading'
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Inputs

Action inputs

Name Description Required Default
GITHUB_TOKEN Token that is used to create comments โœ…
message The comment body โœ…
reactions List of reactions for the comment (comma separated). See https://docs.github.com/en/rest/reactions#reaction-types
pr_number The number of the pull request where to create the comment current pull request number (deduced from context)
comment_includes The text that should be used to find comment in case of replacement.

Contributing

Build

The build steps transpiles the src/main.ts to lib/index.js which is used in a NodeJS environment. It is handled by vercel/ncc compiler.

$ npm run build

actions-comment-pull-request's People

Contributors

dependabot[bot] avatar ericcornelissen avatar fehmianac avatar liyishuai avatar moop-moop avatar omermorad avatar thollander avatar tunetheweb avatar vinodsai-a avatar

Stargazers

 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.