Skip to content

Run PR review only for same-repo PRs - #82

Merged
gontzess merged 3 commits into
mainfrom
gontzess/same-repo-pr-review
May 28, 2026
Merged

gontzess merged 3 commits into
mainfrom
gontzess/same-repo-pr-review

Conversation

@gontzess

Copy link
Copy Markdown
Contributor

Why

The PR review workflow needs to restore high-quality source inspection without running secret-backed Claude review on public fork PRs. Same-repo PRs are the intended automatic review scope; fork PRs should skip clearly instead of entering a privileged review path.

What this changes

  • Switches connector and general PR review workflows from pull_request_target to pull_request.
  • Skips fork PRs with an explicit successful message.
  • Checks out the exact PR head SHA for same-repo PRs so Claude can inspect local source.
  • Loads the review action from the workflow commit instead of @main.
  • Pins the Claude action and artifact upload action by SHA.
  • Filters human comment context to owner, member, and collaborator comments.
  • Verifies outdated review threads are bot-authored before resolving them.

Validation

  • yq parsed both PR review workflows and the composite action.
  • Python scripts compiled with py_compile.
  • git diff --check passed.

Comment thread .github/workflows/pr-review.yaml Outdated
github_token: ${{ secrets.GITHUB_TOKEN }}
pr_number: ${{ github.event.pull_request.number }}
review_prompt: ${{ inputs.review_prompt || 'connector' }}
review_prompt: ${{ github.repository == 'ConductorOne/github-workflows' && 'general' || inputs.review_prompt || 'connector' }}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Suggestion: With the if: github.repository != 'ConductorOne/github-workflows' guard removed from both workflows, pr-review.yaml and general-pr-review.yaml will both fire on pull_request events for ConductorOne/github-workflows. Both resolve to the general profile with the same ### General PR Review: summary heading, producing duplicate reviews with separate summary comments. Consider re-adding the guard here or on general-pr-review.yaml so only one runs on this repo.

@github-actions

github-actions Bot commented May 21, 2026 •

Copy link
Copy Markdown

General PR Review: Run PR review only for same-repo PRs

Blocking Issues: 0 | Suggestions: 0 | Threads Resolved: 0
Review mode: full
View review run

Review Summary

This PR switches both review workflows from pull_request_target to pull_request, restricts review to same-repo PRs (fork PRs are skipped), checks out PR head code for local inspection, pins actions by SHA, filters PR comments to trusted author associations only, and adds SHA verification to prevent reviewing stale code. The previous finding about duplicate reviews on the github-workflows repo is addressed — pr-review.yaml now skips when the event is pull_request and the repository is ConductorOne/github-workflows, so only general-pr-review.yaml runs for this repo. The thread resolution script now verifies all comments in a thread are bot-authored before auto-resolving, preventing resolution of threads with human replies.

Security Issues

None found.

Correctness Issues

None found.

Suggestions

None.

@github-actions github-actions 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.

No blocking issues found.

Comment thread .github/workflows/pr-review.yaml Outdated
github_token: ${{ secrets.GITHUB_TOKEN }}
pr_number: ${{ github.event.pull_request.number }}
review_prompt: ${{ inputs.review_prompt || 'connector' }}
review_prompt: ${{ github.repository == 'ConductorOne/github-workflows' && 'general' || inputs.review_prompt || 'connector' }}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Suggestion: With the if: github.repository != 'ConductorOne/github-workflows' guard removed from both workflows, PRs to the github-workflows repo will now trigger both pr-review.yaml and general-pr-review.yaml. Both resolve to review_prompt: general and produce ### General PR Review: summaries, so they'll race to create/update the same comment. Consider gating one of the two workflows to skip on this repo, or giving them distinct summary headings.

@github-actions

Copy link
Copy Markdown

General PR Review: Run PR review only for same-repo PRs

Blocking Issues: 0 | Suggestions: 1 | Threads Resolved: 0
Review mode: full
View review run

Review Summary

This PR switches both review workflows from pull_request_target to pull_request, skips fork PRs, checks out PR head for local source inspection, pins actions by SHA, filters PR comments to trusted author associations, and adds a bot-authorship check before resolving outdated threads. The changes are well-structured security improvements. One suggestion was raised about duplicate workflow triggers on the github-workflows repo itself.

Security Issues

None found.

Correctness Issues

None found.

Suggestions

  • 🟡 Both pr-review.yaml and general-pr-review.yaml will trigger on PRs to this repo with the same ### General PR Review: heading, causing duplicate reviews — .github/workflows/pr-review.yaml:48
