Giter Site home page Giter Site logo

comment-pr's Introduction

Add comments to a PR with Github Actions

A simple action that allows you to add comments to the PR in your workflow.

You can do multiple comments during the workflow execution via different identifiers. See example bellow.

image

Inputs

Name Description Required Default
message Message that you want in the comment (markdown supported) message or file
file Filename of the message (file needs to be placed in .github/workflows/) message or file
single_comment Would you like to update the existing comment (if exists) instead of creating a new one every time? no true
identifier Identifier that we put a comment in the comment so that we can identify them no GITHUB_ACTION_COMMENT_PR
github_token GitHub token that we use to create/update commit no process.env.GITHUB_TOKEN

It's required to provide message or file input. If both are provided message input will be used.

Output

Name Description Return
commented Reports status on comment creation 'true' / 'false'

Usage

Simple comment

uses: NejcZdovc/comment-pr@v2
with:
  message: "Hello world"
env:
  GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

Simple comment via file

uses: NejcZdovc/comment-pr@v2
with:
  file: "comment.md"
env:
  GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

The file should be placed in .github/workflows and it should be .md.

Passing data in md file

uses: NejcZdovc/comment-pr@v2
with:
  file: "comment.md"
env:
  GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
  DATA: 'year 2020'

When you need to pass data from the workflow info file you just define a new env variable. That will be automatically replaced in the template.

Example of comment.md that uses DATA env variable.

It's almost the end of {DATA}!

Multiple comments

By specifying different identifier per step we will now track two different comments, and they will be updated accordingly.

steps:
  - name: Checkout
    uses: actions/checkout@v3
  - name: Comment Checkout
    uses: NejcZdovc/comment-pr@v2
    with:
      message: "Checkout completed!"
      identifier: "GITHUB_COMMENT_CHECKOUT"
    env:
      GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
  - name: Get time
    uses: actions/github-script@v6
    id: get-time
    with:
        script: return new Date().toString()
        result-encoding: string
  - name: Comment time
    uses: NejcZdovc/comment-pr@v2
    with:
      message: "Execution time: `${{steps.get-time.outputs.result}}`"
      identifier: "GITHUB_COMMENT_SCRIPT"
    env:
      GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

In action

Checkout workflow in action in this repo, follow this link.

GitHub token

You can pass GitHub token two ways:

Via input

uses: NejcZdovc/comment-pr@v2
with:
  message: "Hello world"
  github_token: ${{secrets.GITHUB_TOKEN}}

Via environment variable

uses: NejcZdovc/comment-pr@v2
with:
  message: "Hello world"
env:
  GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

Bugs

Please file an issue for bugs, missing documentation, or unexpected behavior.

LICENSE

MIT

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.