Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ Every command refuses a config with a key it doesn't know before it contacts Git
```text
config.yaml: repos[3].settings (repo old-tool): unknown setting `archive`. Did you mean `archived`? ...
config.yaml: repos[3].settings (repo old-tool): `default_repository_permission` is not a repository setting: it would be sent to PATCH /orgs/{org}, which is not the repo. ...
config.yaml: repos[3].archived: unknown field `archived`, expected one of `name`, `settings`, `visibility`, `use_default_webhook`, `webhook`, `branch_protections`, `required_checks`, `required_checks_bypass`
config.yaml: repos[3].archived: unknown field `archived`, expected one of `name`, `settings`, `visibility`, `use_default_webhook`, `webhook`, `branch_protections`, `required_checks`, `required_checks_bypass`, `required_approvals`
```

**Example `config.yaml`:**
Expand Down Expand Up @@ -259,6 +259,7 @@ repos:
- A name listed twice is refused when the config is loaded. A `Require CI` ruleset that requires one check twice (from different apps) is refused like one with another rule: a config can't say which pin to keep.
- gh-config owns every rule in `Require CI`: if it holds any other rule, `sync` stops with an error naming the repo and the rule instead of dropping it. Keep other rules in other rulesets.
- `required_checks_bypass` is the ruleset's whole bypass list: `sync` makes it exactly these teams (by slug), so leaving it out removes every bypass, including the org's admins, apps and roles a ruleset can name but a config can't. `mode` is `pull_request` (merging a PR may skip the checks; a direct push may not) or `always`. A team that isn't in the config's `teams` (when it lists any), a team named twice, an unknown mode, or a bypass list without `required_checks` is refused when the config is loaded; `sync` creates the config's `teams` before it touches any repo, so a bypass list may name a team the same config adds. A team that neither the org nor the config's `teams` has is refused before `sync` writes anything.
- `required_approvals: N` (1-10) makes PRs to the default branch need N approving reviews, held in the repo's own ruleset `Require review`: one `pull_request` rule, no bypass list, its other review settings off (a stricter one in another ruleset, such as the org's, still applies; GitHub takes the strictest). `sync` creates or rewrites it, adopting one by name, and refuses one holding any other rule. A repo without the key is left alone; to drop the requirement, delete the ruleset and the key. `sync-from-org` and `diff` read it back, from the same rulesets request as `Require CI`.
- `sync --dry-run` names the checks an update would stop requiring, who may bypass them after it and who no longer may.
- A repo with no `required_checks` is left alone: `sync` doesn't read or delete its rulesets. To stop requiring checks, delete the ruleset on GitHub and the key.
- `sync-from-org` records the checks of each repo's `Require CI` ruleset, in the file's order when the file names the same ones; `diff` compares them as a set. It costs one rulesets request per repo, plus one when `Require CI` exists. A ruleset that can't be read keeps what the file has, and `diff` names the repo and exits 1. It records the bypass list too, reading team ids as slugs (one teams request in all). GitHub shows a ruleset's bypass list only to a token that can administer the repo; when it doesn't, or the list holds anything other than the org's teams, the file's list is kept and `diff` names the repo and exits 1. A ruleset that requires no checks is recorded without them and without a bypass list (a config can't hold a bypass list alone), and `sync-from-org` never writes a config that wouldn't load: it stops and leaves the file as it is. Properties other than the checks and the bypass list aren't recorded, so `diff` shows no change when only those differ; `sync` still corrects them.
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
- `sync` creates repos the config lists and GitHub doesn't have, with their `visibility`.
- `sync-from-org` and `diff` record `allow_auto_merge` and private repos' Actions `access_level`, so the drift check keeps them; `sync` reads `access_level` before writing it.
- New repo field `required_checks`, kept in the repo ruleset `Require CI`.
- New repo field `required_approvals`: approving reviews a PR to the default branch needs, kept in the repo ruleset `Require review`.
- New repo field `required_checks_bypass`: the teams, and only those, that may bypass `Require CI` (`pull_request` or `always`). `sync` writes it, `sync-from-org` and `diff` read it back.

## [v1.3.2] - 2026-11-09
Expand Down
1 change: 1 addition & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ repos: # (list) Repository configurations
allow_auto_merge: true # (bool) Let PRs merge themselves once required checks pass
access_level: organization # (string, private repos only) Who may call this repo's workflows: none, user, organization
visibility: private # (string, optional) "public" or "private"; required for sync to create a missing repo
required_approvals: 1 # (integer 1-10, optional) Approving reviews a PR to the default branch needs (ruleset `Require review`)
required_checks: # (list, optional) Checks a PR to the default branch must pass (ruleset `Require CI`)
- Unit Tests
required_checks_bypass: # (list, optional) The only teams that may merge past required_checks
Expand Down
25 changes: 25 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ pub struct Repo {
/// bypass list exactly this, so leaving it out removes every bypass. Needs `required_checks`.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub required_checks_bypass: Vec<CheckBypass>,
/// Approving reviews a PR to the default branch needs (1-10), held in the repo's `Require review` ruleset.
/// Left out: `sync` leaves that ruleset alone.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub required_approvals: Option<u32>,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord)]
Expand Down Expand Up @@ -232,6 +236,12 @@ impl Config {
repo.name
)));
}
if let Some(n) = repo.required_approvals.filter(|n| !(1..=10).contains(n)) {
return Err(crate::error::AppError::Config(format!(
"{main_path}: repos[{i}].required_approvals (repo {}): GitHub takes 1-10 approving reviews, got {n}; leave the key out for none.",
repo.name
)));
}
let bypass = &repo.required_checks_bypass;
let bypass_problem = if !bypass.is_empty() && checks.is_empty() {
Some("a bypass list needs `required_checks`: without them `sync` leaves the repo's rulesets alone.".to_string())
Expand Down Expand Up @@ -429,6 +439,21 @@ allow_force_pushes: false
assert!(err.contains("required_checks") && err.contains("`A` is listed twice"), "{err}");
}

#[test]
fn required_approvals_is_one_to_ten() {
let load = |text: &str| {
let mut file = tempfile::NamedTempFile::new().unwrap();
std::io::Write::write_all(&mut file, text.as_bytes()).unwrap();
Config::from_file_with_defaults(file.path().to_str().unwrap(), None).map_err(|e| e.to_string())
};
assert_eq!(load("org: o\nrepos:\n- name: r\n required_approvals: 1\n").unwrap().repos[0].required_approvals, Some(1));
for n in ["0", "11"] {
let err = load(&format!("org: o\nrepos:\n- name: r\n required_approvals: {n}\n")).unwrap_err();
assert!(err.contains("required_approvals") && err.contains("1-10"), "{n}: {err}");
}
assert!(load("org: o\nrepos:\n- name: r\n required_approvals: one\n").is_err());
}

#[test]
fn a_bypass_list_names_known_teams_once_with_a_known_mode_and_needs_checks() {
let load = |text: &str| {
Expand Down
Loading
Loading