Skip to content

Commit d626fd4

Browse files
committed
fix: ordering issue
1 parent 752e173 commit d626fd4

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

sync-team/src/github/mod.rs

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -489,28 +489,28 @@ impl SyncGitHub {
489489
&self,
490490
expected_repo: &rust_team_data::v1::Repo,
491491
) -> anyhow::Result<Vec<EnvironmentDiff>> {
492-
let mut environment_diffs = Vec::new();
493-
494492
let actual_environments = self
495493
.github
496494
.repo_environments(&expected_repo.org, &expected_repo.name)?;
497495

498496
let expected_env_names: HashSet<String> =
499497
expected_repo.environments.keys().cloned().collect();
500-
501498
let actual_env_names: HashSet<String> = actual_environments.keys().cloned().collect();
502499

503-
// Environments to create or update (sorted for deterministic output)
504-
let mut to_create_or_update: Vec<_> = expected_repo.environments.iter().collect();
505-
to_create_or_update.sort_by_key(|(name, _)| name.as_str());
500+
let mut environment_diffs = Vec::new();
501+
502+
// Process environments to create or update (sorted for deterministic output)
503+
let mut environments_to_process: Vec<_> = expected_repo.environments.iter().collect();
504+
environments_to_process.sort_by_key(|(name, _)| name.as_str());
506505

507-
for (env_name, expected_env) in to_create_or_update {
506+
for (env_name, expected_env) in environments_to_process {
508507
match actual_environments.get(env_name) {
509-
Some(actual_env) if actual_env.branches == expected_env.branches => {
510-
// No change needed
511-
continue;
512-
}
513508
Some(actual_env) => {
509+
// Skip if branches are identical (order-independent comparison)
510+
if branches_equal(&actual_env.branches, &expected_env.branches) {
511+
continue;
512+
}
513+
514514
// Environment exists but branches differ - update it
515515
environment_diffs.push(EnvironmentDiff::Update(
516516
env_name.clone(),
@@ -528,13 +528,13 @@ impl SyncGitHub {
528528
}
529529
}
530530

531-
// Environments to delete (sorted for deterministic output)
532-
let mut to_delete: Vec<_> = actual_env_names
531+
// Process environments to delete (sorted for deterministic output)
532+
let mut envs_to_delete: Vec<_> = actual_env_names
533533
.difference(&expected_env_names)
534534
.cloned()
535535
.collect();
536-
to_delete.sort();
537-
for env in to_delete {
536+
envs_to_delete.sort();
537+
for env in envs_to_delete {
538538
environment_diffs.push(EnvironmentDiff::Delete(env));
539539
}
540540

@@ -554,6 +554,16 @@ impl SyncGitHub {
554554
}
555555
}
556556

557+
/// Compare two branch lists for equality, ignoring order
558+
fn branches_equal(a: &[String], b: &[String]) -> bool {
559+
if a.len() != b.len() {
560+
return false;
561+
}
562+
let a_set: HashSet<&String> = a.iter().collect();
563+
let b_set: HashSet<&String> = b.iter().collect();
564+
a_set == b_set
565+
}
566+
557567
fn calculate_permission_diffs(
558568
expected_repo: &rust_team_data::v1::Repo,
559569
mut actual_teams: HashMap<String, api::RepoTeam>,

0 commit comments

Comments
 (0)