diff --git a/architecture.md b/architecture.md new file mode 100644 index 0000000..43c562a --- /dev/null +++ b/architecture.md @@ -0,0 +1,3 @@ +# Architecture + +This document is intended to explain how the Plenum Bot works. diff --git a/src/main.rs b/src/main.rs index a351283..a67e886 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,9 @@ use std::env; use std::error::Error; +use std::fmt::Display; +use std::io::IsTerminal; +use std::os::linux::raw::stat; use std::time::Instant; use chrono::{Local, NaiveDate}; @@ -9,18 +12,14 @@ use clap::{Arg, Command}; use colored::Colorize; use regex::Regex; -use std::fmt::Display; -use std::io::IsTerminal; - +use cccron_lib::{trace_var, trace_var_, verboseln}; use cccron_lib::config_spec::{self, CfgField, CfgGroup, CfgSpec}; -use cccron_lib::key_value::KeyValueStore as KV; - use cccron_lib::date; use cccron_lib::email::{self, Email, SimpleEmail}; use cccron_lib::hedgedoc::{self, HedgeDoc}; use cccron_lib::is_dry_run; +use cccron_lib::key_value::{KeyValueStore as KV, KeyValueStore}; use cccron_lib::mediawiki::{self, Mediawiki}; -use cccron_lib::{verboseln,trace_var,trace_var_}; use cccron_lib::NYI; /* ***** Config Spec ***** */ @@ -93,6 +92,14 @@ fn today() -> NaiveDate { .map(|v| NaiveDate::parse_from_str(&v, "%F").expect("'TODAY' hat nicht format YYYY-MM-DD")) .unwrap_or(Local::now().date_naive()) } +/// Gets either the state from the config or overrides it with the state from +/// the environment variable `STATE_OVERRIDE` (for testing purposes.) +fn state(config: &KeyValueStore) -> ProgramState { + match env::var("STATE_OVERRIDE") { + Ok(val) => ProgramState::parse(&val), + Err(_e) => ProgramState::parse(&config["state-name"]) + } +} #[derive(Debug)] struct Args { @@ -182,7 +189,7 @@ fn main() -> Result<(), Box> { let nearest_plenum_days = date::get_matching_dates_around(today, plenum_spec); trace_var!(nearest_plenum_days); // figure out where we are - let mut last_state = ProgramState::parse(&config["state-name"]); + let mut last_state = state(&config); let last_run = config.get("state-last-run").unwrap_or_default(); let last_run = NaiveDate::parse_from_str(&last_run, "%Y-%m-%d").unwrap_or_default(); trace_var!(last_run); diff --git a/src/mediawiki.rs b/src/mediawiki.rs index 37df128..420bef0 100644 --- a/src/mediawiki.rs +++ b/src/mediawiki.rs @@ -6,8 +6,8 @@ use reqwest::blocking::Client; use serde::Deserialize; use serde_json::json; -use crate::config_spec::{CfgField, CfgGroup}; use crate::{trace_var, verboseln}; +use crate::config_spec::{CfgField, CfgGroup}; pub const CONFIG: CfgGroup<'static> = CfgGroup { name: "wiki", @@ -284,7 +284,7 @@ pub fn pad_ins_wiki(old_pad_content: String, wiki: &Mediawiki) -> Result<(), Box fn pandoc_convert(markdown: String) -> Result> { let (output, errors, status) = crate::pipe( "pandoc", - &mut ["--from", "markdown", "--to", "mediawiki", "--no-highlight"], + &mut ["--from", "markdown-auto_identifiers", "--to", "mediawiki", "--no-highlight"], markdown, )?; if status.success() {