This commit is contained in:
parent
e42430d24b
commit
3a5fafc6c0
2 changed files with 61 additions and 37 deletions
|
@ -1,37 +1,68 @@
|
|||
use reqwest::{header::ACCEPT, Error};
|
||||
use ramhorns::Content;
|
||||
use reqwest::header::ACCEPT;
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::utils::get_reqwest_client;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct GithubResponse {
|
||||
pub total_count: u32,
|
||||
pub items: Vec<GithubProject>,
|
||||
struct GithubResponse {
|
||||
items: Vec<GithubProject>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct GithubProject {
|
||||
pub repository_url: String,
|
||||
pub number: u32,
|
||||
struct GithubProject {
|
||||
repository_url: String,
|
||||
number: u32,
|
||||
title: String,
|
||||
state: String,
|
||||
pull_request: GithubPullRequest,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
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 state: String,
|
||||
pub pull_request: GithubPullRequest,
|
||||
pub id: u32,
|
||||
pub contrib_url: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct GithubPullRequest {
|
||||
pub html_url: String,
|
||||
pub merged_at: Option<String>,
|
||||
}
|
||||
|
||||
pub async fn fetch_pr() -> Result<GithubResponse, Error> {
|
||||
pub async fn fetch_pr() -> Vec<Project> {
|
||||
// Result<GithubResponse, Error>
|
||||
let client = get_reqwest_client();
|
||||
|
||||
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?
|
||||
.await
|
||||
.unwrap()
|
||||
.json::<GithubResponse>()
|
||||
.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
|
||||
}
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
use crate::{config::Config, github::fetch_pr, template::Infos};
|
||||
use crate::{
|
||||
config::Config,
|
||||
github::{fetch_pr, Project},
|
||||
template::Infos,
|
||||
};
|
||||
use actix_web::{get, web, HttpResponse, Responder};
|
||||
use cached::proc_macro::once;
|
||||
use ramhorns::Content;
|
||||
|
@ -9,31 +13,20 @@ pub async fn page(config: web::Data<Config>) -> impl Responder {
|
|||
}
|
||||
|
||||
#[derive(Content)]
|
||||
struct PortfolioTemplate {}
|
||||
struct PortfolioTemplate {
|
||||
data: Vec<Project>,
|
||||
}
|
||||
|
||||
#[once(time = 60)]
|
||||
pub async fn get_page(config: Config) -> std::string::String {
|
||||
// Fetch latest data from github
|
||||
if let Ok(resp) = fetch_pr().await {
|
||||
println!("Nb: {}", resp.total_count);
|
||||
resp.items.iter().for_each(|x| {
|
||||
println!(
|
||||
"[{} #{}]({}) - {}",
|
||||
x.title,
|
||||
x.number,
|
||||
x.pull_request.html_url,
|
||||
if x.pull_request.merged_at.is_none() {
|
||||
&x.state
|
||||
} else {
|
||||
"merged"
|
||||
}
|
||||
)
|
||||
});
|
||||
};
|
||||
let projects = fetch_pr().await;
|
||||
|
||||
println!("{:#?}", projects);
|
||||
|
||||
config.tmpl.render(
|
||||
"contrib.html",
|
||||
PortfolioTemplate {},
|
||||
PortfolioTemplate { data: projects },
|
||||
Infos {
|
||||
page_title: Some("Mes contributions".to_string()),
|
||||
page_desc: Some("Contributions à l'opensource par Anri".to_string()),
|
||||
|
|
Loading…
Reference in a new issue