Skip to content

Commit

Permalink
Added global labels
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerwood committed Apr 18, 2022
1 parent 2a850a2 commit 8dcadf7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
15 changes: 14 additions & 1 deletion src/confluence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct Confluence {
secret: String,
fqdn: String,
pages: Vec<Page>,
global_labels: Vec<String>,
}

#[derive(Deserialize)]
Expand All @@ -31,7 +32,13 @@ pub struct Version {
}

impl Confluence {
pub fn new(user: String, secret: String, fqdn: String, config_path: String) -> Self {
pub fn new(
user: String,
secret: String,
fqdn: String,
config_path: String,
global_labels: Vec<String>,
) -> Self {
let pages = Self::get_page_config(&config_path).unwrap_or_else(|x| {
println!("Could not read config file.\n[Error: {}]", x.to_string());
process::exit(1)
Expand All @@ -41,6 +48,7 @@ impl Confluence {
secret,
fqdn,
pages,
global_labels,
}
}

Expand All @@ -59,6 +67,10 @@ impl Confluence {
let file = fs::File::open(config_path)?;
let reader = BufReader::new(file);
let config: Config = serde_yaml::from_reader(reader)?;

// for page in config.content.iter() {
// page.labels.append(&mut self.global_labels)
// }
Ok(config.content)
}

Expand Down Expand Up @@ -105,6 +117,7 @@ impl Confluence {
let mut labels: Vec<String> = page.labels.iter().cloned().collect();

labels.push(format!("sha:{}", html_sha));
labels.extend(self.global_labels.clone());

let payload = ContentPayload::new(&page, version, &labels, &html);

Expand Down
2 changes: 1 addition & 1 deletion src/content_payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl ContentPayload {
impl From<&String> for Label {
fn from(label: &String) -> Self {
Label {
name: label.to_owned(),
name: label.to_owned().replace(" ", "-"),
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ enum Opt {
help = "The path to the config file."
)]
config_path: String,

#[structopt(short, long = "label", help = "Add a label to all updating pages.")]
labels: Vec<String>,
},
}

Expand All @@ -53,8 +56,9 @@ async fn main() -> Result<(), String> {
secret,
fqdn,
config_path,
labels,
} => {
let con = Confluence::new(user, secret, fqdn, config_path);
let con = Confluence::new(user, secret, fqdn, config_path, labels);
con.update_pages().await?;
}
}
Expand Down

0 comments on commit 8dcadf7

Please sign in to comment.