diff --git a/src/team_repo.rs b/src/team_repo.rs index 80565677d38..e8b3da762b9 100644 --- a/src/team_repo.rs +++ b/src/team_repo.rs @@ -13,22 +13,19 @@ use reqwest::{Certificate, Client}; #[automock] #[async_trait] pub trait TeamRepo { - async fn get_team(&self, name: &str) -> anyhow::Result; + async fn get_permission(&self, name: &str) -> anyhow::Result; } #[derive(Debug, Clone, Deserialize)] -pub struct Team { - pub name: String, - pub kind: String, - pub members: Vec, +pub struct Permission { + pub people: Vec, } #[derive(Debug, Clone, Deserialize)] -pub struct Member { +pub struct Person { pub name: String, pub github: String, pub github_id: i32, - pub is_lead: bool, } pub struct TeamRepoImpl { @@ -62,8 +59,8 @@ fn build_client() -> Client { #[async_trait] impl TeamRepo for TeamRepoImpl { - async fn get_team(&self, name: &str) -> anyhow::Result { - let url = format!("https://team-api.infra.rust-lang.org/v1/teams/{name}.json"); + async fn get_permission(&self, name: &str) -> anyhow::Result { + let url = format!("https://team-api.infra.rust-lang.org/v1/permissions/{name}.json"); let response = self.client.get(url).send().await?.error_for_status()?; Ok(response.json().await?) } diff --git a/src/tests/worker/sync_admins.rs b/src/tests/worker/sync_admins.rs index bc2e0216ab3..2f1af4c0cf5 100644 --- a/src/tests/worker/sync_admins.rs +++ b/src/tests/worker/sync_admins.rs @@ -1,6 +1,6 @@ use crate::util::TestApp; use crates_io::schema::{emails, users}; -use crates_io::team_repo::{Member, MockTeamRepo, Team}; +use crates_io::team_repo::{MockTeamRepo, Permission, Person}; use crates_io::worker::jobs::SyncAdmins; use crates_io_worker::BackgroundJob; use diesel::prelude::*; @@ -10,19 +10,16 @@ use regex::Regex; #[test] fn test_sync_admins_job() { - let mock_response = mock_team( - "crates-io", - vec![ - mock_member("existing-admin", 1), - mock_member("new-admin", 3), - mock_member("new-admin-without-account", 4), - ], - ); + let mock_response = mock_permission(vec![ + mock_person("existing-admin", 1), + mock_person("new-admin", 3), + mock_person("new-admin-without-account", 4), + ]); let mut team_repo = MockTeamRepo::new(); team_repo - .expect_get_team() - .with(mockall::predicate::eq("crates-io-admins")) + .expect_get_permission() + .with(mockall::predicate::eq("crates_io_admin")) .returning(move |_| Ok(mock_response.clone())); let (app, _) = TestApp::full().with_team_repo(team_repo).empty(); @@ -61,22 +58,17 @@ fn test_sync_admins_job() { assert_eq!(emails.len(), 2); } -fn mock_team(name: impl Into, members: Vec) -> Team { - Team { - name: name.into(), - kind: "marker-team".to_string(), - members, - } +fn mock_permission(people: Vec) -> Permission { + Permission { people } } -fn mock_member(name: impl Into, github_id: i32) -> Member { +fn mock_person(name: impl Into, github_id: i32) -> Person { let name = name.into(); let github = name.clone(); - Member { + Person { name, github, github_id, - is_lead: false, } } diff --git a/src/worker/jobs/sync_admins.rs b/src/worker/jobs/sync_admins.rs index e89582114c0..174dc23a235 100644 --- a/src/worker/jobs/sync_admins.rs +++ b/src/worker/jobs/sync_admins.rs @@ -9,8 +9,8 @@ use std::collections::HashSet; use std::fmt::{Display, Formatter}; use std::sync::Arc; -/// See . -const TEAM_NAME: &str = "crates-io-admins"; +/// See . +const PERMISSION_NAME: &str = "crates_io_admin"; #[derive(Serialize, Deserialize)] pub struct SyncAdmins; @@ -23,7 +23,7 @@ impl BackgroundJob for SyncAdmins { async fn run(&self, ctx: Self::Context) -> anyhow::Result<()> { info!("Syncing admins from rust-lang/team repo…"); - let repo_admins = ctx.team_repo.get_team(TEAM_NAME).await?.members; + let repo_admins = ctx.team_repo.get_permission(PERMISSION_NAME).await?.people; let repo_admin_ids = repo_admins .iter() .map(|m| m.github_id)