uses: mshick/add-pr-comment@v2
Find a file
2022-11-07 12:08:03 -08:00
.github/workflows update workflow 2022-11-07 12:08:03 -08:00
__tests__ Add sticky comment feature and ID based reference. (#61) 2022-11-07 09:43:48 -08:00
dist Add sticky comment feature and ID based reference. (#61) 2022-11-07 09:43:48 -08:00
lib Add sticky comment feature and ID based reference. (#61) 2022-11-07 09:43:48 -08:00
src Add sticky comment feature and ID based reference. (#61) 2022-11-07 09:43:48 -08:00
.gitignore build(typescript): refactoring project with typescript and test setup 2020-05-21 13:17:40 -04:00
.node-version project clean up and update 2022-11-04 16:50:39 -04:00
action.yml Add sticky comment feature and ID based reference. (#61) 2022-11-07 09:43:48 -08:00
LICENSE initial commit 2019-11-22 17:12:31 -05:00
package-lock.json use octokit method (#59) 2022-11-05 12:44:20 -04:00
package.json use octokit method (#59) 2022-11-05 12:44:20 -04:00
README.md Add sticky comment feature and ID based reference. (#61) 2022-11-07 09:43:48 -08:00
tsconfig.json build(refactor): better project organization 2020-07-07 10:51:15 -04:00

add-pr-comment

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

Features

  • Fast, runs in the GitHub Actions node.js runtime.
  • Modify issues for PRs merged to main.
  • By default will post "sticky" comments. If on a subsequent run the message text changes the original comment will be updated.
  • Multiple sticky comments allowed by setting unique message-ids.
  • Multiple posts of the same comment optionally allowable.
  • Supports emoji 😂😂😂!
  • Supports a proxy for fork-based PRs. See below.
  • Supports creating a message from a file path.

Usage

Note that write access needs to be granted for the pull-requests scope.

on:
  pull_request:

jobs:
  test:
    runs-on: ubuntu-latest
    permissions:
      pull-requests: write
    steps:
      - uses: mshick/add-pr-comment@v2
        with:
          message: |
            **Hello**
            🌏
            !
          repo-token: ${{ secrets.GITHUB_TOKEN }}
          allow-repeats: false # This is the default
          message-id: 'add-pr-comment' # This is the default

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

on:
  push:
    branches:
      - main

jobs:
  test:
    runs-on: ubuntu-latest
    permissions:
      pull-requests: write
    steps:
      - uses: mshick/add-pr-comment@v2
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          message: |
            **Hello MAIN**

Configuration options

Variable or Argument Location Description Required Default
message with The message you'd like displayed, supports Markdown and all valid Unicode characters. maybe
message-path with Path to a message you'd like displayed. Will be read and displayed just like a normal message. maybe
repo-token with Valid GitHub token, either the temporary token GitHub provides or a personal access token. maybe
message-id with Message id to use when searching existing comments. If found, updates the existing (sticky comment). no
allow-repeats with Boolean flag to allow identical messages to be posted each time this action is run. no false
proxy-url with String for your proxy service URL if you'd like this to work with fork-based PRs. no
GITHUB_TOKEN env 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 precludes adding 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 host to proxy the create comment requests with a personal access token you provide.

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

Check out the proxy service here: https://github.com/mshick/add-pr-comment-proxy

Example

on:
  pull_request:

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