Skip to content

Add pr-comment option to post scan results on pull requests#714

Open
David-Uka wants to merge 1 commit into
anchore:mainfrom
David-Uka:feat/pr-comment-162
Open

Add pr-comment option to post scan results on pull requests#714
David-Uka wants to merge 1 commit into
anchore:mainfrom
David-Uka:feat/pr-comment-162

Conversation

@David-Uka

Copy link
Copy Markdown

Resolves #162.

Adds an option to post the Grype scan results as a comment on the pull request that triggered the workflow, as requested in #162. Per the maintainer guidance on that issue, this is built into the main action as an option rather than a separate sub-action.

What it does

  • New pr-comment input (default false) and github-token input.
  • When pr-comment: true on a pull_request event, the action reads the SARIF report it already produces, and posts a summary comment: a per-severity count plus a table of findings (severity, package, version, fix, linked advisory).
  • A hidden marker (<!-- anchore/scan-action pr-comment -->) is used to find and update a single comment across runs, instead of posting a new comment on every push.

Notes

  • Best-effort: any failure to comment is logged as a warning and never fails the scan.
  • No new runtime dependency: comments are created/updated with the built-in fetch against the GitHub REST API.
  • Scan logic unchanged: it reads the existing SARIF output file; it does not alter how grype is invoked. It requires output-format: sarif (the default) and warns + skips otherwise.
  • Requires pull-requests: write permission on the token.

Testing

  • Added tests/pr_comment.test.js covering SARIF parsing, comment rendering (counts/sorting/links/empty), and the create-vs-update / skip paths (mocked API). dist/ rebuilt.

Resolves anchore#162.

Adds a 'pr-comment' input (default false) and a 'github-token' input.
When enabled on a pull_request event, the action parses the Grype SARIF
report and posts a summary comment (per-severity counts plus a collapsible
table of findings) on the triggering PR. A hidden marker is used to update
a single comment across runs instead of posting a new one each time.

Per maintainer guidance on the issue, this is built into the main action as
an option rather than a separate sub-action. Commenting is best-effort: any
failure is logged as a warning and never fails the scan. When output-format
is not sarif, an additional SARIF file is emitted solely to render the
comment, leaving the user's chosen output untouched.

PR comments are created/updated via the GitHub REST API using the built-in
fetch, avoiding a new runtime dependency in the bundled action.

Signed-off-by: UKA David Ikechukwu <155882429+David-Uka@users.noreply.github.com>
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.

Automatic feedback of scan results as PR comment

1 participant