2023-04-12 00:56:39 +02:00
|
|
|
use core::panic;
|
|
|
|
|
2023-04-11 23:26:54 +02:00
|
|
|
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>,
|
|
|
|
}
|
|
|
|
|
2023-04-12 00:56:39 +02:00
|
|
|
#[derive(Clone, Copy)]
|
|
|
|
pub enum ProjectState {
|
|
|
|
Closed = 0,
|
|
|
|
Open = 1,
|
|
|
|
Merged = 2,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<u8> for ProjectState {
|
|
|
|
fn from(orig: u8) -> Self {
|
|
|
|
match orig {
|
|
|
|
0 => Self::Closed,
|
|
|
|
1 => Self::Open,
|
|
|
|
2 => Self::Merged,
|
|
|
|
_ => panic!(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-11 23:26:54 +02:00
|
|
|
pub struct Project {
|
|
|
|
pub project: String,
|
|
|
|
pub project_url: String,
|
2023-04-12 00:56:39 +02:00
|
|
|
pub status: ProjectState,
|
2023-04-11 23:26:54 +02:00
|
|
|
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() {
|
2023-04-12 00:56:39 +02:00
|
|
|
if p.state == "closed" {
|
|
|
|
ProjectState::Closed
|
|
|
|
} else {
|
|
|
|
ProjectState::Open
|
|
|
|
}
|
2023-04-11 23:26:54 +02:00
|
|
|
} else {
|
2023-04-12 00:56:39 +02:00
|
|
|
ProjectState::Merged
|
2023-04-11 23:26:54 +02:00
|
|
|
},
|
|
|
|
title: p.title.clone(),
|
|
|
|
id: p.number,
|
|
|
|
contrib_url: p.pull_request.html_url.clone(),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
list
|
2023-04-11 22:45:44 +02:00
|
|
|
}
|