collab: Set github_user_created_at
when seeding GitHub users (#17178)
This PR updates the seed script to set the `github_user_created_at` value for each GitHub user. Release Notes: - N/A
This commit is contained in:
parent
58c0f39714
commit
9a8c301a7d
1 changed files with 6 additions and 4 deletions
|
@ -1,6 +1,7 @@
|
||||||
use crate::db::{self, ChannelRole, NewUserParams};
|
use crate::db::{self, ChannelRole, NewUserParams};
|
||||||
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
|
use chrono::{DateTime, Utc};
|
||||||
use db::Database;
|
use db::Database;
|
||||||
use serde::{de::DeserializeOwned, Deserialize};
|
use serde::{de::DeserializeOwned, Deserialize};
|
||||||
use std::{fmt::Write, fs, path::Path};
|
use std::{fmt::Write, fs, path::Path};
|
||||||
|
@ -8,10 +9,11 @@ use std::{fmt::Write, fs, path::Path};
|
||||||
use crate::Config;
|
use crate::Config;
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
struct GitHubUser {
|
struct GithubUser {
|
||||||
id: i32,
|
id: i32,
|
||||||
login: String,
|
login: String,
|
||||||
email: Option<String>,
|
email: Option<String>,
|
||||||
|
created_at: DateTime<Utc>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
@ -54,7 +56,7 @@ pub async fn seed(config: &Config, db: &Database, force: bool) -> anyhow::Result
|
||||||
}
|
}
|
||||||
|
|
||||||
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,
|
||||||
&format!("https://api.github.com/users/{admin_login}"),
|
&format!("https://api.github.com/users/{admin_login}"),
|
||||||
)
|
)
|
||||||
|
@ -119,7 +121,7 @@ pub async fn seed(config: &Config, db: &Database, force: bool) -> anyhow::Result
|
||||||
if let Some(last_user_id) = last_user_id {
|
if let Some(last_user_id) = last_user_id {
|
||||||
write!(&mut uri, "&since={}", last_user_id).unwrap();
|
write!(&mut uri, "&since={}", last_user_id).unwrap();
|
||||||
}
|
}
|
||||||
let users = fetch_github::<Vec<GitHubUser>>(&client, &uri).await;
|
let users = fetch_github::<Vec<GithubUser>>(&client, &uri).await;
|
||||||
|
|
||||||
for github_user in users {
|
for github_user in users {
|
||||||
last_user_id = Some(github_user.id);
|
last_user_id = Some(github_user.id);
|
||||||
|
@ -129,7 +131,7 @@ pub async fn seed(config: &Config, db: &Database, force: bool) -> anyhow::Result
|
||||||
&github_user.login,
|
&github_user.login,
|
||||||
github_user.id,
|
github_user.id,
|
||||||
github_user.email.as_deref(),
|
github_user.email.as_deref(),
|
||||||
None,
|
Some(github_user.created_at),
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue