Skip to content

Commit 43e433d

Browse files
authored
Add opt-in inline PR review comments to Opengrep action (#20)
Post SAST findings as inline review comments on PRs when pr-comments: 'true' is set (requires pull-requests: write). Uses gh CLI for API calls with automatic pagination and auth. Deduplicates across runs via fingerprint markers in HTML comments. Falls back to a plain PR comment (with update-in-place dedup) when inline review fails.
1 parent cf07a87 commit 43e433d

6 files changed

Lines changed: 372 additions & 1 deletion

File tree

sast/opengrep/README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Differential SAST with [Opengrep](https://opengrep.dev) for pull requests. Scans
66

77
```yaml
88
steps:
9-
- uses: actions/checkout@v4
9+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
1010
- uses: temporalio/public-actions/sast/opengrep@main
1111
```
1212
@@ -19,6 +19,7 @@ That's it. On `pull_request` and `merge_group` events, `baseline-sha` is automat
1919
| `version` | `v1.21.0` | Opengrep version to install |
2020
| `baseline-sha` | Auto-detected | Base SHA for differential scanning. Override to compare against a specific commit. |
2121
| `config` | _(empty)_ | Additional rule config (path or URL). Built-in rules always run. |
22+
| `pr-comments` | `false` | Post findings as inline PR review comments (opt-in, see below). |
2223

2324
## Outputs
2425

@@ -45,6 +46,28 @@ The action writes a GitHub job summary with:
4546

4647
New findings also appear as `::error::` annotations inline on the PR diff.
4748

49+
## PR review comments
50+
51+
Set `pr-comments: 'true'` to post findings as inline review comments directly on the PR diff, similar to Semgrep's managed scans. This requires `pull-requests: write` permission:
52+
53+
```yaml
54+
permissions:
55+
contents: read
56+
pull-requests: write
57+
58+
steps:
59+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
60+
- uses: temporalio/public-actions/sast/opengrep@main
61+
with:
62+
pr-comments: 'true'
63+
```
64+
65+
Comments are deduplicated across runs using the finding fingerprint — re-running the action on the same PR won't create duplicate comments. Each comment includes suppression guidance. Multi-line findings highlight the full matched range in the diff.
66+
67+
When a finding is fixed, the action strikes through the original comment and attempts to resolve the review thread. Thread resolution requires a GitHub App token or PAT — the default `GITHUB_TOKEN` can update the comment body but cannot resolve threads via GraphQL (`Resource not accessible by integration`).
68+
69+
When a finding's line isn't part of the diff (edge case), the action falls back to a single PR comment with a table of findings and clickable links. This fallback comment is updated in-place on subsequent runs to avoid notification noise.
70+
4871
## Built-in rules
4972

5073
| Rule | Languages | What it detects |

sast/opengrep/action.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ inputs:
2020
Built-in Temporal rules always run.
2121
required: false
2222
default: ''
23+
pr-comments:
24+
description: >-
25+
Post findings as inline PR review comments (requires
26+
pull-requests: write permission). Only applies on pull_request events.
27+
required: false
28+
default: 'false'
2329

2430
outputs:
2531
new-count:
@@ -190,6 +196,11 @@ runs:
190196
- name: Report
191197
id: report
192198
shell: bash
199+
env:
200+
GITHUB_TOKEN: ${{ github.token }}
201+
PR_NUMBER: ${{ github.event.pull_request.number }}
202+
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
203+
PR_COMMENTS_ENABLED: ${{ inputs.pr-comments }}
193204
run: |
194205
# Ensure files exist even if prior steps were skipped.
195206
touch "${RUNNER_TEMP}/new-findings.json"

sast/opengrep/rules/deprecated-actions.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ rules:
2020
fix: |
2121
uses: actions/create-github-app-token@v2
2222
metadata:
23+
source: sast/opengrep/rules/deprecated-actions.yml
2324
category: security
2425
references:
2526
- https://github.com/tibdex/github-app-token

sast/opengrep/rules/gha-permissions.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ rules:
88
Add a `permissions:` block at the workflow root (applies to all jobs) or
99
per job with least privilege (e.g., `contents: read` and only specific
1010
writes like `pull-requests: write` if needed).
11+
metadata:
12+
source: sast/opengrep/rules/gha-permissions.yml
1113
patterns:
1214
- pattern-inside: |
1315
jobs:

sast/opengrep/rules/go-zipslip.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ rules:
1313
languages:
1414
- go
1515
metadata:
16+
source: sast/opengrep/rules/go-zipslip.yml
1617
cwe:
1718
- "CWE-22: Improper Limitation of a Pathname to a Restricted Directory
1819
('Path Traversal')"

0 commit comments

Comments
 (0)