wip contrib logic
Some checks are pending
ci/woodpecker/push/publish Pipeline is pending

This commit is contained in:
Mylloon 2023-04-12 01:04:16 +02:00
parent a76bdc867c
commit a50d894926
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 86 additions and 58 deletions

View file

@ -1,6 +1,8 @@
use std::collections::HashMap;
use crate::{ use crate::{
config::Config, config::Config,
github::{fetch_pr, Project}, github::{fetch_pr, ProjectState},
template::Infos, template::Infos,
}; };
use actix_web::{get, web, HttpResponse, Responder}; use actix_web::{get, web, HttpResponse, Responder};
@ -14,19 +16,78 @@ pub async fn page(config: web::Data<Config>) -> impl Responder {
#[derive(Content)] #[derive(Content)]
struct PortfolioTemplate { struct PortfolioTemplate {
data: Vec<Project>, projects: Vec<Project>,
waiting: Vec<Project>,
closed: Vec<Project>,
} }
#[once(time = 60)] #[derive(Content)]
struct Project {
name: String,
url: String,
pulls_merged: Vec<Pull>,
pulls_open: Vec<Pull>,
pulls_closed: Vec<Pull>,
}
#[derive(Content, Clone)]
struct Pull {
url: String,
id: u32,
name: String,
state: u8,
}
#[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 projects = fetch_pr().await;
println!("{:#?}", projects); let mut data: Vec<Project> = Vec::new();
let mut map: HashMap<&str, Vec<Pull>> = HashMap::new();
projects.iter().for_each(|p| {
let project = Pull {
url: p.contrib_url.clone(),
id: p.id,
name: p.project.clone(),
state: p.status as u8,
};
let project_name = p.project.as_str();
if map.contains_key(project_name) {
map.entry(project_name).and_modify(|v| v.push(project));
} else {
data.push(Project {
name: project_name.to_string(),
url: p.project_url.clone(),
pulls_merged: Vec::new(),
pulls_closed: Vec::new(),
pulls_open: Vec::new(),
});
map.insert(project_name, vec![project]);
}
});
data.iter_mut().for_each(|d| {
map.get(d.name.as_str()).unwrap().iter().for_each(|p| {
let state = p.state.into();
match state {
ProjectState::Closed => d.pulls_closed.push(p.clone()),
ProjectState::Merged => d.pulls_merged.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();
});
config.tmpl.render( config.tmpl.render(
"contrib.html", "contrib2.html",
PortfolioTemplate { data: projects }, PortfolioTemplate {
projects: data,
waiting: Vec::new(),
closed: Vec::new(),
},
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()),

View file

@ -2,68 +2,35 @@
<html class="index" lang="fr"> <html class="index" lang="fr">
{{> header.html }} {{> header.html }}
<body> <body>
{{#data}}
<div id="content"> <div id="content">
<h1 class="subtitle">Mes contributions</h1> <h1 class="subtitle">Mes contributions</h1>
<h2 class="subtitle">PineDocs</h2> <!-- Add URL? -->
{{#projects}}
<h2 class="subtitle">{{name}}</h2>
<p> <p>
<a href="https://github.com/xy2z/PineDocs/pull/193">#193</a> {{#pulls_merged}}
<a href="https://github.com/xy2z/PineDocs/pull/194">#194</a> <a href="{{url}}">#{{id}}</a>
<a href="https://github.com/xy2z/PineDocs/pull/196">#196</a> {{/pulls_merged}}
<a href="https://github.com/xy2z/PineDocs/pull/228">#228</a>
<a href="https://github.com/xy2z/PineDocs/pull/230">#230</a>
<a href="https://github.com/xy2z/PineDocs/pull/231">#231</a>
<a href="https://github.com/xy2z/PineDocs/pull/237">#237</a>
<a href="https://github.com/xy2z/PineDocs/pull/240">#240</a>
<a href="https://github.com/xy2z/PineDocs/pull/243">#243</a>
<a href="https://github.com/xy2z/PineDocs/pull/259">#259</a>
</p> </p>
<h2 class="subtitle">Tachiyomi Extensions</h2> {{/projects}}
<p>
<a
href="https://github.com/tachiyomiorg/tachiyomi-extensions/pull/10994"
>#10994</a
>
<a
href="https://github.com/tachiyomiorg/tachiyomi-extensions/pull/12181"
>#12181</a
>
<a
href="https://github.com/tachiyomiorg/tachiyomi-extensions/pull/15397"
>#15397</a
>
</p>
<h2 class="subtitle">x11 Emoji Picker</h2>
<p>
<a href="https://github.com/GaZaTu/x11-emoji-picker/pull/12">#12</a>
</p>
<h2 class="subtitle">Joal</h2>
<p><a href="https://github.com/anthonyraymond/joal/pull/112">#122</a></p>
<h2 class="subtitle">Node Genius Lyrics</h2>
<p>
<a href="https://github.com/zyrouge/node-genius-lyrics/pull/44">#44</a>
</p>
<h1 class="subtitle">En attente</h1> <h1 class="subtitle">En attente</h1>
{{#waiting}}
<p> <p>
<a href="https://github.com/xy2z/PineDocs/pull/213">PineDocs#213</a> {{#pulls_open}}
<a href="https://github.com/xy2z/PineDocs/pull/232">PineDocs#232</a> <a href="{{url}}">{{name}}#{{id}}</a>
<a href="https://github.com/xy2z/PineDocs/pull/234">PineDocs#234</a> {{/pulls_open}}
<a href="https://github.com/xy2z/PineDocs/pull/257">PineDocs#257</a>
<a href="https://github.com/SimpleMobileTools/Simple-Contacts/pull/937"
>Simple-Contacts#937</a
>
<a
href="https://github.com/SimpleMobileTools/Simple-Flashlight/pull/193"
>Simple-Flashlight#193</a
>
</p> </p>
{{/waiting}}
<h1 class="subtitle">Non mergées</h1> <h1 class="subtitle">Non mergées</h1>
{{#closed}}
<p> <p>
<a href="https://github.com/secure-77/Perlite/pull/16">Perlite#16</a> {{#pulls_closed}}
<a href="{{url}}">{{name}}#{{id}}</a>
{{/pulls_closed}}
</p> </p>
{{/closed}}
</div> </div>
{{> footer.html }} {{/data}} {{> footer.html }}
</body> </body>
</html> </html>