From 34f8ff40f69ca94fac992ebaf98c0db31f95236c Mon Sep 17 00:00:00 2001 From: Anthony Shew Date: Tue, 18 Jun 2024 12:47:07 -0600 Subject: [PATCH] Fix outdated user listing. (#8526) ### Description Vercel changed how personal accounts work so that they are team accounts. This meant this implementation was writing personal teams twice. Note: This change should only affect Vercel to compensate for those internal changes. Non-Vercel systems should be unaffected. ### Testing Instructions Run `turbo link`. --- crates/turborepo-lib/src/commands/link.rs | 42 ++++++----------------- 1 file changed, 11 insertions(+), 31 deletions(-) diff --git a/crates/turborepo-lib/src/commands/link.rs b/crates/turborepo-lib/src/commands/link.rs index b5a95ec3c6281..afda0addd9f07 100644 --- a/crates/turborepo-lib/src/commands/link.rs +++ b/crates/turborepo-lib/src/commands/link.rs @@ -203,7 +203,7 @@ pub async fn link( .await .map_err(Error::TeamsRequest)?; - let selected_team = select_team(base, &teams_response.teams, user_display_name)?; + let selected_team = select_team(base, &teams_response.teams)?; let team_id = match selected_team { SelectedTeam::User => user_response.user.id.as_str(), @@ -288,18 +288,12 @@ pub async fn link( .await .map_err(Error::UserNotFound)?; - let user_display_name = user_response - .user - .name - .as_deref() - .unwrap_or(user_response.user.username.as_str()); - let teams_response = api_client .get_teams(token) .await .map_err(Error::TeamsRequest)?; - let selected_team = select_team(base, &teams_response.teams, user_display_name)?; + let selected_team = select_team(base, &teams_response.teams)?; let team_id = match selected_team { SelectedTeam::User => user_response.user.id.as_str(), @@ -382,28 +376,18 @@ fn should_enable_caching() -> Result { } #[cfg(test)] -fn select_team<'a>( - _: &CommandBase, - teams: &'a [Team], - _: &'a str, -) -> Result, Error> { +fn select_team<'a>(_: &CommandBase, teams: &'a [Team]) -> Result, Error> { let mut rng = rand::thread_rng(); - let idx = rng.gen_range(0..=(teams.len())); - if idx == teams.len() { - Ok(SelectedTeam::User) - } else { - Ok(SelectedTeam::Team(&teams[idx])) - } + let idx = rng.gen_range(0..(teams.len())); + Ok(SelectedTeam::Team(&teams[idx])) } #[cfg(not(test))] -fn select_team<'a>( - base: &CommandBase, - teams: &'a [Team], - user_display_name: &'a str, -) -> Result, Error> { - let mut team_names = vec![user_display_name]; - team_names.extend(teams.iter().map(|team| team.name.as_str())); +fn select_team<'a>(base: &CommandBase, teams: &'a [Team]) -> Result, Error> { + let team_names = teams + .iter() + .map(|team| team.name.as_str()) + .collect::>(); let theme = DialoguerTheme { active_item_style: Style::new().cyan().bold(), @@ -429,11 +413,7 @@ fn select_team<'a>( .interact() .map_err(Error::UserCanceled)?; - if selection == 0 { - Ok(SelectedTeam::User) - } else { - Ok(SelectedTeam::Team(&teams[selection - 1])) - } + Ok(SelectedTeam::Team(&teams[selection])) } #[cfg(test)]