uses: mshick/add-pr-comment@v2
Find a file
2020-07-06 21:47:29 -04:00
.github/workflows feat: do not test user.login by default (#15) 2020-05-28 11:43:27 -04:00
__tests__ Create a comment in exist PR (#17) 2020-07-06 11:48:01 -04:00
dist build(package): compile latest 2020-07-06 12:04:10 -04:00
docs docs: triggering changes, adding samples 2020-04-08 17:16:12 -07:00
.editorconfig build(typescript): refactoring project with typescript and test setup 2020-05-21 13:17:40 -04:00
.eslintignore ci: adding simple workflow 2020-05-21 17:30:21 -04:00
.eslintrc.json feat: do not test user.login by default (#15) 2020-05-28 11:43:27 -04:00
.gitignore build(typescript): refactoring project with typescript and test setup 2020-05-21 13:17:40 -04:00
.prettierrc.json build(typescript): refactoring project with typescript and test setup 2020-05-21 13:17:40 -04:00
action.yml feat: adding support for a proxy 2020-07-06 21:47:29 -04:00
add-pr-comment.ts feat: adding support for a proxy 2020-07-06 21:47:29 -04:00
jest.config.js build(typescript): refactoring project with typescript and test setup 2020-05-21 13:17:40 -04:00
LICENSE initial commit 2019-11-22 17:12:31 -05:00
package-lock.json build(deps): updating all deps to latest and assoc code updates 2020-07-06 12:03:13 -04:00
package.json build(deps): updating all deps to latest and assoc code updates 2020-07-06 12:03:13 -04:00
README.md feat: adding support for a proxy 2020-07-06 21:47:29 -04:00
tsconfig.json Create a comment in exist PR (#17) 2020-07-06 11:48:01 -04:00

add-pr-comment

A GitHub Action which adds a comment to a pull request's issue.

Limitations

Due to how GitHub handles permissions in PRs coming from forks you will need to deploy an app if you want to post comments in those situations. See below.

Usage

on:
  pull_request:

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: mshick/add-pr-comment@v1
        with:
          message: |
            **Hello**
            🌏
            !
          repo-token: ${{ secrets.GITHUB_TOKEN }}
          repo-token-user-login: 'github-actions[bot]' # The user.login for temporary GitHub tokens
          allow-repeats: false # This is the default

You can even use it on PR Issues that are related to PRs that were merged into master, for example:

on:
  push:
    branches:
      - master

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: mshick/add-pr-comment@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          message: |
            **Hello MASTER**
          allow-repeats: true

Configuration options

Variable or Argument Location Description Required Default
message with The message you'd like displayed, supports Markdown and all valid Unicode characters yes
repo-token with A valid GitHub token, either the temporary token GitHub provides or a personal access token maybe
repo-token-user-login with Define this to save on comment processing time when checking for repeats. GitHub's default token uses github-actions[bot] no
allow-repeats with A boolean flag to allow identical messages to be posted each time this action is run no false
GITHUB_TOKEN env A valid GitHub token, can alternatively be defined in the env maybe

Proxy for Fork-based PRs

GitHub limits GITHUB_TOKEN and other API access token permissions when creating a PR from a fork. This makes it impossible to add comments when your PRs are coming from forks, which is the norm for open source projects. To work around this situation I've created a simple companion app you can deploy to Cloud Run or another environment to proxy the create comment requests and escalate the token privileges.

See this issue: https://github.community/t/github-actions-are-severely-limited-on-prs/18179/4 for more detail.

Example

on:
  pull_request:

jobs:
  pr:
    runs-on: ubuntu-latest
    steps:
      - uses: mshick/add-pr-comment@v1
        with:
          message: |
            **Howdie!**
          proxy-url: https://add-pr-comment-proxy-94idvmwyie-uc.a.run.app/
          proxy-secret: foobar
          repo-token: ${{ secrets.GITHUB_TOKEN }}

Features

  • Fast, runs in the GitHub Actions node.js runtime; no Docker pull needed.
  • Modify issues for PRs merged to master.
  • Multiple posts of the same comment optionally allowable.
  • Supports emoji 😂😂😂!

Use Case

  • Adding a deployed app URL to a PR issue
  • Printing some sort of output to the PR issue for human-readability