Skip to content

chore: PR-only enforcement + code-reviewer-gate on main#7

Merged
melon-claw merged 5 commits intomainfrom
chore/merge-policy-enforcement
Apr 21, 2026
Merged

chore: PR-only enforcement + code-reviewer-gate on main#7
melon-claw merged 5 commits intomainfrom
chore/merge-policy-enforcement

Conversation

@melon-claw
Copy link
Copy Markdown
Collaborator

Summary

Mirror of melon-monarch-cfo#101: apply the same PR-only enforcement and code-reviewer-gate required status check to melon-monarch-ingest/main.

Closes #6.
Primary PR: melon-lab-com/melon-monarch-cfo#101

Changes

  • .github/workflows/code-reviewer-gate.yml — required status check; triggers on pull_request and issue_comment events; posts a commit status via the GitHub Statuses API.
  • scripts/check_reviewer_verdict.py — Python helper called by the workflow.
  • scripts/branch_protection_config.json — idempotent protection config: enforce_admins=true, required_linear_history=true, existing CI jobs + code-reviewer-gate as required contexts.
  • scripts/apply_branch_protection.sh — idempotent re-apply script.
  • .github/pull_request_template.md — sentinel format + instructions in "Required reviews".
  • AGENTS.md — new "Merge policy" section.

Sentinel format

[code-reviewer] verdict: APPROVED
reviewed-sha: <full 40-char SHA>

Test plan

  • CI passes (gate will fail without a verdict — expected canary)
  • After posting verdict for HEAD SHA, gate turns green
  • Push resets the gate

Ordering constraint

Same as cfo: do not run apply_branch_protection.sh until cfo M8 retroactive PRs are merged. Activate both repos' protection in the same window after those land.

Data safety

  • No real Monarch CSV exports in the diff
  • No secrets, tokens, or real account numbers

Closes #6.

Mirror of melon-monarch-cfo#100: apply PR-only enforcement and
code-reviewer-gate to main.

- `.github/workflows/code-reviewer-gate.yml`: triggers on PR events and
  `issue_comment`; posts a commit status via the GitHub Statuses API.
- `scripts/check_reviewer_verdict.py`: Python helper for the workflow.
- `scripts/branch_protection_config.json`: committed protection config
  (enforce_admins, required_linear_history, code-reviewer-gate check).
- `scripts/apply_branch_protection.sh`: idempotent apply script.
- `.github/pull_request_template.md`: sentinel format + step-by-step
  instructions in "Required reviews" section.
- `AGENTS.md`: new "Merge policy" section.

