Skip to content

Add a shared pull request comment action - #18

Merged
pauloiankoski merged 4 commits into
mainfrom
feat/pr-comment
Nov 4, 2026
Merged

pauloiankoski merged 4 commits into
mainfrom
feat/pr-comment

Conversation

@pauloiankoski

@pauloiankoski pauloiankoski commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Adds .github/actions/pr-comment, one place for the pull request comment operations other actions need: find, create, update, delete, and "replace the comment that starts with this marker, or create it".

Why

Third-party comment actions on floating tags can change under us, and they hold a token that can write. This calls the GitHub API through actions/github-script, which every action here already uses. It is tested with the real Octokit and a replaced network, like the other actions.

Use

From a workflow step ($/.github/actions/pr-comment inside this repository), or from another action's script (require('../pr-comment/pr-comment.js')).

- uses: $/.github/actions/pr-comment
  continue-on-error: true
  with:
    marker: '<!-- my-check:example-org/my-plugin -->'
    body-file: comment.md
  • A comment is found by its first line, not by its author.
  • An empty marker is refused, because it would match every comment.
  • An empty body, or one over 65,536 characters, is refused before any request.
  • A refused write (403) says what to change: grant pull-requests: write, or skip forks.

The README has the inputs, the outputs and the rules.

Next

#14 (Plugin Check) and #15 (Playground preview) will use it, and will be stacked on this branch.

Tests

npm install, then node --test. This also changes the test helper so a rule can answer 204, which a delete does.

Summary by CodeRabbit

  • New Features
    • Added an action to find, create, update, delete, or upsert pull request and issue comments. Comments can be matched using a marker, and the action reports the comment ID, URL, and outcome.
    • Added support for providing comment text directly or from a file. The action rejects blank or oversized comment bodies before making a request.
    • Update and delete operations can target a comment by ID; delete reports when a comment is not found.
  • Documentation
    • Documented the action’s inputs, outputs, behavior, permissions, and error handling, with workflow examples.

@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Adds a composite GitHub Action and JavaScript helper to find, create, update, and delete issue or pull-request comments. The action accepts comment and target inputs, sets result outputs, and includes documentation and tests for operations, validation, and API responses.

Changes: PR comment action

Layer / File(s) Summary
Action interface and usage
.github/actions/pr-comment/action.yml, .github/actions/pr-comment/README.md
Defines action inputs, outputs, defaults, and script invocation. Documents operation behavior, input limits, permissions, and usage.
Comment operations and dispatch
.github/actions/pr-comment/pr-comment.js
Implements marker and body validation, paginated comment lookup, comment operations, dispatch, output setting, and write-side 403 handling.
Operation and API validation
tests/actions/pr-comment/pr-comment.test.js, tests/support/actions.js, tests/support/actions.test.js
Adds tests for validation, comment operations, action outputs, and API responses. Updates the response helper to use a bodyless response for statuses 204 and 304.

Estimated code review effort: 3 (Moderate) | ~30 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant CompositeAction
  participant GithubScript as actions/github-script
  participant CommentHelper as pr-comment.js
  participant GitHubAPI as GitHub comments API
  CompositeAction->>GithubScript: Pass inputs and token
  GithubScript->>CommentHelper: Call run with github, core, and environment
  CommentHelper->>GitHubAPI: Find, create, update, or delete comment
  GitHubAPI-->>CommentHelper: Return comment data or API result
  CommentHelper-->>GithubScript: Set result and comment outputs
Loading

Possibly related PRs

  • stellarwp/plugin-toolbox#15: Adds marker-based upsert behavior for a Playground preview comment. The PR is identified as a planned user of this action.
  • stellarwp/plugin-toolbox#14: Adds marker-based comment creation and updates for Plugin Check. The PR is identified as a planned user of this action.

Suggested labels: enhancement

Suggested reviewers: d4mation, estevao90

Merge Risk: Minimal · up to 6a9f6

No actionable issue remains from this review; the action is ready to merge after normal checks.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: adding a shared pull request comment action.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 15 functions across 4 files. (1 skipped: 1 unsupported.)

Finishing Touches
Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: e4fc56d3-548e-45ed-84d9-38bbcec95ed6
Commits

Reviewing files that changed from the base of the PR and between 1ff9128 and 6a9f678.

Files selected for processing: 1
  • .github/actions/pr-comment/README.md
Files skipped from review as they are similar to previous changes: 1
  • .github/actions/pr-comment/README.md

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

@coderabbitai coderabbitai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Fix comments: Fix CodeRabbit comments on this PR

Comment thread .github/actions/pr-comment/action.yml Resolved
Comment thread .github/actions/pr-comment/README.md Outdated
| `operation` | `upsert` | `upsert`, `create`, `update`, `delete` or `find` |
| `marker` | empty | Hidden first line that finds the comment. Needed for `upsert` and `find`. For `update` and `delete` it finds the comment when there is no `comment-id` |
| `body` | empty | The comment text. Give `body` or `body-file`, not both |
| `body-file` | empty | Path of a file that holds the comment text. Prefer it for long text |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took me some investigation to realize why we need this.

It is to avoid this on a caller, which is gross. I was hoping that we could expect callers to just cat the file directly into body but it would require a whole setup before it which is very inconvenient when they may have a boilerplate comment that gets added to every PR or similar.

- id: text
  run: |
    {
      echo 'body<<EOF'
      cat result.md
      echo 'EOF'
    } >> "$GITHUB_OUTPUT"
- uses: ./.github/actions/pr-comment
  with:
    body: ${{ steps.text.outputs.body }}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. The README now has a "Body from a file" section that shows the extra step callers would need without it (6a9f678).

@pauloiankoski
pauloiankoski merged commit e258044 into main Nov 4, 2026
2 checks passed
@pauloiankoski
pauloiankoski deleted the feat/pr-comment branch November 4, 2026 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants