use ramhorns::Content; use reqwest::header::ACCEPT; use serde::Deserialize; use crate::utils::get_reqwest_client; #[derive(Deserialize)] struct GithubResponse { items: Vec, } #[derive(Deserialize)] struct GithubProject { repository_url: String, number: u32, title: String, state: String, pull_request: GithubPullRequest, } #[derive(Deserialize)] struct GithubPullRequest { html_url: String, merged_at: Option, } #[derive(Content, Debug)] pub struct Project { pub project: String, pub project_url: String, pub status: String, pub title: String, pub id: u32, pub contrib_url: String, } pub async fn fetch_pr() -> Vec { // Result let client = get_reqwest_client(); let resp = client .get("https://api.github.com/search/issues?q=is:pr%20author:Mylloon") .header(ACCEPT, "application/vnd.github.text-match+json") .send() .await .unwrap() .json::() .await .unwrap(); let mut list = vec![]; resp.items.iter().for_each(|p| { list.push(Project { project: p.repository_url.split('/').last().unwrap().to_string(), project_url: p.repository_url.clone(), status: if p.pull_request.merged_at.is_none() { p.state.clone() } else { "merged".to_string() }, title: p.title.clone(), id: p.number, contrib_url: p.pull_request.html_url.clone(), }); }); list }