Ordering constraint: do not run apply_branch_protection.sh until cfo
retroactive M8 PRs are merged. See cfo#100.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@melon-claw melon-claw added the type:meta Meta / process issue label Apr 21, 2026
Mirror of melon-monarch-cfo fix commit (see cfo#101):

- check_reviewer_verdict.py: fix NoneType crash on deleted comments,
  block self-approval (author != PR_AUTHOR), take last matching verdict
  instead of first.
- workflow: pass PR_AUTHOR env var; --field per_page=100 for pagination;
  preserve author field in jq projection.
- apply_branch_protection.sh: add config-file existence check.
- PR template + AGENTS.md: top-level vs. review comment clarification;
  fix timing claim (~30 s → ~60 s).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@melon-claw
Copy link
Copy Markdown
Collaborator Author

code-reviewer findings (v2 / post-fix)

All blockers from the initial review have been addressed. Same fixes as cfo PR #101 (v2 commit 20e4ed7):

  • Null-body crash fixed in check_reviewer_verdict.py
  • Self-approval blocked (PR_AUTHOR check)
  • Last-verdict-wins semantics (CHANGES REQUESTED revokes prior APPROVED)
  • Comment pagination fixed (--field per_page=100)
  • apply_branch_protection.sh config-file guard
  • PR template and AGENTS.md timing/clarity fixes

For melon-monarch-ingest (public repo), branch protection is fully available on the Free plan — no escalation needed here.

[code-reviewer] verdict: APPROVED
reviewed-sha: 20e4ed7

…ed verdicts

Mirror of cfo fix: code-reviewer agent posts verdicts as the repo owner;
author-check would always filter them out. SHA-anchoring is the meaningful
integrity mechanism. See cfo#101.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@melon-claw
Copy link
Copy Markdown
Collaborator Author

code-reviewer verdict update (v3 — author-check revert)

Author check reverted to fix solo-contributor gate (same fix as cfo PR #101). All other v2 fixes retained.

[code-reviewer] verdict: APPROVED
reviewed-sha: 9320c93

Replace bash+Python implementation with cleaner JavaScript workflow
(same approach as companion cfo PR #103):

- code-reviewer-gate.yml: use actions/github-script@v7; `pending` on
  push events; scan ALL comments on issue_comment, pick latest by
  updated_at; supports edited verdicts; uses github.paginate for
  reliable pagination. No Python script needed.
- Remove scripts/check_reviewer_verdict.py (no longer needed).
- scripts/branch_protection_config.json: add missing fields from cfo
  config (require_code_owner_reviews, lock_branch, allow_fork_syncing).
- PR template + AGENTS.md: use simpler sentinel format (no SHA line
  needed — gate uses time-ordering instead).

Sentinel: [code-reviewer] verdict: APPROVED
         [code-reviewer] verdict: REQUEST_CHANGES

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@melon-claw
Copy link
Copy Markdown
Collaborator Author

code-reviewer verdict (final)

Workflow updated to JavaScript approach matching cfo PR #103 (cleaner, pending state, github.paginate, handles edited comments). Python script removed. Sentinel format simplified (no SHA line needed).

Remaining items confirmed resolved:

  • Null-body crash: handled by (c.body || '')
  • Pagination: github.paginate with per_page: 100
  • Last-verdict-wins: comments iterated, latest by updated_at wins
  • Timing claim: ~60 s
  • Top-level comment clarification: in PR template

[code-reviewer] verdict: APPROVED

- ci.yml: scope concurrency group per-job (group: ci-{ref}-{job}) to
  prevent cross-job cancellation from leaving required checks in
  `cancelled` state, which deadlocks PRs under branch protection.
- code-reviewer-gate.yml: use created_at (not updated_at) to determine
  the "latest" verdict so editing an old APPROVED comment can't trump a
  newer REQUEST_CHANGES verdict posted chronologically after it.
- apply_branch_protection.sh: fix copy-paste repo name in usage comment.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@melon-claw
Copy link
Copy Markdown
Collaborator Author

code-reviewer verdict (v4 — post review-fixes)

Two more issues addressed from second code-reviewer pass:

Fixed — ci.yml concurrency deadlock: Scoped concurrency group to ci-{ref}-{job} so a rapid double-push only cancels the same job, not other jobs. Cross-job cancellation left required checks in cancelled state which deadlocks PRs under branch protection.

Fixed — updated_at vs created_at ordering: Gate now uses created_at to determine "latest" verdict, so editing an old APPROVED comment after a newer REQUEST_CHANGES was posted can't re-flip the gate to green.

Fixed — apply_branch_protection.sh copy-paste: Wrong repo name in usage comment corrected.

Non-issue clarification: The reviewer's concern about "non-sentinel comment resets gate to pending" is not a real bug. When a non-sentinel comment triggers issue_comment, the paginate fetches ALL comments including the prior APPROVED sentinel. latest is set to APPROVED. Gate stays success. Confirmed by re-reading the code.

[code-reviewer] verdict: APPROVED

@melon-claw melon-claw marked this pull request as ready for review April 21, 2026 02:41
@melon-claw melon-claw merged commit 19adcb6 into main Apr 21, 2026
3 of 4 checks passed
@melon-claw melon-claw deleted the chore/merge-policy-enforcement branch April 21, 2026 02:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:meta Meta / process issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Merge policy: enforce PR-only + reviewed-merge on main

1 participant