Skip to content

refactor: hard-code v1 API response #1914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion site/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
23 changes: 18 additions & 5 deletions site/src/request_handlers/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ async fn handle_rust_timer(
issue: github::Issue,
) -> ServerResult<github::Response> {
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(
Expand Down Expand Up @@ -177,17 +179,28 @@ fn build_captures(comment_body: &str) -> impl Iterator<Item = (&str, regex::Capt
})
}

pub async fn get_authorized_users() -> Result<Vec<usize>, 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<Vec<u64>, String> {
#[derive(serde::Deserialize)]
struct Permission {
github_ids: Vec<u64>,
}

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::<rust_team_data::v1::Permission>()
.json::<Permission>()
.await
.map_err(|err| format!("failed to fetch authorized users: {}", err))
.map(|perms| perms.github_ids)
Expand Down
Loading