Skip to content

Commit 2b751e9

Browse files
authored
Merge pull request #68 from kacper-mikolajczak/slice2
Add postCodeReviewResults.sh to claude-review-toolkit
2 parents 2108efd + 416438a commit 2b751e9

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

.github/actions/claude-review-toolkit/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Caller repos must ship a `.claude/skills/coding-standards/rules/` directory with
4444
| `addPrReaction.sh` | `<PR_NUMBER> <REACTION>` | Adds a reaction (`+1`, `-1`, `laugh`, `confused`, `heart`, `hooray`, `rocket`, `eyes`) to the PR. |
4545
| `removePrReaction.sh` | `<PR_NUMBER> <REACTION> <USER>` | Removes the matching reaction authored by `<USER>` (typically `github-actions[bot]`). Idempotent. |
4646
| `createInlineComment.sh` | `<PR_NUMBER> <path> <body> <line>` | Posts an inline review comment. Requires `GITHUB_REPOSITORY`, `GH_TOKEN`, and `ALLOWED_RULES_FILE` in env. The body must reference a rule tag matching `[A-Z]+(-[A-Z]+)*-[0-9]+` (e.g. `PERF-1`) that is present in the allowlist; otherwise the comment is rejected. |
47+
| `postCodeReviewResults.sh` | `<PR_NUMBER>` | Posts the result of a Claude code review. With no violations, adds a `+1` reaction to the PR; with violations, posts one inline comment per violation. Reads the JSON output from env `STRUCTURED_OUTPUT`. Requires `GH_TOKEN`, `GITHUB_REPOSITORY`, `ALLOWED_RULES_FILE`, and `STRUCTURED_OUTPUT` in env. Individual comment failures are swallowed so one rejected comment does not kill the loop. |
4748
| `extractAllowedRules.sh` | `<rules-dir> <output-file>` | Walks `<rules-dir>` for `.md` rule files and writes their `ruleId:` tags to `<output-file>`. Invoked automatically by the action; rarely called directly. |
4849

4950
## Schema extension
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
# Post the result of a Claude code review.
4+
# With no violations: adds a "+1" reaction to the PR.
5+
# With violations: posts one inline comment per violation parsed from $STRUCTURED_OUTPUT.
6+
# Usage: postCodeReviewResults.sh <PR_NUMBER>
7+
# Env: STRUCTURED_OUTPUT (JSON from claude-code-action), GH_TOKEN, GITHUB_REPOSITORY, ALLOWED_RULES_FILE
8+
set -eu
9+
10+
if [[ $# -lt 1 ]]; then
11+
echo "Usage: $0 <PR_NUMBER>" >&2
12+
exit 1
13+
fi
14+
15+
if ! [[ "$1" =~ ^[0-9]+$ ]]; then
16+
echo "Error: PR_NUMBER must be a positive integer" >&2
17+
exit 1
18+
fi
19+
20+
if [[ -z "${STRUCTURED_OUTPUT:-}" ]]; then
21+
echo "::error::Claude Code Action returned empty structured output" >&2
22+
exit 1
23+
fi
24+
25+
readonly PR_NUMBER="$1"
26+
27+
COUNT=$(echo "$STRUCTURED_OUTPUT" | jq '.violations | length')
28+
readonly COUNT
29+
30+
if [[ "$COUNT" -eq 0 ]]; then
31+
addPrReaction.sh "$PR_NUMBER" "+1"
32+
else
33+
echo "$STRUCTURED_OUTPUT" | jq -c '.violations[]' | while IFS= read -r violation; do
34+
PATH_ARG=$(echo "$violation" | jq -r '.path')
35+
BODY_ARG=$(echo "$violation" | jq -r '.body')
36+
LINE_ARG=$(echo "$violation" | jq -r '.line')
37+
createInlineComment.sh "$PR_NUMBER" "$PATH_ARG" "$BODY_ARG" "$LINE_ARG" || true
38+
done
39+
fi

0 commit comments

Comments
 (0)