Skip to content

Commit ec7adbb

Browse files
authored
team_repo: Query permission instead of team (#8047)
1 parent 0f26687 commit ec7adbb

File tree

3 files changed

+21
-32
lines changed

3 files changed

+21
-32
lines changed

src/team_repo.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,19 @@ use reqwest::{Certificate, Client};
1313
#[automock]
1414
#[async_trait]
1515
pub trait TeamRepo {
16-
async fn get_team(&self, name: &str) -> anyhow::Result<Team>;
16+
async fn get_permission(&self, name: &str) -> anyhow::Result<Permission>;
1717
}
1818

1919
#[derive(Debug, Clone, Deserialize)]
20-
pub struct Team {
21-
pub name: String,
22-
pub kind: String,
23-
pub members: Vec<Member>,
20+
pub struct Permission {
21+
pub people: Vec<Person>,
2422
}
2523

2624
#[derive(Debug, Clone, Deserialize)]
27-
pub struct Member {
25+
pub struct Person {
2826
pub name: String,
2927
pub github: String,
3028
pub github_id: i32,
31-
pub is_lead: bool,
3229
}
3330

3431
pub struct TeamRepoImpl {
@@ -62,8 +59,8 @@ fn build_client() -> Client {
6259

6360
#[async_trait]
6461
impl TeamRepo for TeamRepoImpl {
65-
async fn get_team(&self, name: &str) -> anyhow::Result<Team> {
66-
let url = format!("https://team-api.infra.rust-lang.org/v1/teams/{name}.json");
62+
async fn get_permission(&self, name: &str) -> anyhow::Result<Permission> {
63+
let url = format!("https://team-api.infra.rust-lang.org/v1/permissions/{name}.json");
6764
let response = self.client.get(url).send().await?.error_for_status()?;
6865
Ok(response.json().await?)
6966
}

src/tests/worker/sync_admins.rs

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::util::TestApp;
22
use crates_io::schema::{emails, users};
3-
use crates_io::team_repo::{Member, MockTeamRepo, Team};
3+
use crates_io::team_repo::{MockTeamRepo, Permission, Person};
44
use crates_io::worker::jobs::SyncAdmins;
55
use crates_io_worker::BackgroundJob;
66
use diesel::prelude::*;
@@ -10,19 +10,16 @@ use regex::Regex;
1010

1111
#[test]
1212
fn test_sync_admins_job() {
13-
let mock_response = mock_team(
14-
"crates-io",
15-
vec![
16-
mock_member("existing-admin", 1),
17-
mock_member("new-admin", 3),
18-
mock_member("new-admin-without-account", 4),
19-
],
20-
);
13+
let mock_response = mock_permission(vec![
14+
mock_person("existing-admin", 1),
15+
mock_person("new-admin", 3),
16+
mock_person("new-admin-without-account", 4),
17+
]);
2118

2219
let mut team_repo = MockTeamRepo::new();
2320
team_repo
24-
.expect_get_team()
25-
.with(mockall::predicate::eq("crates-io-admins"))
21+
.expect_get_permission()
22+
.with(mockall::predicate::eq("crates_io_admin"))
2623
.returning(move |_| Ok(mock_response.clone()));
2724

2825
let (app, _) = TestApp::full().with_team_repo(team_repo).empty();
@@ -61,22 +58,17 @@ fn test_sync_admins_job() {
6158
assert_eq!(emails.len(), 2);
6259
}
6360

64-
fn mock_team(name: impl Into<String>, members: Vec<Member>) -> Team {
65-
Team {
66-
name: name.into(),
67-
kind: "marker-team".to_string(),
68-
members,
69-
}
61+
fn mock_permission(people: Vec<Person>) -> Permission {
62+
Permission { people }
7063
}
7164

72-
fn mock_member(name: impl Into<String>, github_id: i32) -> Member {
65+
fn mock_person(name: impl Into<String>, github_id: i32) -> Person {
7366
let name = name.into();
7467
let github = name.clone();
75-
Member {
68+
Person {
7669
name,
7770
github,
7871
github_id,
79-
is_lead: false,
8072
}
8173
}
8274

src/worker/jobs/sync_admins.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use std::collections::HashSet;
99
use std::fmt::{Display, Formatter};
1010
use std::sync::Arc;
1111

12-
/// See <https://github.com/rust-lang/team/blob/master/teams/crates-io-admins.toml>.
13-
const TEAM_NAME: &str = "crates-io-admins";
12+
/// See <https://github.com/rust-lang/team/pull/1197>.
13+
const PERMISSION_NAME: &str = "crates_io_admin";
1414

1515
#[derive(Serialize, Deserialize)]
1616
pub struct SyncAdmins;
@@ -23,7 +23,7 @@ impl BackgroundJob for SyncAdmins {
2323
async fn run(&self, ctx: Self::Context) -> anyhow::Result<()> {
2424
info!("Syncing admins from rust-lang/team repo…");
2525

26-
let repo_admins = ctx.team_repo.get_team(TEAM_NAME).await?.members;
26+
let repo_admins = ctx.team_repo.get_permission(PERMISSION_NAME).await?.people;
2727
let repo_admin_ids = repo_admins
2828
.iter()
2929
.map(|m| m.github_id)

0 commit comments

Comments
 (0)