2023-04-12 00:56:39 +02:00
|
|
|
use core::panic;
|
|
|
|
|
2023-04-12 01:21:07 +02:00
|
|
|
use reqwest::{header::ACCEPT, Error};
|
2023-04-11 22:45:44 +02:00
|
|
|
use serde::Deserialize;
|
|
|
|
|
2023-04-14 11:44:49 +02:00
|
|
|
use crate::misc::utils::get_reqwest_client;
|
2023-04-11 22:45:44 +02:00
|
|
|
|
|
|
|
#[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-12 01:21:07 +02:00
|
|
|
pub async fn fetch_pr() -> Result<Vec<Project>, Error> {
|
2023-04-11 23:26:54 +02:00
|
|
|
// 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-12 01:21:07 +02:00
|
|
|
.await?
|
2023-04-11 22:45:44 +02:00
|
|
|
.json::<GithubResponse>()
|
2023-04-12 01:21:07 +02:00
|
|
|
.await?;
|
2023-04-11 23:26:54 +02:00
|
|
|
|
|
|
|
let mut list = vec![];
|
|
|
|
resp.items.iter().for_each(|p| {
|
|
|
|
list.push(Project {
|
2023-04-21 19:22:00 +02:00
|
|
|
project: p.repository_url.split('/').last().unwrap().to_owned(),
|
2023-04-24 12:18:21 +02:00
|
|
|
project_url: p.repository_url.to_owned(),
|
2023-04-11 23:26:54 +02:00
|
|
|
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
|
|
|
},
|
2023-04-24 12:18:21 +02:00
|
|
|
title: p.title.to_owned(),
|
2023-04-11 23:26:54 +02:00
|
|
|
id: p.number,
|
2023-04-24 12:18:21 +02:00
|
|
|
contrib_url: p.pull_request.html_url.to_owned(),
|
2023-04-11 23:26:54 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-04-12 01:21:07 +02:00
|
|
|
Ok(list)
|
2023-04-11 22:45:44 +02:00
|
|
|
}
|