use failure::{Error, ResultExt}; use reqwest::header::{AUTHORIZATION, USER_AGENT}; use reqwest::{Client, Error as HttpError, RequestBuilder, Response, StatusCode}; use std::io::Read; #[derive(Debug, serde::Deserialize)] pub struct User { pub login: String, } impl User { pub fn current(client: &GithubClient) -> Result { Ok(client .get("https://api.github.com/user") .send_req()? .json()?) } pub fn is_team_member(&self, client: &GithubClient) -> Result { let client = client.raw(); let url = format!("{}/teams.json", rust_team_data::v1::BASE_URL); let permission: rust_team_data::v1::Teams = client .get(&url) .send() .and_then(Response::error_for_status) .and_then(|mut r| r.json()) .context("could not get team data")?; let map = permission.teams; Ok(map["all"].members.iter().any(|g| g.github == self.login)) } } #[derive(Debug, Clone, serde::Deserialize)] pub struct Label { pub name: String, } impl Label { fn exists(&self, repo_api_prefix: &str, client: &GithubClient) -> bool { #[allow(clippy::redundant_pattern_matching)] match client .get(&format!("{}/labels/{}", repo_api_prefix, self.name)) .send_req() { Ok(_) => true, // XXX: Error handling if the request failed for reasons beyond 'label didn't exist' Err(_) => false, } } } #[derive(Debug, serde::Deserialize)] pub struct Issue { pub number: u64, title: String, user: User, labels: Vec