Skip to content

Commit b3bc685

Browse files
authored
ci(hook): adopt the commit gate in this repo and fail on empty review secrets (#690)
## What - `scripts/hooks/pre-commit` and `scripts/setup-hooks.sh` (`core.hooksPath`): fmt, clippy when Rust files are staged, then `cora hook verify` with `cora review --staged --ci --severity major` as fallback. - `cora-review.yml`: the secret guard now errors with the name of each empty secret among CORA_API_KEY, CORA_BASE_URL and CORA_MODEL. - AGENTS.md: a before-committing line; CHANGELOG entry. ## Why Uses the commit gate from #674 in this repository, and makes sure a Cora Review without its secrets can never pass silently. ## Testing - bash -n on the hook, workflow YAML parses, local review passes. - The secret guard runs on this PR (secrets are set, so it must pass). Signed-off-by: ajianaz <ajianaz@users.noreply.github.com> Co-authored-by: ajianaz <ajianaz@users.noreply.github.com>
1 parent d3a2ad1 commit b3bc685

5 files changed

Lines changed: 64 additions & 5 deletions

File tree

‎.github/workflows/cora-review.yml‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,21 @@ jobs:
2424
# CORA_API_KEY (pull_request_target). A PR-supplied .cora.yaml could set
2525
# provider.base_url and exfiltrate the key. CORA_BASE_URL (env) always
2626
# takes precedence over project config, so require it to be pinned.
27-
- name: Require pinned CORA_BASE_URL
27+
- name: Require the review secrets
2828
env:
29+
CORA_API_KEY: ${{ secrets.CORA_API_KEY }}
2930
CORA_BASE_URL: ${{ secrets.CORA_BASE_URL }}
31+
CORA_MODEL: ${{ secrets.CORA_MODEL }}
3032
run: |
31-
if [ -z "$CORA_BASE_URL" ]; then
32-
echo "::error::Secret CORA_BASE_URL must be set so a PR-supplied .cora.yaml cannot redirect the API key."
33-
exit 1
34-
fi
33+
# An empty secret must fail the job: a skipped or fallback review is not a pass.
34+
missing=0
35+
for name in CORA_API_KEY CORA_BASE_URL CORA_MODEL; do
36+
if [ -z "${!name}" ]; then
37+
echo "::error::Secret $name is empty or missing. Cora Review cannot run, and that must not pass silently."
38+
missing=1
39+
fi
40+
done
41+
exit "$missing"
3542
3643
- name: Checkout PR head
3744
uses: actions/checkout@v4

‎AGENTS.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ code structure are in `AGENT.md`.
99
- CI runs the same gates: `cargo fmt --all -- --check` and
1010
`cargo clippy --all-targets --features tree-sitter -- -D warnings`.
1111
- User-visible changes go under `## [Unreleased]` in `CHANGELOG.md`.
12+
- Before committing: review the staged diff (`cora review --staged`, or the
13+
`/cora-review` skill) and run `scripts/setup-hooks.sh` once per clone so the
14+
pre-commit hook enforces the same gates. Never `--no-verify` past a finding.
1215

1316
## Conventions enforced by CI
1417

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313

1414
### Fixed
1515

16+
- The `Cora Review` workflow now fails with an error naming each empty secret (`CORA_API_KEY`, `CORA_BASE_URL`, `CORA_MODEL`) instead of running without them.
1617
- The `Cora Review` job no longer gets cancelled on larger pull requests: its time limit is 30 minutes (the review action allows up to three LLM attempts of 10 minutes each).
1718

1819
## [0.19.0] - 2026-10-16

‎scripts/hooks/pre-commit‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
# Repo pre-commit hook: fmt, clippy (when Rust files are staged), then the cora gate.
3+
# Enable once per clone with scripts/setup-hooks.sh.
4+
set -uo pipefail
5+
6+
CORA_BIN="${CORA_BIN:-cora}"
7+
8+
if ! cargo fmt --all -- --check >/dev/null 2>&1; then
9+
echo "cargo fmt --all -- --check failed. Run: cargo fmt --all" >&2
10+
exit 1
11+
fi
12+
13+
if git diff --cached --name-only | grep -q '\.rs$'; then
14+
if ! cargo clippy --all-targets --features tree-sitter -- -D warnings >/dev/null 2>&1; then
15+
echo "cargo clippy failed. Run it and fix the warnings before committing." >&2
16+
exit 1
17+
fi
18+
fi
19+
20+
# Already reviewed (by an agent or by `cora review --staged`)? Then it passes.
21+
"$CORA_BIN" hook verify --quiet
22+
case $? in
23+
0) exit 0 ;;
24+
10)
25+
echo "cora: the staged diff was reviewed and the verdict blocks the commit." >&2
26+
exit 2
27+
;;
28+
esac
29+
30+
"$CORA_BIN" review --staged --ci --severity major --format compact
31+
case $? in
32+
0) exit 0 ;;
33+
2)
34+
echo "cora review found blocking issues. Do not use --no-verify to get past them." >&2
35+
exit 2
36+
;;
37+
*)
38+
echo "cora review hit a tooling error. That is not a pass." >&2
39+
exit 0
40+
;;
41+
esac

‎scripts/setup-hooks.sh‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
# Point git at the committed hooks in scripts/hooks (once per clone).
3+
set -euo pipefail
4+
cd "$(git rev-parse --show-toplevel)"
5+
chmod +x scripts/hooks/pre-commit
6+
git config core.hooksPath scripts/hooks
7+
echo "git hooks now come from scripts/hooks"

0 commit comments

Comments
 (0)