From 17a4e7e94ae55338f52ff77bec325d03286b5371 Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Sun, 28 Jan 2024 15:01:34 +0700 Subject: [PATCH] Removing unnecessary logging format, fix response message, use HashSet instead of Vec for allowed organizations --- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 7 +++---- config.toml | 1 - src/config.rs | 32 ++++---------------------------- src/main.rs | 7 ++++--- 6 files changed, 13 insertions(+), 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dcd9452..d90a407 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -579,7 +579,7 @@ dependencies = [ [[package]] name = "doc-previewer" -version = "0.3.0" +version = "0.3.1" dependencies = [ "actix-web", "awc", diff --git a/Cargo.toml b/Cargo.toml index 9cebb30..0ed12d1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "doc-previewer" -version = "0.3.0" +version = "0.3.1" edition = "2021" description = "Web service that publishes a preview of a GitHub project documentation." license = "3bsd" diff --git a/README.md b/README.md index 5dc0fa9..144a4e1 100644 --- a/README.md +++ b/README.md @@ -61,9 +61,9 @@ Currently only packages for Debian are provided. The package can be installed using the next command: ``` -curl -sLO https://github.com/pandas-dev/github-doc-previewer/releases/download/v0.3.0/doc-previewer_0.3.0-1_amd64.deb \ - && sudo dpkg -i doc-previewer_0.3.0-1_amd64.deb \ - && rm doc-previewer_0.3.0-1_amd64.deb +curl -sLO https://github.com/pandas-dev/github-doc-previewer/releases/download/v0.3.0/doc-previewer_0.3.1-1_amd64.deb \ + && sudo dpkg -i doc-previewer_0.3.1-1_amd64.deb \ + && rm doc-previewer_0.3.1-1_amd64.deb ``` To start the service: @@ -94,7 +94,6 @@ allowed_owners = [ "pandas-dev", "pydata" ] [log] level = "info" -format = "%a %{User-Agent}i" ``` All the fields are optional except for the GitHub token, which is required. diff --git a/config.toml b/config.toml index 80eeaed..e0ff89e 100644 --- a/config.toml +++ b/config.toml @@ -14,4 +14,3 @@ allowed_owners = [ "pydata", "pandas-dev" ] [log] level = "info" -format = "%a %{User-Agent}i" diff --git a/src/config.rs b/src/config.rs index ae0a8cd..7c1cd9c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -20,10 +20,10 @@ /// /// [log] /// level = "info" -/// format = "%a %{User-Agent}i" /// ``` use std::fs; use std::path::Path; +use std::collections::HashSet; use serde_derive::Deserialize; const PREVIEWS_PATH: &str = "/var/doc-previewer"; @@ -37,7 +37,6 @@ const SERVER_URL: &str = "https://doc-previewer.pydata.org/"; const GITHUB_ENDPOINT: &str = "https://api.github.com/repos/"; const LOG_LEVEL: &str = "info"; -const LOG_FORMAT: &str = "%a %{User-Agent}i"; #[derive(Deserialize)] pub struct TomlConfig { @@ -65,8 +64,7 @@ struct TomlGitHub { #[derive(Deserialize)] struct TomlLog { - level: Option, - format: Option + level: Option } /// Settings after filling the missing ones with default values. @@ -77,7 +75,6 @@ pub struct Settings { pub github_token: String, pub log_level: String, - pub log_format: String, pub per_thread: SettingsPerThread } @@ -92,7 +89,7 @@ pub struct SettingsPerThread { pub server_url: String, pub github_endpoint: String, - pub github_allowed_owners: Vec + pub github_allowed_owners: HashSet } impl Settings { @@ -108,7 +105,6 @@ impl Settings { github_token: config.github.token.to_owned(), log_level: config.log.as_ref().and_then(|x| x.level.to_owned()).unwrap_or(LOG_LEVEL.to_owned()), - log_format: config.log.and_then(|x| x.format).unwrap_or(LOG_FORMAT.to_owned()), per_thread: SettingsPerThread { previews_path: config.previews_path.unwrap_or(PREVIEWS_PATH.to_owned()), @@ -118,29 +114,9 @@ impl Settings { server_url: config.server.url.unwrap_or(SERVER_URL.to_owned()), github_endpoint: config.github.endpoint.unwrap_or(GITHUB_ENDPOINT.to_owned()), - github_allowed_owners: config.github.allowed_owners + github_allowed_owners: config.github.allowed_owners.into_iter().collect() } }; - // self.previews_path.unwrap_or(PREVIEWS_PATH.to_owned()) settings } } - -/* - Settings { - previews_path: PREVIEWS_PATH.to_owned(), - retention_days: RETENTION_DAYS, - max_artifact_size: MAX_ARTIFACT_SIZE, - - address: ADDRESS.to_owned(), - port: PORT, - publish_url: PUBLISH_URL.to_owned(), - - github_token: GITHUB_TOKEN.to_owned(), - github_endpoint: GITHUB_ENDPOINT.to_owned(), - - log_level: LOG_LEVEL.to_owned(), - log_format: LOG_FORMAT.to_owned() - } - } -*/ diff --git a/src/main.rs b/src/main.rs index 9936b05..79d0202 100644 --- a/src/main.rs +++ b/src/main.rs @@ -52,7 +52,7 @@ async fn preview_handler(params: web::Path<(String, String, u64)>, .join(pull_request_number.to_string()); let publish_url = format!( - "{}{github_owner}/{github_repo}/{pull_request_number}", + "{}{github_owner}/{github_repo}/{pull_request_number}/", settings.server_url ); @@ -80,7 +80,9 @@ async fn preview_handler(params: web::Path<(String, String, u64)>, } } }); - HttpResponse::Ok().body(publish_url) + HttpResponse::Ok().body( + format!("Website preview of this PR available at: {}", publish_url) + ) } Err(e) => { log::error!("[PR {}] {:?}", pull_request_number, e); @@ -113,7 +115,6 @@ async fn main() -> std::io::Result<()> { App::new() .wrap(Logger::default()) - .wrap(Logger::new(&settings.log_format)) .app_data(web::Data::new(client.clone())) .app_data(web::Data::new(settings.per_thread.clone())) .service(preview_handler)