Add feature flags to seed script (#16385)

Release Notes:

- N/A
This commit is contained in:
Joseph T. Lyons 2024-08-16 17:08:44 -04:00 committed by GitHub
parent 0fdc9d0f05
commit 9ef3306f55
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -44,6 +44,17 @@ pub async fn seed(config: &Config, db: &Database, force: bool) -> anyhow::Result
let mut first_user = None; let mut first_user = None;
let mut others = vec![]; let mut others = vec![];
let flag_names = ["remoting", "language-models"];
let mut flags = Vec::new();
for flag_name in flag_names {
let flag = db
.create_user_flag(flag_name, false)
.await
.unwrap_or_else(|_| panic!("failed to create flag: '{flag_name}'"));
flags.push(flag);
}
for admin_login in seed_config.admins { for admin_login in seed_config.admins {
let user = fetch_github::<GitHubUser>( let user = fetch_github::<GitHubUser>(
&client, &client,
@ -66,6 +77,15 @@ pub async fn seed(config: &Config, db: &Database, force: bool) -> anyhow::Result
} else { } else {
others.push(user.user_id) others.push(user.user_id)
} }
for flag in &flags {
db.add_user_flag(user.user_id, *flag)
.await
.context(format!(
"Unable to enable flag '{}' for user '{}'",
flag, user.user_id
))?;
}
} }
for channel in seed_config.channels { for channel in seed_config.channels {
@ -86,6 +106,7 @@ pub async fn seed(config: &Config, db: &Database, force: bool) -> anyhow::Result
} }
} }
// TODO: Fix this later
if let Some(number_of_users) = seed_config.number_of_users { if let Some(number_of_users) = seed_config.number_of_users {
// Fetch 100 other random users from GitHub and insert them into the database // Fetch 100 other random users from GitHub and insert them into the database
// (for testing autocompleters, etc.) // (for testing autocompleters, etc.)
@ -105,15 +126,23 @@ pub async fn seed(config: &Config, db: &Database, force: bool) -> anyhow::Result
for github_user in users { for github_user in users {
last_user_id = Some(github_user.id); last_user_id = Some(github_user.id);
user_count += 1; user_count += 1;
db.get_or_create_user_by_github_account( let user = db
&github_user.login, .get_or_create_user_by_github_account(
Some(github_user.id), &github_user.login,
github_user.email.as_deref(), Some(github_user.id),
Some(github_user.created_at), github_user.email.as_deref(),
None, Some(github_user.created_at),
) None,
.await )
.expect("failed to insert user"); .await
.expect("failed to insert user");
for flag in &flags {
db.add_user_flag(user.id, *flag).await.context(format!(
"Unable to enable flag '{}' for user '{}'",
flag, user.id
))?;
}
} }
} }
} }
@ -132,9 +161,9 @@ async fn fetch_github<T: DeserializeOwned>(client: &reqwest::Client, url: &str)
.header("user-agent", "zed") .header("user-agent", "zed")
.send() .send()
.await .await
.unwrap_or_else(|_| panic!("failed to fetch '{}'", url)); .unwrap_or_else(|_| panic!("failed to fetch '{url}'"));
response response
.json() .json()
.await .await
.unwrap_or_else(|_| panic!("failed to deserialize github user from '{}'", url)) .unwrap_or_else(|_| panic!("failed to deserialize github user from '{url}'"))
} }