From 5cccf32012e723eef0dc0b8a2f04bb3647598879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Sat, 6 Jan 2024 21:23:05 +0100 Subject: [PATCH 1/3] Add support for syncing branch protection required approval count --- Cargo.lock | 32 +++++++++++++++++++++++++++----- src/github/mod.rs | 9 ++++++++- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a49de59..d20f3fb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -192,6 +192,12 @@ dependencies = [ "termcolor", ] +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + [[package]] name = "fastrand" version = "1.8.0" @@ -313,7 +319,7 @@ dependencies = [ "futures-sink", "futures-util", "http", - "indexmap", + "indexmap 1.9.1", "slab", "tokio", "tokio-util", @@ -326,6 +332,12 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +[[package]] +name = "hashbrown" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" + [[package]] name = "hermit-abi" version = "0.1.14" @@ -453,7 +465,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" dependencies = [ "autocfg", - "hashbrown", + "hashbrown 0.12.3", +] + +[[package]] +name = "indexmap" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" +dependencies = [ + "equivalent", + "hashbrown 0.14.3", "serde", ] @@ -778,12 +800,12 @@ dependencies = [ [[package]] name = "rust_team_data" version = "1.0.0" -source = "git+https://github.com/rust-lang/team#c46e938189fc085b902ce0e96cb1e611d2e400cc" +source = "git+https://github.com/rust-lang/team#3c2148cab16d60b9a0336076ac085bed7ddeb46b" dependencies = [ "chacha20poly1305", "getrandom", "hex", - "indexmap", + "indexmap 2.1.0", "serde", ] @@ -922,7 +944,7 @@ dependencies = [ "base64 0.13.0", "env_logger", "hyper-old-types", - "indexmap", + "indexmap 1.9.1", "log", "reqwest", "rust_team_data", diff --git a/src/github/mod.rs b/src/github/mod.rs index 7b82220..a0e5bbd 100644 --- a/src/github/mod.rs +++ b/src/github/mod.rs @@ -439,7 +439,14 @@ fn construct_branch_protection( expected_repo: &rust_team_data::v1::Repo, branch_protection: &rust_team_data::v1::BranchProtection, ) -> api::BranchProtection { - let required_approving_review_count = u8::from(!expected_repo.bots.contains(&Bot::Bors)); + let required_approving_review_count: u8 = if expected_repo.bots.contains(&Bot::Bors) { + 0 + } else { + branch_protection + .required_approvals + .try_into() + .expect("Too large required approval count") + }; let push_allowances = expected_repo .bots .contains(&Bot::Bors) From 555c68e9af1c7767a67ff2d54dcfd8170e67e8f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Sat, 6 Jan 2024 21:27:44 +0100 Subject: [PATCH 2/3] Fix clippy warning --- src/github/api.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/github/api.rs b/src/github/api.rs index 66bea84..af5d7c9 100644 --- a/src/github/api.rs +++ b/src/github/api.rs @@ -789,7 +789,7 @@ impl GitHub { let res: GraphResult = resp.json_annotated().with_context(|| { format!("Failed to decode response body on graphql request with query '{query}'") })?; - if let Some(error) = res.errors.get(0) { + if let Some(error) = res.errors.first() { bail!("graphql error: {}", error.message); } else if let Some(data) = res.data { Ok(data) From a093cf684b6e9b0931b5882d28e35d128f3eb154 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Sat, 6 Jan 2024 21:31:10 +0100 Subject: [PATCH 3/3] Update dependencies to fix tests --- Cargo.lock | 8 ++++---- Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d20f3fb..8515842 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -319,7 +319,7 @@ dependencies = [ "futures-sink", "futures-util", "http", - "indexmap 1.9.1", + "indexmap 1.9.3", "slab", "tokio", "tokio-util", @@ -460,9 +460,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.9.1" +version = "1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg", "hashbrown 0.12.3", @@ -944,7 +944,7 @@ dependencies = [ "base64 0.13.0", "env_logger", "hyper-old-types", - "indexmap 1.9.1", + "indexmap 2.1.0", "log", "reqwest", "rust_team_data", diff --git a/Cargo.toml b/Cargo.toml index dfcf17b..1e54cb2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,4 +17,4 @@ tempfile = "3.3" serde_json = "1.0" [dev-dependencies] -indexmap = "1.9" +indexmap = "2.1.0"