Add /lgtm + /approve review gate - #2277
Conversation
Signed-off-by: Riaan Kleinhans <riaankleinhans@gmail.com>
There was a problem hiding this comment.
Pull request overview
Adds a CODEOWNERS-driven merge gate for PRs that tracks /lgtm and /approve slash commands, publishes the combined result as a commit status (lgtm/approved), and mirrors state via labels and a sticky status comment.
Changes:
- Introduces a new GitHub Actions workflow that reacts to PR lifecycle events and PR comment slash commands to compute/update gate state.
- Adds a JS “core” module that loads CODEOWNERS from the PR base commit, validates sign-offs, computes coverage, and updates labels/status/sticky comment.
- Registers
lgtmandapprovedlabels in.github/labels.yaml.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| .github/workflows/lgtm.yml | New workflow to process /lgtm//approve commands and reset state on PR lifecycle events. |
| .github/actions/lgtm-core/index.js | Implements CODEOWNERS parsing, signer validation, coverage computation, and GitHub updates (labels/status/sticky comment). |
| .github/labels.yaml | Adds lgtm and approved label definitions for repo label automation. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Narrow comment trigger to the four handled commands (avoid runs on unrelated slash commands like /assign, /retest) - Validate LGTM_OWNERSHIP_MODE and fail loudly on unsupported values - Sync in-code LABEL_DEFS with .github/labels.yaml (color/description) - findStickyComment now keeps the newest match to avoid stale status Signed-off-by: Riaan Kleinhans <riaankleinhans@gmail.com>
|
Couple things. First, this type of work should live in cncf/automation. This isn't a pattern exclusive to the TOC repo. Second... https://github.com/marketplace/actions/prow-github-actions already exists. :) I'd rather not vibe out a solution for an already solved problem. |
|
@jeefy We have been vibing /commands for a while now. |
What this does
This PR adds an automated review gate for pull requests, driven by two chat commands in PR comments:
/lgtm— a code owner signals the change looks good (review sign-off)./approve— a different code owner authorizes the merge.A PR is considered "ready" only when both commands have been given by two different code owners. The result is published as a commit status check (
lgtm/approved) and mirrored with two labels (lgtm,approved) plus a running status comment on the PR.Only people listed in
CODEOWNERSfor the files a PR touches can give these sign-offs, so review authority follows the existing ownership rules.How it works, step by step
/lgtmor/approve. A workflow triggers on the comment.CODEOWNERfor at least one file changed in the PR./lgtmand/approve— those must come from two different people./lgtmsign-offs, and/approvesign-offs (from different people), andlgtm/approved(green when all requirements are met, red otherwise),lgtmandapprovedlabels,/remove-lgtmand/remove-approvelet a reviewer retract their own sign-off; the PR author can also clear a sign-off axis./lgtmand/approvesign-offs are cleared and the gate goes back to red, so approvals always reflect the latest code. The bot posts a note when this happens.Files in this PR
CODEOWNERS, resolving team membership, computing coverage, updating labels/status/comment). It has no external dependencies.lgtmandapprovedlabel definitions so they aren't auto-pruned.Configuration (repository variables)
Behavior is controlled by repo variables, so no code changes are needed to tune or disable it:
LGTM_GATE_ENABLED— master on/off switch. Whenfalse, the status is always green (observe-only). This PR ships with it set tofalse.LGTM_MIN/APPROVE_MIN— how many of each sign-off are required (default1each).LGTM_OWNERSHIP_MODE— ownership evaluation mode (coverage).Rollout / how to review
LGTM_GATE_ENABLED=false): it will post the status comment and labels and show what it would decide, but it will not block any merges.LGTM_GATE_ENABLEDtotrueand addlgtm/approvedas a required status check in branch protection.Security notes
CODEOWNERSfrom the PR's base branch (trusted), never from the PR's own changes — so a PR can't grant itself ownership by editingCODEOWNERSor the gate logic.@org/team) are resolved via the GitHub API; if the token lacks org read permission, the run fails visibly rather than silently miscounting.