Repository navigation
Add org-wide OpenRouter code review workflow #16
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
Changes from all commits
1b4c5af
b47554c
86e8c83
765c36e
9daea4b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,207 @@ | ||
| # Organization-required OpenRouter PR review. | ||
| # Enforced via org ruleset "Require OpenRouter code review" pointing at this | ||
| # file, so every pegma-dev repository (including new ones) gets it without a | ||
| # per-repo workflow. Auth: org-level OPENROUTER_API_KEY secret only. | ||
| # | ||
| # Two cheap review lanes run in parallel and the pinned judge union-merges | ||
| # their findings into one review: | ||
| # meta/muse-spark-1.2 (Meta Muse Spark 1.2) | ||
| # z-ai/glm-5.3-flash (Z.ai GLM 5.3 Flash) | ||
| # judge: openai/gpt-5.6-luna | ||
| # | ||
| # Scope selection: opened, reopened, and manual runs always review the full | ||
| # PR (50 read-only tool rounds). A synchronize run reviews only the | ||
| # unreviewed commit range (30 rounds) when this PR already carries a review | ||
| # ledger posted by the bot, and otherwise performs the full-PR review | ||
| # itself. The action refuses a latest-commit round with no ledger, and | ||
| # GitHub can discard a still-queued first pass when a newer run enters the | ||
| # same concurrency group, so a synchronize must never assume a ledger | ||
| # exists. If the ledger probe itself fails, the run falls back to full-pr. | ||
| # | ||
| # One concurrency group per PR with cancel-in-progress off, so runs for the | ||
| # same PR execute one at a time and each sees the ledger the previous one | ||
| # wrote. GitHub keeps only the newest pending run per group; with ledger- | ||
| # based scope selection the survivor always does the right thing. | ||
| # | ||
| # The job always runs and only the review steps are gated, so the required | ||
| # check stays green for events that cannot be reviewed: ruleset-triggered | ||
| # runs ignore the `types:` filter below and fire only on opened, synchronize, | ||
| # and reopened; fork and Dependabot PRs never receive the org secret; drafts | ||
| # are reviewed like any other PR because ready_for_review never arrives from | ||
| # the ruleset. A missing org secret warns and skips. What can still turn the | ||
| # check red: the job timeout, a checkout failure, or the action itself | ||
| # failing (for example every lane and retry failing during an OpenRouter | ||
| # outage). Those are accepted; organization admins bypass the ruleset, and | ||
| # fail_on stays "never" so review findings are never a merge gate. | ||
| name: OpenRouter code review | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, synchronize, reopened, ready_for_review] | ||
| # Optional manual re-run from the Actions tab on a PR's head repo | ||
| workflow_dispatch: | ||
| inputs: | ||
| pr_number: | ||
| description: PR number to review | ||
| required: true | ||
| type: string | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
|
|
||
| concurrency: | ||
| group: openrouter-code-review-${{ github.repository }}-${{ github.event.pull_request.number || github.event.inputs.pr_number }} | ||
|
FlyOverCoderKY marked this conversation as resolved.
Resolved
|
||
| cancel-in-progress: false | ||
|
|
||
|
FlyOverCoderKY marked this conversation as resolved.
Resolved
|
||
| jobs: | ||
| review: | ||
| name: OpenRouter review | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 30 | ||
| env: | ||
| OR_MODELS: meta/muse-spark-1.2,z-ai/glm-5.3-flash | ||
| OR_JUDGE: openai/gpt-5.6-luna | ||
| # Must match the posting identity (github.token posts as github-actions[bot]). | ||
| BOT_LOGIN: github-actions[bot] | ||
| # Hidden marker the action embeds in every review body that carries loop state. | ||
| LEDGER_MARKER: "<!-- openrouter-review-ledger:v1:" | ||
| # Eligible: a manual dispatch, or a same-repo pull_request event of a | ||
| # reviewable type from anyone but Dependabot. Fork PRs have no org | ||
| # secret and no write token; Dependabot runs get Dependabot secrets. | ||
| REVIEW_ELIGIBLE: >- | ||
| ${{ | ||
| (github.event_name == 'workflow_dispatch' || | ||
| (github.event_name == 'pull_request' && | ||
| contains(fromJSON('["opened","synchronize","reopened","ready_for_review"]'), github.event.action) && | ||
| github.event.pull_request.head.repo.full_name == github.repository && | ||
| github.event.pull_request.user.login != 'dependabot[bot]' && | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 Dependabot/actor check misses variants and can block PRs ( If a Dependabot PR arrives as Evidence: Checked via
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not applicable. dependabot-preview[bot] has not existed for years, and Dependabot PRs always present both user.login and github.actor as dependabot[bot], which is what the gate checks. Renovate and other GitHub App PRs are same-repo branches and do receive org secrets, so they are reviewed normally. The only no-secret cases are forks and Dependabot, both handled. |
||
| github.actor != 'dependabot[bot]')) && 'true' || 'false' | ||
| }} | ||
| steps: | ||
| - name: Skip ineligible event | ||
| if: env.REVIEW_ELIGIBLE != 'true' | ||
| env: | ||
| EVENT: ${{ github.event_name }} | ||
| ACTION: ${{ github.event.action }} | ||
| run: echo "::notice::OpenRouter review skipped for ${EVENT}/${ACTION} (fork, Dependabot, or non-review activity)." | ||
|
|
||
| - name: Check OPENROUTER_API_KEY | ||
| if: env.REVIEW_ELIGIBLE == 'true' | ||
| id: key | ||
| env: | ||
| OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }} | ||
| run: | | ||
| if [ -z "${OPENROUTER_API_KEY}" ]; then | ||
| echo "::warning::OPENROUTER_API_KEY is empty; review skipped. Set the org-level OPENROUTER_API_KEY secret with visibility to this repository." | ||
| echo "present=false" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "present=true" >> "$GITHUB_OUTPUT" | ||
| fi | ||
|
|
||
| - name: Resolve PR head and review scope | ||
| if: env.REVIEW_ELIGIBLE == 'true' && steps.key.outputs.present == 'true' | ||
| id: pr | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| GH_REPO: ${{ github.repository }} | ||
| EVENT_ACTION: ${{ github.event.action }} | ||
| EVENT_HEAD_SHA: ${{ github.event.pull_request.head.sha }} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 workflow_dispatch SHA resolution can hard-fail the required check ( On Evidence: Checked the checkout in the new file and the grok file for comparison; no retry or empty-SHA validation exists. Falsification considered that
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not applicable. A workflow_dispatch run executes on the dispatch ref, not the PR head SHA, so its check run is not the one the ruleset evaluates for the PR; a failed manual run cannot block a merge. b47554c also validates pr_number and the SHA, and sets GH_REPO, which removes the failure the scenario relies on. |
||
| PR_NUMBER: ${{ github.event.pull_request.number || github.event.inputs.pr_number }} | ||
| run: | | ||
| set -euo pipefail | ||
| if [[ ! "${PR_NUMBER}" =~ ^[1-9][0-9]*$ ]]; then | ||
| echo "::error::pr_number must be a positive integer, got '${PR_NUMBER}'." | ||
| exit 1 | ||
| fi | ||
| SHA="${EVENT_HEAD_SHA:-}" | ||
| if [ -z "$SHA" ]; then | ||
| SHA="$(gh pr view "$PR_NUMBER" --json headRefOid --jq .headRefOid)" | ||
|
FlyOverCoderKY marked this conversation as resolved.
Resolved
|
||
| fi | ||
| if [[ ! "$SHA" =~ ^[0-9a-fA-F]{40}$ ]]; then | ||
| echo "::error::Could not resolve a full head SHA for PR ${PR_NUMBER}." | ||
| exit 1 | ||
| fi | ||
| # A synchronize run may only narrow to the latest commits when the | ||
| # bot has already posted loop state on this PR; otherwise it is the | ||
| # initial full-PR review regardless of the event that started it. | ||
| SCOPE=full-pr | ||
| TURNS=50 | ||
|
FlyOverCoderKY marked this conversation as resolved.
Resolved
|
||
| if [ "${EVENT_ACTION}" = "synchronize" ]; then | ||
| # jq reads BOT_LOGIN and LEDGER_MARKER from the environment. A | ||
| # probe failure (API error) must not fail the required check: | ||
| # fall back to the full-PR review, which is always valid. | ||
| LEDGERS="$(gh api --paginate "repos/${GH_REPO}/pulls/${PR_NUMBER}/reviews" \ | ||
| --jq '[.[] | select(.user.login == env.BOT_LOGIN) | .body // "" | select(contains(env.LEDGER_MARKER))] | length' \ | ||
| | awk '{s+=$1} END {print s+0}' || true)" | ||
| if [[ ! "${LEDGERS}" =~ ^[0-9]+$ ]]; then | ||
| echo "::warning::Ledger probe failed for PR ${PR_NUMBER}; falling back to the full-PR review." | ||
| LEDGERS=0 | ||
| fi | ||
| if [ "${LEDGERS}" -gt 0 ]; then | ||
| SCOPE=latest-commit | ||
| TURNS=30 | ||
| else | ||
| echo "::notice::No prior review ledger on PR ${PR_NUMBER}; running the initial full-PR review." | ||
| fi | ||
| fi | ||
| { | ||
| echo "head_sha=${SHA,,}" | ||
| echo "number=${PR_NUMBER}" | ||
| echo "scope=${SCOPE}" | ||
| echo "turns=${TURNS}" | ||
| } >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Checkout PR head | ||
| if: env.REVIEW_ELIGIBLE == 'true' && steps.key.outputs.present == 'true' | ||
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 The SHA
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Verified: refs/tags/v7.0.1 in actions/checkout resolves to 3d3c42e5aac5ba805825da76410c181273ba90b1, so the annotation is correct. The Grok sibling pins an older v4.2.2 SHA, which is a candidate for a separate bump. |
||
| with: | ||
| persist-credentials: false | ||
| fetch-depth: 0 | ||
|
FlyOverCoderKY marked this conversation as resolved.
Resolved
|
||
| ref: ${{ steps.pr.outputs.head_sha }} | ||
|
|
||
| - name: Run OpenRouter review | ||
| if: env.REVIEW_ELIGIBLE == 'true' && steps.key.outputs.present == 'true' | ||
| id: review | ||
| uses: FlyOverCoderKY/openrouter-pr-review-action@4471f5963751223c26a2e169d78c0f13817165aa # main 2026-09-09 | ||
| with: | ||
| github_token: ${{ github.token }} | ||
| pr_number: ${{ steps.pr.outputs.number }} | ||
| bot_login: ${{ env.BOT_LOGIN }} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 New unverified action contract: This commit adds contract assumptions about
Converse risk worth checking with the action author: if the action can emit a marker-bearing review body even when its run errored (e.g. a verdict of This is the same degrade-silently mechanism as r1-6; the reply's external verification (pre-dating this commit) does not cover the new surface.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Verified against the pinned revision: bot_login is a declared input in action.yml (default github-actions[bot]), the marker literal is LEDGER_PREFIX in src/or_pr_review/loop.py (<!-- openrouter-review-ledger:v1:), ledger state is read from pulls/{n}/reviews bodies authored by bot_login (github_ops.list_bot_review_bodies), and per the README a failed or partial initial review does not publish authoritative loop state. Round 4 also exercised the probe end to end on this PR. |
||
| models: ${{ env.OR_MODELS }} | ||
| judge_model: ${{ env.OR_JUDGE }} | ||
|
FlyOverCoderKY marked this conversation as resolved.
Resolved
|
||
| review_scope: ${{ steps.pr.outputs.scope }} | ||
| review_mode: auto | ||
| fail_on: never | ||
| roast_level: professional | ||
| status_comments: "true" | ||
| max_tool_turns: ${{ steps.pr.outputs.turns }} | ||
| env: | ||
| OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }} | ||
|
|
||
| - name: Summary | ||
| if: always() | ||
| env: | ||
| EVENT: ${{ github.event_name }} | ||
| ACTION: ${{ github.event.action }} | ||
| KEY_PRESENT: ${{ steps.key.outputs.present }} | ||
| SCOPE: ${{ steps.pr.outputs.scope }} | ||
| VERDICT: ${{ steps.review.outputs.verdict }} | ||
| ISSUES: ${{ steps.review.outputs.issue_count }} | ||
| REVIEW_URL: ${{ steps.review.outputs.review_url }} | ||
| run: | | ||
| { | ||
| echo "### OpenRouter code review" | ||
| echo "" | ||
| echo "| Field | Value |" | ||
| echo "| --- | --- |" | ||
| echo "| Event | \`${EVENT}/${ACTION:-dispatch}\` |" | ||
| echo "| Eligible | \`${REVIEW_ELIGIBLE}\` |" | ||
| echo "| Secret present | \`${KEY_PRESENT:-n/a}\` |" | ||
| echo "| Scope | \`${SCOPE:-n/a}\` |" | ||
| echo "| Models | \`${OR_MODELS}\` |" | ||
| echo "| Judge | \`${OR_JUDGE}\` |" | ||
| echo "| Verdict | \`${VERDICT:-n/a}\` |" | ||
| echo "| Issues | \`${ISSUES:-n/a}\` |" | ||
| echo "| Review | ${REVIEW_URL:-n/a} |" | ||
| } >> "$GITHUB_STEP_SUMMARY" | ||
Uh oh!
There was an error while loading. Please reload this page.