Skip to content

Commit

Permalink
Removing unnecessary logging format, fix response message, use HashSe…
Browse files Browse the repository at this point in the history
…t instead of Vec for allowed organizations
  • Loading branch information
datapythonista committed Jan 28, 2024
1 parent d058edc commit 17a4e7e
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ allowed_owners = [ "pydata", "pandas-dev" ]

[log]
level = "info"
format = "%a %{User-Agent}i"
32 changes: 4 additions & 28 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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 {
Expand Down Expand Up @@ -65,8 +64,7 @@ struct TomlGitHub {

#[derive(Deserialize)]
struct TomlLog {
level: Option<String>,
format: Option<String>
level: Option<String>
}

/// Settings after filling the missing ones with default values.
Expand All @@ -77,7 +75,6 @@ pub struct Settings {
pub github_token: String,

pub log_level: String,
pub log_format: String,

pub per_thread: SettingsPerThread
}
Expand All @@ -92,7 +89,7 @@ pub struct SettingsPerThread {
pub server_url: String,

pub github_endpoint: String,
pub github_allowed_owners: Vec<String>
pub github_allowed_owners: HashSet<String>
}

impl Settings {
Expand All @@ -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()),
Expand All @@ -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()
}
}
*/
7 changes: 4 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 17a4e7e

Please sign in to comment.