This commit is contained in:
parent
cfe0620aa9
commit
addf6e0035
3 changed files with 74 additions and 61 deletions
|
@ -1,6 +1,6 @@
|
||||||
use core::panic;
|
use core::panic;
|
||||||
|
|
||||||
use reqwest::header::ACCEPT;
|
use reqwest::{header::ACCEPT, Error};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
use crate::utils::get_reqwest_client;
|
use crate::utils::get_reqwest_client;
|
||||||
|
@ -52,7 +52,7 @@ pub struct Project {
|
||||||
pub contrib_url: String,
|
pub contrib_url: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn fetch_pr() -> Vec<Project> {
|
pub async fn fetch_pr() -> Result<Vec<Project>, Error> {
|
||||||
// Result<GithubResponse, Error>
|
// Result<GithubResponse, Error>
|
||||||
let client = get_reqwest_client();
|
let client = get_reqwest_client();
|
||||||
|
|
||||||
|
@ -60,11 +60,9 @@ pub async fn fetch_pr() -> Vec<Project> {
|
||||||
.get("https://api.github.com/search/issues?q=is:pr%20author:Mylloon")
|
.get("https://api.github.com/search/issues?q=is:pr%20author:Mylloon")
|
||||||
.header(ACCEPT, "application/vnd.github.text-match+json")
|
.header(ACCEPT, "application/vnd.github.text-match+json")
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await?
|
||||||
.unwrap()
|
|
||||||
.json::<GithubResponse>()
|
.json::<GithubResponse>()
|
||||||
.await
|
.await?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let mut list = vec![];
|
let mut list = vec![];
|
||||||
resp.items.iter().for_each(|p| {
|
resp.items.iter().for_each(|p| {
|
||||||
|
@ -86,5 +84,5 @@ pub async fn fetch_pr() -> Vec<Project> {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
list
|
Ok(list)
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ pub async fn page(config: web::Data<Config>) -> impl Responder {
|
||||||
|
|
||||||
#[derive(Content)]
|
#[derive(Content)]
|
||||||
struct PortfolioTemplate {
|
struct PortfolioTemplate {
|
||||||
|
error: bool,
|
||||||
projects: Vec<Project>,
|
projects: Vec<Project>,
|
||||||
waiting: Vec<Project>,
|
waiting: Vec<Project>,
|
||||||
closed: Vec<Project>,
|
closed: Vec<Project>,
|
||||||
|
@ -41,65 +42,76 @@ struct Pull {
|
||||||
#[once(time = 120)]
|
#[once(time = 120)]
|
||||||
pub async fn get_page(config: Config) -> std::string::String {
|
pub async fn get_page(config: Config) -> std::string::String {
|
||||||
// Fetch latest data from github
|
// Fetch latest data from github
|
||||||
let projects = fetch_pr().await;
|
let data = match fetch_pr().await {
|
||||||
|
Ok(projects) => {
|
||||||
let mut data: Vec<Project> = Vec::new();
|
let mut data: Vec<Project> = Vec::new();
|
||||||
let mut map: HashMap<&str, Vec<Pull>> = HashMap::new();
|
let mut map: HashMap<&str, Vec<Pull>> = HashMap::new();
|
||||||
projects.iter().for_each(|p| {
|
projects.iter().for_each(|p| {
|
||||||
let project = Pull {
|
let project = Pull {
|
||||||
url: p.contrib_url.clone(),
|
url: p.contrib_url.clone(),
|
||||||
id: p.id,
|
id: p.id,
|
||||||
name: p.project.clone(),
|
name: p.project.clone(),
|
||||||
state: p.status as u8,
|
state: p.status as u8,
|
||||||
};
|
};
|
||||||
let project_name = p.project.as_str();
|
let project_name = p.project.as_str();
|
||||||
if map.contains_key(project_name) {
|
if map.contains_key(project_name) {
|
||||||
map.entry(project_name).and_modify(|v| v.push(project));
|
map.entry(project_name).and_modify(|v| v.push(project));
|
||||||
} else {
|
} else {
|
||||||
data.push(Project {
|
data.push(Project {
|
||||||
name: project_name.to_string(),
|
name: project_name.to_string(),
|
||||||
url: p.project_url.clone(),
|
url: p.project_url.clone(),
|
||||||
pulls_merged: Vec::new(),
|
pulls_merged: Vec::new(),
|
||||||
pulls_closed: Vec::new(),
|
pulls_closed: Vec::new(),
|
||||||
pulls_open: Vec::new(),
|
pulls_open: Vec::new(),
|
||||||
|
});
|
||||||
|
map.insert(project_name, vec![project]);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
map.insert(project_name, vec![project]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
data.iter_mut().for_each(|d| {
|
data.iter_mut().for_each(|d| {
|
||||||
map.get(d.name.as_str()).unwrap().iter().for_each(|p| {
|
map.get(d.name.as_str()).unwrap().iter().for_each(|p| {
|
||||||
let state = p.state.into();
|
let state = p.state.into();
|
||||||
match state {
|
match state {
|
||||||
ProjectState::Closed => d.pulls_closed.push(p.clone()),
|
ProjectState::Closed => d.pulls_closed.push(p.clone()),
|
||||||
ProjectState::Merged => d.pulls_merged.push(p.clone()),
|
ProjectState::Merged => d.pulls_merged.push(p.clone()),
|
||||||
ProjectState::Open => d.pulls_open.push(p.clone()),
|
ProjectState::Open => d.pulls_open.push(p.clone()),
|
||||||
|
}
|
||||||
|
});
|
||||||
|
let mut name: Vec<char> = d.name.replace('-', " ").chars().collect();
|
||||||
|
name[0] = name[0].to_uppercase().next().unwrap();
|
||||||
|
d.name = name.into_iter().collect();
|
||||||
|
});
|
||||||
|
|
||||||
|
PortfolioTemplate {
|
||||||
|
error: false,
|
||||||
|
projects: data
|
||||||
|
.iter()
|
||||||
|
.cloned()
|
||||||
|
.filter(|p| !p.pulls_merged.is_empty())
|
||||||
|
.collect(),
|
||||||
|
waiting: data
|
||||||
|
.iter()
|
||||||
|
.cloned()
|
||||||
|
.filter(|p| !p.pulls_open.is_empty())
|
||||||
|
.collect(),
|
||||||
|
closed: data
|
||||||
|
.iter()
|
||||||
|
.cloned()
|
||||||
|
.filter(|p| !p.pulls_closed.is_empty())
|
||||||
|
.collect(),
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
let mut name: Vec<char> = d.name.replace('-', " ").chars().collect();
|
Err(_) => PortfolioTemplate {
|
||||||
name[0] = name[0].to_uppercase().next().unwrap();
|
error: true,
|
||||||
d.name = name.into_iter().collect();
|
projects: Vec::new(),
|
||||||
});
|
waiting: Vec::new(),
|
||||||
|
closed: Vec::new(),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
config.tmpl.render(
|
config.tmpl.render(
|
||||||
"contrib.html",
|
"contrib.html",
|
||||||
PortfolioTemplate {
|
data,
|
||||||
projects: data
|
|
||||||
.iter()
|
|
||||||
.cloned()
|
|
||||||
.filter(|p| !p.pulls_merged.is_empty())
|
|
||||||
.collect(),
|
|
||||||
waiting: data
|
|
||||||
.iter()
|
|
||||||
.cloned()
|
|
||||||
.filter(|p| !p.pulls_open.is_empty())
|
|
||||||
.collect(),
|
|
||||||
closed: data
|
|
||||||
.iter()
|
|
||||||
.cloned()
|
|
||||||
.filter(|p| !p.pulls_closed.is_empty())
|
|
||||||
.collect(),
|
|
||||||
},
|
|
||||||
Infos {
|
Infos {
|
||||||
page_title: Some("Mes contributions".to_string()),
|
page_title: Some("Mes contributions".to_string()),
|
||||||
page_desc: Some("Contributions à l'opensource par Anri".to_string()),
|
page_desc: Some("Contributions à l'opensource par Anri".to_string()),
|
||||||
|
|
|
@ -4,6 +4,9 @@
|
||||||
<body>
|
<body>
|
||||||
{{#data}}
|
{{#data}}
|
||||||
<div id="content">
|
<div id="content">
|
||||||
|
{{#error}}
|
||||||
|
<p>Github ne veut pas que tu vois ces informations...</p>
|
||||||
|
{{/error}} {{^error}}
|
||||||
<h1 class="subtitle">Mes contributions</h1>
|
<h1 class="subtitle">Mes contributions</h1>
|
||||||
<!-- Add URL? -->
|
<!-- Add URL? -->
|
||||||
{{#projects}}
|
{{#projects}}
|
||||||
|
@ -31,6 +34,6 @@
|
||||||
</p>
|
</p>
|
||||||
{{/closed}}
|
{{/closed}}
|
||||||
</div>
|
</div>
|
||||||
{{/data}} {{> footer.html }}
|
{{/error}} {{/data}} {{> footer.html }}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in a new issue