Skip to content
Merged
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
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,21 @@ repos:

**Upgrading from 1.3.0:** a config with `default_webhook` and no `use_default_webhook` keeps working but connects nothing new. Add the key to each repo that should have the default, or run `sync-from-org` to mark the repos that already have it. That marks every repo holding the webhook, so delete any that shouldn't have it first.

### Labels

`default_labels` are labels every repo in `repos` gets: for a label a process depends on, such as the one a CI workflow waits for.

```yaml
default_labels:
- name: ok-to-test
color: "0e8a16" # six hex digits, no `#`; quote it so YAML reads a string
description: Run CI on this PR
```

- `sync` creates each label a repo lacks and corrects one whose color or description differs (an omitted description is none). It never deletes or renames a label, so a repo's other labels stay. Names match ignoring case, as on GitHub. Archived repos are skipped. `sync --dry-run` prints each label it would create or update.
- `diff` reads each listed repo's labels and lists what `sync` would write, exiting 1 if anything is; a repo whose labels can't be read is named. `sync-from-org` keeps the file's `default_labels`.
- Labels need a token that can write issues or pull requests (an App: `Issues` or `Pull requests`, write) for `sync`, and read them for `diff`.

### Defaults and Merging

You can provide a `defaults.config.yaml` file to specify org-wide or policy defaults. All fields are optional. The main config takes precedence over defaults.
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file.
- A required check can be pinned to the app that must post it: `{context: <name>, app_id: <id>}`. Only an `app_id` sets or changes a pin; a plain name keeps the ruleset's. `sync`, `diff` and `sync-from-org` compare and record pins.
- `sync` keeps a `Require CI` ruleset's branch conditions and strictness when it rewrites it, instead of resetting them to the default branch and not strict.
- New top-level `actions` block: the org's `default_workflow_permissions` and `can_approve_pull_request_reviews`. `sync` writes them, `sync-from-org` and `diff` read them back; without the block they're left alone.
- New top-level `default_labels`: labels every listed repo gets. `sync` creates a missing one and corrects its color and description, never deleting a label; `diff` lists what it would write; `sync-from-org` keeps them.

## [v1.3.2] - 2026-11-09

Expand Down
5 changes: 5 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ default_webhook: # (object, optional) Webhook of repos with use
events:
- push

default_labels: # (list, optional) Labels every listed repo gets; sync never deletes one
- name: ok-to-test
color: "0e8a16" # (string) six hex digits, no "#"
description: Run CI on this PR # (string, optional)

default_branch_protections: # (list, optional) Default branch protection rules
- pattern: main
enforce_admins: true
Expand Down
53 changes: 53 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,19 @@ impl WorkflowPermissions {
}
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(deny_unknown_fields)]
/// An issue and pull request label every repo of the config gets.
pub struct Label {
/// The label's name. GitHub matches label names ignoring case.
pub name: String,
/// Six hex digits, without `#`.
pub color: String,
/// Empty: the label has no description.
#[serde(default, skip_serializing_if = "String::is_empty")]
pub description: String,
}

#[derive(Debug, Serialize, Deserialize, Clone)] // Added Clone
#[serde(deny_unknown_fields)]
///
Expand Down Expand Up @@ -281,6 +294,10 @@ pub struct Config {
/// Default branch protection rules for all repositories (if not overridden).
#[serde(default)]
pub default_branch_protections: Vec<BranchProtectionRule>,
/// Labels every repo in `repos` gets, archived ones aside. `sync` creates a missing one and corrects its color
/// and description; it never deletes a label, so a repo's other labels stay.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub default_labels: Vec<Label>,
}

impl Config {
Expand Down Expand Up @@ -308,6 +325,20 @@ impl Config {
// Unknown or misplaced keys are refused, naming the file, where the key is and the keys allowed there.
let config: Config = serde_path_to_error::deserialize(main_config)
.map_err(|e| crate::error::AppError::Config(format!("{main_path}: {}: {}", e.path(), e.inner())))?;
for (i, label) in config.default_labels.iter().enumerate() {
let problem = if label.name.trim().is_empty() {
Some("a label needs a name.".to_string())
} else if label.color.len() != 6 || !label.color.chars().all(|c| c.is_ascii_hexdigit()) {
Some(format!("color `{}` isn't six hex digits (write it without `#`).", label.color))
} else if config.default_labels.iter().take(i).any(|l| l.name.eq_ignore_ascii_case(&label.name)) {
Some("it is listed twice (GitHub matches label names ignoring case).".to_string())
} else {
None
};
if let Some(problem) = problem {
return Err(crate::error::AppError::Config(format!("{main_path}: default_labels[{i}] (label {}): {problem}", label.name)));
}
}
let allowed = crate::api_mapping::repo_settings();
let all = crate::github_api_mapping_generated::get_github_api_mapping();
for (i, repo) in config.repos.iter().enumerate() {
Expand Down Expand Up @@ -580,6 +611,28 @@ allow_force_pushes: false
assert!(err.contains("needs `required_checks`"), "{err}");
}

#[test]
fn default_labels_need_a_name_a_hex_color_and_appear_once() {
let load = |labels: &str| {
let mut file = tempfile::NamedTempFile::new().unwrap();
std::io::Write::write_all(&mut file, format!("org: o\ndefault_labels: {labels}\n").as_bytes()).unwrap();
Config::from_file_with_defaults(file.path().to_str().unwrap(), None).map_err(|e| e.to_string())
};
let ok = load("[{name: ok-to-test, color: 0E8a16, description: Run CI}, {name: x, color: ffffff}]").unwrap();
assert_eq!(ok.default_labels[0], Label { name: "ok-to-test".into(), color: "0E8a16".into(), description: "Run CI".into() });
assert_eq!(ok.default_labels[1].description, "");
for (labels, expected) in [
("[{name: a, color: '#0e8a16'}]", "isn't six hex digits"),
("[{name: a, color: green}]", "isn't six hex digits"),
("[{name: ' ', color: 0e8a16}]", "needs a name"),
("[{name: a, color: 0e8a16}, {name: A, color: ffffff}]", "listed twice"),
("[{name: a, color: 0e8a16, colour: x}]", "unknown field `colour`"),
] {
let err = load(labels).unwrap_err();
assert!(err.contains("default_labels") && err.contains(expected), "{labels}: {err}");
}
}

#[test]
fn test_config_with_branch_protections() {
let yaml = r#"
Expand Down
Loading
Loading