Prompt for AI agents
Verify each finding against the current code and only fix it if needed.

## Suggestions

In `.github/workflows/pr-review.yaml`:
- Around line 48: Both `pr-review.yaml` and `general-pr-review.yaml` now have `on: pull_request` triggers and neither skips the `ConductorOne/github-workflows` repo (the old `if: github.repository != 'ConductorOne/github-workflows'` guard was removed from both). Both resolve to `review_prompt: general` for this repo, producing the same `### General PR Review:` summary heading. This means PRs to the github-workflows repo will trigger duplicate Claude reviews that race to create/update the same summary comment. Fix by either adding an `if: github.repository != 'ConductorOne/github-workflows'` condition back to one of the two workflows, or by giving them distinct summary headings so they don't conflict.

@github-actions github-actions 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.

No blocking issues found.

@github-actions github-actions 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.

No blocking issues found.

@gontzess
gontzess marked this pull request as ready for review May 22, 2026 00:33

@github-actions github-actions 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.

No blocking issues found.

@gontzess
gontzess force-pushed the gontzess/same-repo-pr-review branch from 731d75f to 43ca2fb Compare May 28, 2026 18:16
@gontzess
gontzess merged commit 67a387b into main May 28, 2026
4 checks passed
@gontzess
gontzess deleted the gontzess/same-repo-pr-review branch May 28, 2026 19:12
jugonzalez12 added a commit that referenced this pull request Oct 2, 2026
## Why

Pull requests to this repository get no Claude review. The organization
ruleset that requires `general-pr-review.yaml` on managed repositories
covers this repository too, and the injected run does start here, but
the job's `if:` skipped it: the condition was `github.event_name !=
'pull_request' || github.repository != 'ConductorOne/github-workflows'`,
and the injected run is a `pull_request` event in this repository. A
skipped required job counts as passing, so every PR here merged with the
review check reporting "skipped" (see #140).

## What this changes

Deletes that `if:` line. The event half of the condition only existed to
exempt `workflow_call` callers from the self-skip, so once the
repository check goes there is nothing left for it to do. Nothing else
changes: fork PRs are still skipped by the same-repo guard on each step,
and the connector workflow `pr-review.yaml` keeps its own self-skip, so
this repository gets exactly one review per PR instead of two racing on
the same summary comment.

## Where the self-skip came from

Nobody recorded the reason, so here is the reconstruction from git and
review history.

1. **#50 (February), the original reviewer.** The workflow was
`pull_request_target`-triggered and lived in this repository, so it
fired on this repository's own PRs. Its prompt opened with "You are
reviewing a pull request for a ConductorOne connector repository", so
the one repository that is not a connector excluded itself. No comment
or PR text explains it; that is the inferred origin.
2. **#76 (May 13), the general profile.** `general-pr-review.yaml` was
created by copying the connector workflow and the clause came along
verbatim, even though the connector-prompt reason no longer applied to
the general profile.
3. **#82 (May 21 to 28), the fork fix.** The first commit replaced the
self-skip on both files with a fork-skip, so this repository would have
been reviewed. The bot reviewer then flagged that both workflows now
fire on this repository's PRs with the same `### General PR Review:`
heading and race to update one comment. The response came in two steps:
"Guard PR review against stale heads" put the self-skip back on the
connector workflow only, narrowed to native `pull_request` events so
reusable-workflow callers still run, and the reviewer's next summary
records the intent that only the general workflow runs for this
repository. Then "Skip general PR review self-runs" added the same
clause to the general workflow, with no body and no thread. The
managed-repository ruleset had been created a week earlier and already
injected the general workflow here, so the likely trigger was a second
duplicate: the injected run plus the native run of the same file. The
clause chosen skips both, because the injected run is also a
`pull_request` event in this repository.

So the clause's surviving purpose is duplicate prevention, and the last
step overshot: it removed this repository's review entirely rather than
only the redundant native run. On #140 only one general run existed, the
injected one, so the duplicate from May does not reproduce today.

## Rollout

The injected run always executes the workflow from `main`, so this PR is
still reviewed by the old condition and reports skipped. The first
review lands on the next PR after this merges. The injected run checks
out the workflow repository through contexts that the required-workflow
machinery fills in; on a managed repository they resolve to this
repository at `main`, and the same is expected here, but the
self-repository case cannot be exercised before merge. If it did fail,
the next PR's required check fails loudly and the revert is this one
line.

## Validation

- `actionlint` on the changed file: the only findings are the
pre-existing `job.workflow_repository` / `job.workflow_sha` expressions,
unchanged by this PR.
- `git diff --check` clean.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.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.

2 participants