mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-11 04:36:24 +00:00
parent
0fdc9d0f05
commit
9ef3306f55
1 changed files with 40 additions and 11 deletions
|
@ -44,6 +44,17 @@ pub async fn seed(config: &Config, db: &Database, force: bool) -> anyhow::Result
|
|||
let mut first_user = None;
|
||||
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 {
|
||||
let user = fetch_github::<GitHubUser>(
|
||||
&client,
|
||||
|
@ -66,6 +77,15 @@ pub async fn seed(config: &Config, db: &Database, force: bool) -> anyhow::Result
|
|||
} else {
|
||||
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 {
|
||||
|
@ -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 {
|
||||
// Fetch 100 other random users from GitHub and insert them into the database
|
||||
// (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 {
|
||||
last_user_id = Some(github_user.id);
|
||||
user_count += 1;
|
||||
db.get_or_create_user_by_github_account(
|
||||
&github_user.login,
|
||||
Some(github_user.id),
|
||||
github_user.email.as_deref(),
|
||||
Some(github_user.created_at),
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.expect("failed to insert user");
|
||||
let user = db
|
||||
.get_or_create_user_by_github_account(
|
||||
&github_user.login,
|
||||
Some(github_user.id),
|
||||
github_user.email.as_deref(),
|
||||
Some(github_user.created_at),
|
||||
None,
|
||||
)
|
||||
.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")
|
||||
.send()
|
||||
.await
|
||||
.unwrap_or_else(|_| panic!("failed to fetch '{}'", url));
|
||||
.unwrap_or_else(|_| panic!("failed to fetch '{url}'"));
|
||||
response
|
||||
.json()
|
||||
.await
|
||||
.unwrap_or_else(|_| panic!("failed to deserialize github user from '{}'", url))
|
||||
.unwrap_or_else(|_| panic!("failed to deserialize github user from '{url}'"))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue