Skip to content

Commit

Permalink
Add a branch protection option to choose required approval count
Browse files Browse the repository at this point in the history
Before this PR, the default value was implicitly 0 if bors is used or 1 if bors isn't used. However, for some repositories it's enough to require PRs, but approvals are not needed. Setting `required-approvals = 0` will allow that (once it's implemented in `sync-team`).
  • Loading branch information
Kobzol committed Jan 6, 2024
1 parent 57e50ec commit 87be2d9
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/toml-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,8 @@ ci-checks = ["CI"]
# merging into this branch require another review.
# (optional - default `false`)
dismiss-stale-review = false
# How many approvals are required for a PR to be merged.
# This option is only relevant if bors is not used.
# (optional - default `1`)
required-approvals = 1
```
1 change: 1 addition & 0 deletions rust_team_data/src/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ pub struct BranchProtection {
pub pattern: String,
pub ci_checks: Vec<String>,
pub dismiss_stale_review: bool,
pub required_approvals: u32,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down
2 changes: 2 additions & 0 deletions src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -733,4 +733,6 @@ pub(crate) struct BranchProtection {
pub ci_checks: Vec<String>,
#[serde(default)]
pub dismiss_stale_review: bool,
#[serde(default)]
pub required_approvals: Option<u32>,
}
1 change: 1 addition & 0 deletions src/static_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ impl<'a> Generator<'a> {
pattern: b.pattern.clone(),
ci_checks: b.ci_checks.clone(),
dismiss_stale_review: b.dismiss_stale_review,
required_approvals: b.required_approvals.unwrap_or(1),
})
.collect();
let repo = v1::Repo {
Expand Down
3 changes: 2 additions & 1 deletion tests/static-api/_expected/v1/repos.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"ci_checks": [
"CI"
],
"dismiss_stale_review": false
"dismiss_stale_review": false,
"required_approvals": 1
}
]
}
Expand Down
3 changes: 2 additions & 1 deletion tests/static-api/_expected/v1/repos/some_repo.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"ci_checks": [
"CI"
],
"dismiss_stale_review": false
"dismiss_stale_review": false,
"required_approvals": 1
}
]
}

0 comments on commit 87be2d9

Please sign in to comment.