Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Create Comment Action

Reusable GitHub Action for posting a comment to a pull request or issue.

The action uses the GitHub REST API directly, so it has no runtime npm dependencies and is suitable for GitHub Enterprise environments.

Usage

name: Comment

on:
  pull_request:
    types: [opened, synchronize]

permissions:
  contents: read
  pull-requests: write
  issues: write

jobs:
  comment:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: your-org/action-create-comment@v1
        with:
          body: |
            Build completed for `${{ github.sha }}`.

Inputs

Input Required Default Description
github-token No ${{ github.token }} Token used to call the GitHub API.
repository No ${{ github.repository }} Repository in owner/name format.
issue-number No Current issue or pull request Issue or pull request number to comment on.
body No Comment body. Required unless body-file is set.
body-file No Path to a file containing the comment body.
marker No Stable text used to find and update an existing comment instead of creating a duplicate.
comment-author No Optional login that must match the existing comment author when marker is used.

Updating an Existing Comment

Set marker to a stable hidden marker and include the same marker in the comment body.

- uses: your-org/action-create-comment@v1
  with:
    marker: '<!-- ci-summary -->'
    body: |
      <!-- ci-summary -->
      CI summary for `${{ github.sha }}`.

When marker is present, the action lists comments for the target issue or PR. If a comment contains the marker, that comment is updated. Otherwise, a new comment is created.

Use comment-author when the marker should only match comments from a specific bot or user.

- uses: your-org/action-create-comment@v1
  with:
    marker: '<!-- ci-summary -->'
    comment-author: github-actions[bot]
    body: |
      <!-- ci-summary -->
      CI summary for `${{ github.sha }}`.

Outputs

Output Description
comment-id ID of the created or updated comment.
comment-url Browser URL for the created or updated comment.
operation created or updated.

GitHub Enterprise

The action uses GITHUB_API_URL when present, so it will target the API URL for the GitHub Enterprise Server instance running the workflow.

About

Simple GitHub action to create a comment and attach to a PR or comment, also updates a comment

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors