Skip to content

Commit f182c1d

Browse files
committed
feat: add verbose logging
1 parent ac98f09 commit f182c1d

File tree

2 files changed

+85
-7
lines changed

2 files changed

+85
-7
lines changed

sync-team/src/github/mod.rs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -510,10 +510,11 @@ impl SyncGitHub {
510510
// No change needed
511511
continue;
512512
}
513-
Some(_actual_env) => {
513+
Some(actual_env) => {
514514
// Environment exists but branches differ - update it
515515
environment_diffs.push(EnvironmentDiff::Update(
516516
env_name.clone(),
517+
actual_env.branches.clone(),
517518
expected_env.branches.clone(),
518519
));
519520
}
@@ -966,7 +967,7 @@ struct UpdateRepoDiff {
966967
#[derive(Debug)]
967968
enum EnvironmentDiff {
968969
Create(String, Vec<String>),
969-
Update(String, Vec<String>),
970+
Update(String, Vec<String>, Vec<String>),
970971
Delete(String),
971972
}
972973

@@ -1030,8 +1031,8 @@ impl UpdateRepoDiff {
10301031
EnvironmentDiff::Create(name, branches) => {
10311032
sync.create_environment(&self.org, &self.name, name, branches)?;
10321033
}
1033-
EnvironmentDiff::Update(name, branches) => {
1034-
sync.update_environment(&self.org, &self.name, name, branches)?;
1034+
EnvironmentDiff::Update(name, _old_branches, new_branches) => {
1035+
sync.update_environment(&self.org, &self.name, name, new_branches)?;
10351036
}
10361037
EnvironmentDiff::Delete(name) => {
10371038
sync.delete_environment(&self.org, &self.name, name)?;
@@ -1118,10 +1119,28 @@ impl std::fmt::Display for UpdateRepoDiff {
11181119
writeln!(f, " Branches: {}", branches.join(", "))?;
11191120
}
11201121
}
1121-
EnvironmentDiff::Update(name, branches) => {
1122+
EnvironmentDiff::Update(name, old_branches, new_branches) => {
11221123
writeln!(f, " 🔄 Update: {name}")?;
1123-
if !branches.is_empty() {
1124-
writeln!(f, " Branches: {}", branches.join(", "))?;
1124+
let old_set: HashSet<_> = old_branches.iter().collect();
1125+
let new_set: HashSet<_> = new_branches.iter().collect();
1126+
1127+
let mut added: Vec<_> =
1128+
new_set.difference(&old_set).map(|s| s.as_str()).collect();
1129+
let mut removed: Vec<_> =
1130+
old_set.difference(&new_set).map(|s| s.as_str()).collect();
1131+
1132+
// Sort for deterministic output
1133+
added.sort();
1134+
removed.sort();
1135+
1136+
if !added.is_empty() {
1137+
writeln!(f, " Adding branches: {}", added.join(", "))?;
1138+
}
1139+
if !removed.is_empty() {
1140+
writeln!(f, " Removing branches: {}", removed.join(", "))?;
1141+
}
1142+
if added.is_empty() && removed.is_empty() {
1143+
writeln!(f, " No branch changes")?;
11251144
}
11261145
}
11271146
EnvironmentDiff::Delete(name) => writeln!(f, " ❌ Delete: {name}")?,

sync-team/src/github/tests/mod.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,3 +1108,62 @@ fn repo_environment_update() {
11081108
]
11091109
"#);
11101110
}
1111+
1112+
#[test]
1113+
fn repo_environment_update_branches() {
1114+
let mut model = DataModel::default();
1115+
model.create_repo(
1116+
RepoData::new("repo1").environment_with_branches("production", &["main", "release/*"]),
1117+
);
1118+
let gh = model.gh_model();
1119+
1120+
// Update branches for production environment
1121+
model.get_repo("repo1").environments.insert(
1122+
"production".to_string(),
1123+
v1::Environment {
1124+
branches: vec!["main".to_string(), "stable".to_string()],
1125+
},
1126+
);
1127+
1128+
let diff = model.diff_repos(gh);
1129+
insta::assert_debug_snapshot!(diff, @r#"
1130+
[
1131+
Update(
1132+
UpdateRepoDiff {
1133+
org: "rust-lang",
1134+
name: "repo1",
1135+
repo_node_id: "0",
1136+
settings_diff: (
1137+
RepoSettings {
1138+
description: "",
1139+
homepage: None,
1140+
archived: false,
1141+
auto_merge_enabled: false,
1142+
},
1143+
RepoSettings {
1144+
description: "",
1145+
homepage: None,
1146+
archived: false,
1147+
auto_merge_enabled: false,
1148+
},
1149+
),
1150+
permission_diffs: [],
1151+
branch_protection_diffs: [],
1152+
environment_diffs: [
1153+
Update(
1154+
"production",
1155+
[
1156+
"main",
1157+
"release/*",
1158+
],
1159+
[
1160+
"main",
1161+
"stable",
1162+
],
1163+
),
1164+
],
1165+
},
1166+
),
1167+
]
1168+
"#);
1169+
}

0 commit comments

Comments
 (0)