Skip to content

Commit

Permalink
add a way to edit summary messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jupyterkat committed Feb 13, 2024
1 parent 1f9e2d5 commit be505ce
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 8 deletions.
3 changes: 3 additions & 0 deletions crates/icondiffbot2/config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ blacklist_contact = "Good luck!"
# Logging level (Optional, defaults to info), Valid values are "info", "warn", "trace", "error", "debug"
logging = "info"

# Summary message, the message that goes before the diff, (Optional, defaults to below)
# summary_msg = "*Please file any issues [here](https://github.com/spacestation13/BYONDDiffBots/issues).*\n\nIcons with diff:"

# Mysql db url, the bots will write down a table that contains necessary information,
# for automated deletion (Optional)
# db_url = ""
Expand Down
10 changes: 10 additions & 0 deletions crates/icondiffbot2/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ pub struct Config {
pub blacklist_contact: String,
#[serde(default = "default_log_level")]
pub logging: String,
#[serde(default = "default_msg")]
pub summary_msg: String,
pub secret: Option<String>,
pub db_url: Option<String>,
pub grafana_loki: Option<GrafanaLoki>,
Expand All @@ -74,6 +76,10 @@ fn default_log_level() -> String {
"info".to_string()
}

fn default_msg() -> String {
"*Please file any issues [here](https://github.com/spacestation13/BYONDDiffBots/issues).*\n\nIcons with diff:".to_string()
}

static CONFIG: OnceLock<Config> = OnceLock::new();
// static FLAME_LAYER_GUARD: OnceCell<tracing_flame::FlushGuard<std::io::BufWriter<File>>> =
// OnceCell::new();
Expand All @@ -88,6 +94,10 @@ fn init_config(path: &Path) -> eyre::Result<&'static Config> {
Ok(CONFIG.get().unwrap())
}

fn read_config() -> &'static Config {
CONFIG.get().unwrap()
}

// fn init_global_subscriber() {
// use tracing_subscriber::prelude::*;

Expand Down
8 changes: 4 additions & 4 deletions crates/icondiffbot2/src/table_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ impl<'a> OutputTableBuilder<'a> {
if current_output_text.len() + diff_block.len() > 60_000 {
chunks.push(Output {
title: "Icon difference rendering",
summary: "*Please file any issues [here](https://github.com/spacestation13/BYONDDiffBots/issues).*\n\nIcons with diff:".to_string(),
text: std::mem::take(&mut current_output_text)
summary: crate::read_config().summary_msg.to_string(),
text: std::mem::take(&mut current_output_text),
});
}

Expand All @@ -85,8 +85,8 @@ impl<'a> OutputTableBuilder<'a> {
if !current_output_text.is_empty() {
chunks.push(Output {
title: "Icon difference rendering",
summary: "*Please file any issues [here](https://github.com/spacestation13/BYONDDiffBots/issues).*\n\nIcons with diff:".to_string(),
text: std::mem::take(&mut current_output_text)
summary: crate::read_config().summary_msg.to_string(),
text: std::mem::take(&mut current_output_text),
});
}
Ok(chunks)
Expand Down
3 changes: 3 additions & 0 deletions crates/mapdiffbot2/config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ gc_schedule = "0 0 4 * * *"
# Logging level (Optional, defaults to info), Valid values are "info", "warn", "trace", "error", "debug"
logging = "info"

# Summary message, the message that goes before the diff, (Optional, defaults to below)
# summary_msg = "*Please file any issues [here](https://github.com/spacestation13/BYONDDiffBots/issues).*\n\n*Github may fail to render some images, appearing as cropped on large map changes. Please use the raw links in this case.*\n\nMaps with diff:"

# Mysql db url, the bots will write down a table that contains necessary information,
# for automated deletion (Optional)
# db_url = ""
Expand Down
5 changes: 1 addition & 4 deletions crates/mapdiffbot2/src/job_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,7 @@ fn generate_finished_output<P: AsRef<Path>>(
.to_string()
.replace('\\', "/");

let mut builder = CheckOutputBuilder::new(
"Map renderings",
"*Please file any issues [here](https://github.com/spacestation13/BYONDDiffBots/issues).*\n\n*Github may fail to render some images, appearing as cropped on large map changes. Please use the raw links in this case.*\n\nMaps with diff:",
);
let mut builder = CheckOutputBuilder::new("Map renderings", &crate::read_config().summary_msg);

let link_base = format!("{file_url}/{non_abs_directory}");

Expand Down
10 changes: 10 additions & 0 deletions crates/mapdiffbot2/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ pub struct Config {
pub gc_schedule: String,
#[serde(default = "default_log_level")]
pub logging: String,
#[serde(default = "default_msg")]
pub summary_msg: String,
pub secret: Option<String>,
pub db_url: Option<String>,
pub azure_blobs: Option<AzureBlobs>,
Expand All @@ -83,6 +85,10 @@ fn default_log_level() -> String {
"info".to_string()
}

fn default_msg() -> String {
"*Please file any issues [here](https://github.com/spacestation13/BYONDDiffBots/issues).*\n\n*Github may fail to render some images, appearing as cropped on large map changes. Please use the raw links in this case.*\n\nMaps with diff:".to_string()
}

static CONFIG: OnceLock<Config> = OnceLock::new();

fn read_key(path: PathBuf) -> Vec<u8> {
Expand All @@ -107,6 +113,10 @@ fn init_config(path: &std::path::Path) -> eyre::Result<&'static Config> {
Ok(CONFIG.get().unwrap())
}

fn read_config() -> &'static Config {
CONFIG.get().unwrap()
}

type Azure = Option<std::sync::Arc<object_store::azure::MicrosoftAzure>>;

#[actix_web::main]
Expand Down

0 comments on commit be505ce

Please sign in to comment.