From a50d894926cf743ba0612c0147e3032e5e215357 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Wed, 12 Apr 2023 01:04:16 +0200 Subject: [PATCH] wip contrib logic --- src/routes/contrib.rs | 73 ++++++++++++++++++++++++++++++++++++++---- templates/contrib.html | 71 +++++++++++----------------------------- 2 files changed, 86 insertions(+), 58 deletions(-) diff --git a/src/routes/contrib.rs b/src/routes/contrib.rs index bbd37c9..b87349d 100644 --- a/src/routes/contrib.rs +++ b/src/routes/contrib.rs @@ -1,6 +1,8 @@ +use std::collections::HashMap; + use crate::{ config::Config, - github::{fetch_pr, Project}, + github::{fetch_pr, ProjectState}, template::Infos, }; use actix_web::{get, web, HttpResponse, Responder}; @@ -14,19 +16,78 @@ pub async fn page(config: web::Data) -> impl Responder { #[derive(Content)] struct PortfolioTemplate { - data: Vec, + projects: Vec, + waiting: Vec, + closed: Vec, } -#[once(time = 60)] +#[derive(Content)] +struct Project { + name: String, + url: String, + pulls_merged: Vec, + pulls_open: Vec, + pulls_closed: Vec, +} + +#[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 { // Fetch latest data from github let projects = fetch_pr().await; - println!("{:#?}", projects); + let mut data: Vec = Vec::new(); + let mut map: HashMap<&str, Vec> = 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 = d.name.replace('-', " ").chars().collect(); + name[0] = name[0].to_uppercase().next().unwrap(); + d.name = name.into_iter().collect(); + }); config.tmpl.render( - "contrib.html", - PortfolioTemplate { data: projects }, + "contrib2.html", + PortfolioTemplate { + projects: data, + waiting: Vec::new(), + closed: Vec::new(), + }, Infos { page_title: Some("Mes contributions".to_string()), page_desc: Some("Contributions à l'opensource par Anri".to_string()), diff --git a/templates/contrib.html b/templates/contrib.html index 5e80b7a..766e75b 100644 --- a/templates/contrib.html +++ b/templates/contrib.html @@ -2,68 +2,35 @@ {{> header.html }} + {{#data}}

Mes contributions

-

PineDocs

+ + {{#projects}} +

{{name}}

- #193 - #194 - #196 - #228 - #230 - #231 - #237 - #240 - #243 - #259 + {{#pulls_merged}} + #{{id}} + {{/pulls_merged}}

-

Tachiyomi Extensions

-

- #10994 - #12181 - #15397 -

- -

x11 Emoji Picker

-

- #12 -

-

Joal

-

#122

-

Node Genius Lyrics

-

- #44 -

- + {{/projects}}

En attente

+ {{#waiting}}

- PineDocs#213 - PineDocs#232 - PineDocs#234 - PineDocs#257 - Simple-Contacts#937 - Simple-Flashlight#193 + {{#pulls_open}} + {{name}}#{{id}} + {{/pulls_open}}

- + {{/waiting}}

Non mergées

+ {{#closed}}

- Perlite#16 + {{#pulls_closed}} + {{name}}#{{id}} + {{/pulls_closed}}

+ {{/closed}}
- {{> footer.html }} + {{/data}} {{> footer.html }}