Giter Site home page Giter Site logo

comment-progress's Introduction

Comment Progress

test

GitHub Action to notify progress by commenting on GitHub issues, pull requests, and commits.

Commenting inspired by GitHub bots like netlify, sonarcloud etc.

Used at Hasura to relay progress of long running GitHub Action workflows on pull requests.

Use case

When deploying preview for a pull request, the GitHub workflow starts by commenting

review-app-start

As the job progresses and if there is a failure at some step, the bot appends the updates about failure in the same comment and fails the GitHub workflow.

review-app-fail

If the workflow succeeds, the bot comments the details of the preview environment. (configurable to be a new comment or an update to the previous comment that reported the progress)

review-app-end

Usage

- uses: hasura/[email protected]
  with:
    # The GitHub token to be used when creating/updating comments
    # ${{ secrets.GITHUB_TOKEN }} is provided by default by GitHub actions
    github-token: ${{ secrets.GITHUB_TOKEN }}

    # The repository to which the pull request or issue belongs to
    # ${{ github.repository }} gives the slug of the repository on which the action is running
    repository: "my-org/my-repo"

    # The pull request or issue number on which the comment should be made
    number: ${{ github.event.number }}

    # The commit sha on which the comment should be made
    commit-sha: ${{ github.sha }}

    # Friendly identifier denoting the context of the comment
    # This id is hidden on the comment made and used for referring the same comment afterwards.
    id: deploy-progress

    # Markdown message to be used for commenting
    message: "Thank you for opening this PR :pray:"

    # Comments on the PR/issue and fails the job
    fail: true

    # Appends the message to a comment that already exits with the given id.
    # If a comment with the given id is not found, a new comment is created
    append: true

    # Deletes all the existing comments matching the given id and
    # creates a new comment with the given message
    recreate: true

    # Deletes all the existing comments matching the given id
    delete: true

Note: The number and commit-sha fields are mutually exclusive. Only one of them should be set in a job. If both or none are present, an error will be thrown and the job will fail.

Note: The append and recreate fields are also mutually exclusive. If none of them are set, the job will continue in normal mode but if both are present an error will be thrown and the job will fail.

Scenarios

Make a simple comment on an issue or pull request

Making a simple thank you comment via the github-actions user whenever a pull request is opened.

on:
  pull_request:
    types: [opened]

jobs:
  thank-user:
    runs-on: ubuntu-20.04
    name: Say thanks for the PR
    steps:
      - name: comment on the pull request
        uses: hasura/[email protected]
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          repository: "my-org/my-repo"
          number: ${{ github.event.number }}
          id: thank-you-comment
          message: "Thank you for opening this PR :pray:"

say-thanks

Make a simple comment on a commit

This is very similar to commenting on an issue/PR. Here, instead of providing the number field we provide the commit-sha which is the SHA of the commit that we want to comment on.

on:
  push:
    branches:
      - main

jobs:
  commit-comment:
    runs-on: ubuntu-20.04
    name: Comment on commit with some info
    steps:
      - name: Comment on commit
        uses: hasura/[email protected]
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          repository: "my-org/my-repo"
          commit-sha: ${{ github.sha }}
          id: commit-comment
          message: "This is a commit comment :D."

Make a comment and append updates to the same comment

This makes use of the append flag to add the message to the end of an already existing comment that was made with the same id.

on:
  pull_request:
    types: [opened]

jobs:
  deploy-preview:
    runs-on: ubuntu-20.04
    name: Deploy preview
    steps:
      - name: Notify about starting this deployment
        uses: hasura/[email protected]
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          repository: "my-org/my-repo"
          number: ${{ github.event.number }}
          id: deploy-preview
          message: "Starting deployment of this pull request."

      - name: Deploy preview
        run: |
          echo "deploy preview"
          # long running step

      - name: Notify about the result of this deployment
        uses: hasura/[email protected]
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          repository: "my-org/my-repo"
          number: ${{ github.event.number }}
          id: deploy-preview
          message: "Deployment of a preview for this pull request was successful."
          append: true

Delete older/stale comment and add a new comment

Take a case where you need to re-deploy a preview for your pull request and report the status of the redeployment as a new comment and at the same time delete the old comment containing stale information. recreate flag will help in achieving this scenario.

on:
  workflow_dispatch:
    inputs:
      number:
        description: "pull request number"
        required: true

jobs:
  deploy-preview:
    runs-on: ubuntu-20.04
    name: Deploy preview
    steps:
      - name: Notify about starting this deployment
        uses: hasura/[email protected]
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          repository: "my-org/my-repo"
          number: ${{ github.event.inputs.number }}
          id: deploy-preview
          message: "Starting deployment of this pull request."

      - name: Deploy preview
        run: |
          echo "deploy preview"
          # long running step

      - name: Notify about the result of this deployment
        uses: hasura/[email protected]
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          repository: "my-org/my-repo"
          number: ${{ github.event.inputs.number }}
          id: deploy-preview
          message: "Deployment of a preview for this pull request was successful."
          recreate: true

Delete a comment which is no longer relevant

Take a case where you need to delete a comment which is no longer relevant. E.g., let's say we previously added a comment in a PR with id: preview-url to post a link where the changes of the pull request could be previewed. It might be useful to delete such a comment when the PR is closed to avoid users from accessing stale preview links. We can use the delete flag to achieve this.

on:
  pull_request:
    types: [closed]

jobs:
  cleanup-automated-comments:
    runs-on: ubuntu-20.04
    name: Delete automated PR comments
    steps:
      - name: delete comment that contains a preview link
        uses: hasura/[email protected]
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          repository: "my-org/my-repo"
          number: ${{ github.event.number }}
          id: preview-url

Contributing

Contributions are welcome ๐Ÿ™ Please open an issue before working on something big or breaking.

After making changes to the source code, you will need to perform a packaging step manually by doing the following.

npm install
npm run build

git add .
git commit -m "generates dist for updated code"

comment-progress's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

comment-progress's Issues

Support commit comments

Introduce a new field called commit in the config that expects a Commit SHA and creates a commit comment instead of a pull request or issue comment.

We should make sure to validate if either number or commit field is present before running the action.

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.