Skip to content

Commit

Permalink
Fix outdated user listing. (#8526)
Browse files Browse the repository at this point in the history
### 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`.
  • Loading branch information
anthonyshew authored Jun 18, 2024
1 parent 4710617 commit 34f8ff4
Showing 1 changed file with 11 additions and 31 deletions.
42 changes: 11 additions & 31 deletions crates/turborepo-lib/src/commands/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -382,28 +376,18 @@ fn should_enable_caching() -> Result<bool, Error> {
}

#[cfg(test)]
fn select_team<'a>(
_: &CommandBase,
teams: &'a [Team],
_: &'a str,
) -> Result<SelectedTeam<'a>, Error> {
fn select_team<'a>(_: &CommandBase, teams: &'a [Team]) -> Result<SelectedTeam<'a>, 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<SelectedTeam<'a>, 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<SelectedTeam<'a>, Error> {
let team_names = teams
.iter()
.map(|team| team.name.as_str())
.collect::<Vec<_>>();

let theme = DialoguerTheme {
active_item_style: Style::new().cyan().bold(),
Expand All @@ -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)]
Expand Down

0 comments on commit 34f8ff4

Please sign in to comment.