From 5d22662499e8da899e82ebb9a0fa39bca001c59e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arma=C3=ABl=20Gu=C3=A9neau?= Date: Fri, 22 Nov 2024 16:10:20 +0100 Subject: [PATCH] cargo fmt --- src/main.rs | 91 ++++++++++++++++++++++++++++------------------------- 1 file changed, 48 insertions(+), 43 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9b01384..cf98c41 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,45 +1,39 @@ -use forgejo_api::{Auth, Forgejo}; -use std::collections::HashMap; -use tokio::time::{sleep, Duration}; +use actix_web::{get, post, web, App, HttpRequest, HttpResponse, HttpServer, Responder}; use bayespam::classifier::Classifier; -use serde::{Serialize, Deserialize}; -use std::path::Path; +use forgejo_api::{Auth, Forgejo}; +use lazy_static::lazy_static; +use rand::prelude::*; +use serde::{Deserialize, Serialize}; +use std::collections::HashMap; use std::fs::File; use std::io::{BufReader, BufWriter}; -use rand::prelude::*; -use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder, HttpRequest}; -use tera::Tera; -use lazy_static::lazy_static; +use std::path::Path; use std::sync::Mutex; +use tera::Tera; +use tokio::time::{sleep, Duration}; -#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)] -#[derive(Serialize, Deserialize)] +#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, Serialize, Deserialize)] struct RepoId(i64); -#[derive(Debug)] -#[derive(Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize)] struct RepoData { name: String, description: Option, } -#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)] -#[derive(Serialize, Deserialize)] +#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, Serialize, Deserialize)] struct IssueId(i64); -#[derive(Debug)] -#[derive(Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize)] struct IssueData { title: String, body: String, } -#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)] -#[derive(Serialize, Deserialize)] +#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, Serialize, Deserialize)] struct UserId(i64); -#[derive(Debug)] -#[derive(Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize)] struct UserData { login: String, email: String, @@ -71,12 +65,13 @@ impl UserData { fn to_text(&self) -> String { let mut text = String::new(); let mut add = |s: &str| { - text += s; text += " " + text += s; + text += " " }; for email_part in self.email.split('@') { add(email_part) - }; + } match &self.location { Some(s) => add(&s), @@ -251,7 +246,8 @@ async fn get_users_data(forge: &Forgejo) -> anyhow::Result anyhow::Result anyhow::Result anyhow::Result<(Db, Classifier)> { Classifier::new() }; - let api_token = - std::fs::read_to_string(Path::new("api_token"))? - .trim().to_string(); + let api_token = std::fs::read_to_string(Path::new("api_token"))? + .trim() + .to_string(); let forge = Forgejo::new( Auth::Token(&api_token), - url::Url::parse("https://git.deuxfleurs.fr")? + url::Url::parse("https://git.deuxfleurs.fr")?, )?; let db_path = Path::new("db.json"); @@ -324,13 +324,11 @@ async fn load_db() -> anyhow::Result<(Db, Classifier)> { Ok((db, classifier)) } -fn unclassified_users<'a>(db: &'a Db, classifier: &Classifier) -> - Vec<(&'a UserId, &'a UserData)> -{ +fn unclassified_users<'a>(db: &'a Db, classifier: &Classifier) -> Vec<(&'a UserId, &'a UserData)> { db.users - .iter() - .filter(|(user_id, _)| ! db.classification.contains_key(&user_id)) - .collect() + .iter() + .filter(|(user_id, _)| !db.classification.contains_key(&user_id)) + .collect() } /* @@ -407,8 +405,10 @@ async fn index(data: web::Data) -> impl Responder { eprintln!("compute unclassified users"); - let users: Vec<&UserData> = - unclassified_users(db, classifier).into_iter().map(|(_id, u)| u).collect(); + let users: Vec<&UserData> = unclassified_users(db, classifier) + .into_iter() + .map(|(_id, u)| u) + .collect(); let mut context = tera::Context::new(); @@ -422,9 +422,14 @@ async fn index(data: web::Data) -> impl Responder { } #[post("/")] -async fn apply(data: web::Data, req: web::Form>) -> impl Responder { +async fn apply( + data: web::Data, + req: web::Form>, +) -> impl Responder { println!("{:#?}", req); - HttpResponse::SeeOther().insert_header(("Location", "/")).finish() + HttpResponse::SeeOther() + .insert_header(("Location", "/")) + .finish() } #[actix_web::main]