state transition progress
- add notes what needs to happen - hedgedoc summary
This commit is contained in:
parent
8bc7405d63
commit
d152e0da61
|
@ -1,4 +1,5 @@
|
|||
use crate::config_spec::{CfgField, CfgGroup};
|
||||
use regex::Regex;
|
||||
use reqwest::blocking::Client;
|
||||
use reqwest::blocking::Response;
|
||||
use std::error::Error;
|
||||
|
@ -96,6 +97,23 @@ impl HedgeDoc {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn summarize(pad_content: String) -> String {
|
||||
// 1. remove HTML comments
|
||||
let re_comment = Regex::new(r"(?s)<!--.*?-->").unwrap();
|
||||
let pad_content = re_comment.replace_all(&pad_content, "").to_string();
|
||||
// 2. accumulate topic lines
|
||||
let re_header = Regex::new(r"^\s*##(#*) TOP ([\d.]+\s*.*?)\s*#*$").unwrap();
|
||||
let mut result: Vec<String> = Vec::new();
|
||||
for line in pad_content.lines() {
|
||||
if let Some(captures) = re_header.captures(line) {
|
||||
let indent = " ".repeat(captures.get(1).unwrap().as_str().len());
|
||||
let title = captures.get(2).unwrap().as_str();
|
||||
result.push(format!("{}{}", indent, title));
|
||||
}
|
||||
}
|
||||
result.join("\n")
|
||||
}
|
||||
|
||||
/// For the config, make a new pad ID (by actually making a pad.)
|
||||
fn make_pad_id(_key: &str, config: &crate::KV, is_dry_run: bool) -> Result<String, Box<dyn Error>> {
|
||||
HedgeDoc::new(&config.get("hedgedoc-server-url").unwrap(), is_dry_run).create_pad()
|
||||
|
|
37
src/main.rs
37
src/main.rs
|
@ -253,6 +253,11 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
if args.check_mode {
|
||||
return config_spec::interactive_check(&CONFIG_SPEC, config);
|
||||
}
|
||||
// ensure existence of this is checked early
|
||||
let _current_pad_id = config
|
||||
.get("hedgedoc-last-id")
|
||||
.expect("ID des aktuellen Pads undefiniert. Bitte in der DB eintragen oder generieren.");
|
||||
trace_var!(_current_pad_id);
|
||||
// get config
|
||||
let hedgedoc = HedgeDoc::new(&config["hedgedoc-server-url"], is_dry_run());
|
||||
trace_var!(hedgedoc);
|
||||
|
@ -337,10 +342,11 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
|
||||
let action: &ST = &TRANSITION_LUT[last_state as usize][intended_state as usize];
|
||||
verboseln!("Notewendige Aktionen: {}", action.to_string().cyan());
|
||||
// run action, which is responsible for updating the state as needed
|
||||
action.get()(delta, &plenum_day, &config, &hedgedoc, &email, &wiki)?;
|
||||
|
||||
// TODO: cleanup / write new state
|
||||
|
||||
// shutdown
|
||||
config.set("state-last-run", &today.to_string())?;
|
||||
if config.has_errors() {
|
||||
return Err("There were errors while writing config values.".into());
|
||||
} else {
|
||||
|
@ -676,7 +682,17 @@ fn do_announcement(
|
|||
ttp: i64, plenum_day: &NaiveDate, config: &KV, hedgedoc: &HedgeDoc, email: &SimpleEmail,
|
||||
wiki: &Mediawiki,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
// use TTP to adjust text if needed (in {ttp} days)
|
||||
let current_pad_id = &config["hedgedoc-last-id"];
|
||||
let pad_content = hedgedoc.download(current_pad_id).expect("Hedgedoc: Download-Fehler");
|
||||
let toc = hedgedoc::summarize(pad_content);
|
||||
verboseln!("Zusammenfassung des aktuellen Plenum-Pads:\n{}", toc.cyan());
|
||||
let n_topics = toc.lines().count();
|
||||
verboseln!("(Das sind {} Themen.)", n_topics.to_string().cyan());
|
||||
// TODO: if
|
||||
// summary empty: write message variant
|
||||
// summary not empty: write other message variant
|
||||
// TODO: set/write state as Announced
|
||||
// TODO: write summary
|
||||
todo!()
|
||||
}
|
||||
|
||||
|
@ -685,7 +701,13 @@ fn do_reminder(
|
|||
ttp: i64, plenum_day: &NaiveDate, config: &KV, hedgedoc: &HedgeDoc, email: &SimpleEmail,
|
||||
wiki: &Mediawiki,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
// use TTP to adjust text if needed (tomorrow or today / in {ttp} days)
|
||||
// TODO: get pad
|
||||
// TODO: make summary
|
||||
// TODO: if
|
||||
// summary empty: write message variant
|
||||
// summary not empty: make diff, send diff etc.
|
||||
// TODO: set/write state as Reminded
|
||||
// TODO: write summary
|
||||
todo!()
|
||||
}
|
||||
|
||||
|
@ -694,7 +716,10 @@ fn do_protocol(
|
|||
ttp: i64, plenum_day: &NaiveDate, config: &KV, hedgedoc: &HedgeDoc, email: &SimpleEmail,
|
||||
wiki: &Mediawiki,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
// use TTP to adjust text if needed ({-ttp} days ago)
|
||||
// TODO: get pad
|
||||
// TODO: write to wiki
|
||||
// TODO: write to email
|
||||
// TODO: set state as Logged
|
||||
todo!()
|
||||
}
|
||||
|
||||
|
@ -705,6 +730,8 @@ fn do_cleanup(
|
|||
ttp: i64, plenum_day: &NaiveDate, config: &KV, hedgedoc: &HedgeDoc, email: &SimpleEmail,
|
||||
wiki: &Mediawiki,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
// TODO: reset any state vars (e.g. summary)
|
||||
// TODO: set state back to normal
|
||||
todo!()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue