mylloon.fr/src/misc/github.rs

69 lines
1.6 KiB
Rust
Raw Normal View History

2023-04-11 23:26:54 +02:00
use ramhorns::Content;
use reqwest::header::ACCEPT;
2023-04-11 22:45:44 +02:00
use serde::Deserialize;
use crate::utils::get_reqwest_client;
#[derive(Deserialize)]
2023-04-11 23:26:54 +02:00
struct GithubResponse {
items: Vec<GithubProject>,
2023-04-11 22:45:44 +02:00
}
#[derive(Deserialize)]
2023-04-11 23:26:54 +02:00
struct GithubProject {
repository_url: String,
number: u32,
title: String,
state: String,
pull_request: GithubPullRequest,
2023-04-11 23:08:45 +02:00
}
#[derive(Deserialize)]
2023-04-11 23:26:54 +02:00
struct GithubPullRequest {
html_url: String,
merged_at: Option<String>,
}
#[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,
2023-04-11 22:45:44 +02:00
}
2023-04-11 23:26:54 +02:00
pub async fn fetch_pr() -> Vec<Project> {
// Result<GithubResponse, Error>
2023-04-11 22:45:44 +02:00
let client = get_reqwest_client();
2023-04-11 23:26:54 +02:00
let resp = client
2023-04-11 22:45:44 +02:00
.get("https://api.github.com/search/issues?q=is:pr%20author:Mylloon")
.header(ACCEPT, "application/vnd.github.text-match+json")
.send()
2023-04-11 23:26:54 +02:00
.await
.unwrap()
2023-04-11 22:45:44 +02:00
.json::<GithubResponse>()
.await
2023-04-11 23:26:54 +02:00
.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
2023-04-11 22:45:44 +02:00
}