Repository navigation
Expand file tree
/
Copy pathgatehouse.yml
More file actions
122 lines (116 loc) · 6.4 KB
/
Copy pathgatehouse.yml
File metadata and controls
122 lines (116 loc) · 6.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# Gatehouse — fork-safe code review + workflow protection, in ONE file.
#
# Drop this in your repo at .github/workflows/gatehouse.yml, add a OPENROUTER_API_KEY
# secret, and you get:
# • AI review of every PR (including from forks) — posted as a PR review
# • rejection of untrusted PRs that try to modify your workflow files
#
# Nothing is ever checked out from the PR. The fork's change is only ever read as
# a diff (data); the reviewer logic lives in the pinned gatehouse container; the
# rules (your styleguide/constitution) are fetched from YOUR base branch, not the
# PR. The one thing you don't trust — the proposed change — is only ever read.
#
# Three jobs with DIFFERENT authority:
# • guard — a real blocking gate. Mark it a REQUIRED status check so a PR
# that tampers with your workflow files is rejected.
# • review — ADVISORY. It posts findings as PR comments and no finding
# fails it; it fails only when the review did not happen:
# fewer than half of the agents finished (provider down,
# key refused), or the reviewer could not run at all. Do
# NOT mark it required. An LLM reviewer is non-deterministic,
# so it must never hold merge authority. (Opt into blocking with
# `blocking: true` below only if you accept that tradeoff — and
# even then, keep it out of branch protection.)
# • triage — deterministic. Fails while any finding has no answer
# (`fixed in <sha>`, `not a bug: <reason>` or
# `deferred: <open issue URL>`), or while the
# last review did not finish. Safe to mark
# REQUIRED: it never judges code, only whether a human answered.
name: Gatehouse
on:
pull_request_target:
types: [opened, synchronize, reopened]
# A reply rings the doorbell: this run's own checks do not count toward
# branch rules, so gatehouse-retriage.yml answers it by re-running
# triage inside the pull_request_target run. Add that file too.
pull_request_review_comment:
types: [created, edited, deleted]
permissions: {} # default-deny; each job grants only what it needs
jobs:
# ── 1) Protect the workflow files themselves ────────────────────────────────
# Rejects PRs from forks that touch .github/workflows/ or .sdlc/ (the
# launcher the required `sdlc ci` check runs). Safe under
# pull_request_target because it only reads the changed-file LIST via the
# API — it never checks out or runs your code. And because pull_request_target
# runs the BASE version of this file, a PR can't edit this job to disable it.
guard:
name: Protect workflows
# Runs on replies too. A job skipped on the reply event reports
# "skipped", which a required check counts as passing: skipping the
# guard there would let any comment on a rejected fork PR clear it.
runs-on: ${{ github.event.repository.private && vars.UNCACHED_RUNNER_LABEL || 'ubuntu-latest' }}
permissions:
contents: read
pull-requests: write
steps:
- name: Reject workflow changes from untrusted PRs
env:
GH_TOKEN: ${{ github.token }}
EVENT: ${{ github.event_name }}
PR: ${{ github.event.pull_request.number }}
HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }}
run: |
set -euo pipefail
# Gate on where the branch lives, not on the author's role: a branch
# pushed into this repo already required write access, and a fork is
# what pull_request_target actually guards against.
if [ "$HEAD_REPO" = "$GITHUB_REPOSITORY" ]; then
echo "Head branch is in $GITHUB_REPOSITORY; allowing."; exit 0
fi
# Both sides of a rename: `gh pr diff --name-only` lists only the new
# path, so a fork could move a file out of .github/workflows/ or .sdlc/ unseen.
changed="$(gh api --paginate "repos/$GITHUB_REPOSITORY/pulls/$PR/files" \
--jq '.[] | .filename, (.previous_filename // empty)')"
if echo "$changed" | grep -qE '^(\.github/workflows|\.sdlc)/'; then
echo "::error::PR modifies .github/workflows/ or .sdlc/ — not accepted from external contributors."
# Explain once, on the PR event; replies re-run the check, not the comment.
if [ "$EVENT" = "pull_request_target" ]; then
gh pr comment "$PR" --repo "$GITHUB_REPOSITORY" --body \
$'🚫 **Workflow changes are not accepted via pull request.** Please open an issue and a maintainer will make the change.'
fi
exit 1
fi
echo "No workflow files changed."
# ── 2) Review the PR diff (no checkout, BYO key) ────────────────────────────
# The reviewer is maintained centrally in gatehouse's reusable workflow and the
# container it names, called at the major tag — so a fix reaches you with no
# change to this file.
# Scope OPENROUTER_API_KEY to this reusable workflow so only it can read the key.
review:
name: Gatehouse review
if: github.event_name == 'pull_request_target'
permissions:
contents: read
pull-requests: write
uses: crunchtools/gatehouse/.github/workflows/review.yml@v0
# Advisory by default — findings post as comments and never fail the check.
# Uncomment to let critical/high findings fail the check (still not required):
# with:
# blocking: true
secrets:
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
# ── 3) Every finding answered ──────────────────────────────────────────────
# Runs after the review on a push, and alone on a reply (review is skipped
# then, hence always()). Read-only, no secrets. LOW findings need an answer
# only from Bug Hunter and Security Scan; other LOWs are advisory. To change
# which agents' LOWs are required (agent names, comma-separated), set the
# same list here and on the review job above, so the review posts them all:
# with:
# required_low_agents: "Bug Hunter,Security Scan,Test Coverage"
triage:
name: Gatehouse triage
needs: review
if: always()
permissions:
pull-requests: read
uses: crunchtools/gatehouse/.github/workflows/triage.yml@v0