-
Notifications
You must be signed in to change notification settings - Fork 4
Add shared scripts to skip AI reviews already completed for a commit #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
neil-marcellini
wants to merge
6
commits into
main
Choose a base branch
from
neil-skip-ai-review-same-commit
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+119
−0
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
798cfb2
Add shared scripts to skip AI reviews already completed for a commit
neil-marcellini c94bc3b
Document what the review context argument is for
neil-marcellini 096f415
Name the marker status ai-review-completed so it is not read as a rev…
neil-marcellini f80a5ac
Explain use of shouldSkipReview script
neil-marcellini 1a4fa52
Scope the review marker to the PR and paginate the status lookup
neil-marcellini dde402f
Never skip a review requested by comment
neil-marcellini File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
.github/actions/claude-review-toolkit/scripts/recordReviewComplete.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Record that an AI review completed for a specific commit by setting a commit status. | ||
| # A later "ready for review" event reads this status and skips the duplicate review. | ||
| # Usage: recordReviewComplete.sh <HEAD_SHA> <CONTEXT> [DESCRIPTION] | ||
| # Env: GH_TOKEN, GITHUB_REPOSITORY, GITHUB_SERVER_URL, GITHUB_RUN_ID | ||
| # | ||
| # CONTEXT is the key shouldSkipReview.sh looks for, so pass that step's "context" output rather | ||
| # than rebuilding the string here - it names the reviewer and the PR (e.g. | ||
| # "ai-review-completed/claude/pr-97"), and a mismatch means the review is never recognised as | ||
| # already done. GitHub allows one status per context per commit, so a second status with the same | ||
| # context replaces the first rather than stacking up. It shows up as the status's label in the | ||
| # PR's checks list. | ||
| set -eu | ||
|
|
||
| if [[ $# -lt 2 ]]; then | ||
| echo "Usage: $0 <HEAD_SHA> <CONTEXT> [DESCRIPTION]" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| if ! [[ "$1" =~ ^[0-9a-f]{40}$ ]]; then | ||
| echo "Error: HEAD_SHA must be a full 40-character commit SHA" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| if ! [[ "$2" =~ ^[a-z0-9]([a-z0-9/_-]*[a-z0-9])?$ ]]; then | ||
| echo "Error: CONTEXT must be lowercase alphanumeric with '/', '_' or '-' separators" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| readonly HEAD_SHA="$1" | ||
| readonly CONTEXT="$2" | ||
| # GitHub rejects status descriptions longer than 140 characters. | ||
| readonly DESCRIPTION="${3:-Reviewed at this commit}" | ||
| readonly TRUNCATED_DESCRIPTION="${DESCRIPTION:0:140}" | ||
| readonly REPO="${GITHUB_REPOSITORY}" | ||
| readonly RUN_URL="${GITHUB_SERVER_URL}/${REPO}/actions/runs/${GITHUB_RUN_ID}" | ||
|
|
||
| gh api -X POST "/repos/$REPO/statuses/$HEAD_SHA" \ | ||
| -f state=success \ | ||
| -f context="$CONTEXT" \ | ||
| -f description="$TRUNCATED_DESCRIPTION" \ | ||
| -f target_url="$RUN_URL" |
57 changes: 57 additions & 0 deletions
57
.github/actions/claude-review-toolkit/scripts/shouldSkipReview.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Decide whether an AI review already completed for the PR's current head commit. Useful when a PR author manually requests a review while the PR is still a draft, | ||
| # and then marks it ready for review once the AI review passes. In that case, this skips running the AI review again, since it already completed successfully for the same commit. | ||
| # Writes "head_sha=<sha>", "context=<status context>" and "skip=true|false" to $GITHUB_OUTPUT. | ||
| # Usage: shouldSkipReview.sh <PR_NUMBER> <CONTEXT> | ||
| # Env: GH_TOKEN, GITHUB_REPOSITORY, GITHUB_OUTPUT | ||
| # | ||
| # CONTEXT names the reviewer (e.g. "ai-review-completed/claude", "ai-review-completed/codex"). | ||
| # Commit statuses belong to a repository commit rather than to a PR, and two PRs can share a head | ||
| # SHA - the same branch opened against two different base branches, for example - so the PR number | ||
| # is appended to form the status context this looks for. That full context is written to | ||
| # $GITHUB_OUTPUT as "context" and must be the value recordReviewComplete.sh is given. | ||
| set -eu | ||
|
|
||
| if [[ $# -lt 2 ]]; then | ||
| echo "Usage: $0 <PR_NUMBER> <CONTEXT>" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| if ! [[ "$1" =~ ^[0-9]+$ ]]; then | ||
| echo "Error: PR_NUMBER must be a positive integer" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| if ! [[ "$2" =~ ^[a-z0-9]([a-z0-9/_-]*[a-z0-9])?$ ]]; then | ||
| echo "Error: CONTEXT must be lowercase alphanumeric with '/', '_' or '-' separators" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| readonly PR_NUMBER="$1" | ||
| readonly CONTEXT="$2" | ||
| readonly STATUS_CONTEXT="$CONTEXT/pr-$PR_NUMBER" | ||
| readonly REPO="${GITHUB_REPOSITORY}" | ||
|
|
||
| HEAD_SHA=$(gh api "/repos/$REPO/pulls/$PR_NUMBER" --jq '.head.sha') | ||
| readonly HEAD_SHA | ||
|
|
||
| if [[ -z "$HEAD_SHA" ]]; then | ||
| echo "::error::Could not resolve head SHA for PR #$PR_NUMBER" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # The combined status endpoint returns only the most recent status per context, but it pages at 30 | ||
| # statuses, so --paginate is needed to see a marker on a commit that carries many other statuses. | ||
| STATE=$(gh api --paginate "/repos/$REPO/commits/$HEAD_SHA/status" --jq ".statuses[] | select(.context == \"$STATUS_CONTEXT\") | .state") | ||
| readonly STATE | ||
|
|
||
| echo "head_sha=$HEAD_SHA" >> "$GITHUB_OUTPUT" | ||
| echo "context=$STATUS_CONTEXT" >> "$GITHUB_OUTPUT" | ||
|
|
||
| if [[ "$STATE" == "success" ]]; then | ||
| echo "$STATUS_CONTEXT already completed for $HEAD_SHA, skipping review" >&2 | ||
| echo "skip=true" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "skip=false" >> "$GITHUB_OUTPUT" | ||
| fi |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.