From 0df4e9a4a707c473ff4fbbab1d37fa24e5244b40 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Wed, 29 May 2024 06:05:30 -0400 Subject: [PATCH] refactor: hard-code v1 API response It makes no different between depending on an arbitrary Git commit of rust-lang/team and inlining the responded JSON structure. --- Cargo.lock | 11 ----------- site/Cargo.toml | 1 - site/src/request_handlers/github.rs | 23 ++++++++++++++++++----- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4e9440d2d..c8cdf60b8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1109,7 +1109,6 @@ checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" dependencies = [ "equivalent", "hashbrown", - "serde", ] [[package]] @@ -2087,15 +2086,6 @@ dependencies = [ "walkdir", ] -[[package]] -name = "rust_team_data" -version = "1.0.0" -source = "git+https://github.com/rust-lang/team#89bb40d3dca1bd9a6c6dbc1b8cb2ddc1fcc932ad" -dependencies = [ - "indexmap", - "serde", -] - [[package]] name = "rustc-demangle" version = "0.1.23" @@ -2346,7 +2336,6 @@ dependencies = [ "ring", "rmp-serde", "rust-embed", - "rust_team_data", "ruzstd 0.6.0", "semver", "serde", diff --git a/site/Cargo.toml b/site/Cargo.toml index a67ad6bd3..d83c7aadb 100644 --- a/site/Cargo.toml +++ b/site/Cargo.toml @@ -27,7 +27,6 @@ regex = "1" lazy_static = "1" reqwest = { version = "0.11", features = ["json", "blocking"] } toml = "0.7" -rust_team_data = { git = "https://github.com/rust-lang/team" } parking_lot = "0.12" snap = "1" itertools = "0.10" diff --git a/site/src/request_handlers/github.rs b/site/src/request_handlers/github.rs index b99363868..ef776bb96 100644 --- a/site/src/request_handlers/github.rs +++ b/site/src/request_handlers/github.rs @@ -104,7 +104,9 @@ async fn handle_rust_timer( issue: github::Issue, ) -> ServerResult { if comment.author_association != github::Association::Owner - && !get_authorized_users().await?.contains(&comment.user.id) + && !get_authorized_users() + .await? + .contains(&(comment.user.id as _)) { main_client .post_comment( @@ -177,17 +179,28 @@ fn build_captures(comment_body: &str) -> impl Iterator Result, String> { - let url = format!("{}/permissions/perf.json", ::rust_team_data::v1::BASE_URL); +/// Gets GitHub user IDs authorized to use rust-timer. +/// +/// This data is fetched from the team V1 API. See: +/// +/// * [V1 API base URL](https://github.com/rust-lang/team/blob/28eb994c7334d84cbbfeda221af8555a9bac7a47/rust_team_data/src/v1.rs#L4) +/// * [`/permission/perf.json` endpoint](https://github.com/rust-lang/team/blob/28eb994c7334d84cbbfeda221af8555a9bac7a47/src/static_api.rs#L320-L328) +pub async fn get_authorized_users() -> Result, String> { + #[derive(serde::Deserialize)] + struct Permission { + github_ids: Vec, + } + + let url = "https://team-api.infra.rust-lang.org/v1/permissions/perf.json"; let client = reqwest::Client::new(); client - .get(&url) + .get(url) .send() .await .map_err(|err| format!("failed to fetch authorized users: {}", err))? .error_for_status() .map_err(|err| format!("failed to fetch authorized users: {}", err))? - .json::() + .json::() .await .map_err(|err| format!("failed to fetch authorized users: {}", err)) .map(|perms| perms.github_ids)