finished push

This commit is contained in:
JOLIMAITRE Matthieu 2022-09-30 00:53:22 +02:00
parent 9d7fa48390
commit 7aea0241e6
2 changed files with 37 additions and 8 deletions

View file

@ -1,35 +1,58 @@
use std::process::Command;
use std::process::{exit, Command};
use chrono::Utc;
use crate::{config::Config, utils::log_success};
use crate::{
config::Config,
utils::{log_error, log_process, log_success},
};
pub fn main(message: Option<String>) {
let message = message.unwrap_or_else(|| Utc::now().format("pi - %d/%m/%Y %H:%M").to_string());
let timestamp = Utc::now().timestamp();
let suffix = format!("pi-{timestamp}");
let tag = Config::get_local()
.unwrap_or_else(|| {
log_error(
"no config file found.\nPlease initialize with 'pi init <path> <identifier>'",
);
exit(1)
})
.identifier()
.to_string()
+ &suffix;
// commit
log_process("committing changes");
Command::new("git")
.args(["commit", "-m", &message])
.status()
.unwrap();
.unwrap()
.success()
.then_some(())
.unwrap_or_else(|| exit(1));
// push
Command::new("git").arg("push").status().unwrap();
// tag
let timestamp = Utc::now().timestamp();
let suffix = format!("pi-{timestamp}");
let tag = Config::get_local().unwrap().identifier().to_string() + &suffix;
log_process("tagging");
Command::new("git")
.args(["tag", "-a", &tag, "-m", ""])
.status()
.unwrap();
.unwrap()
.success()
.then_some(())
.unwrap_or_else(|| exit(1));
// push tag
Command::new("git")
.args(["push", "--follow-tags"])
.status()
.unwrap();
.unwrap()
.success()
.then_some(())
.unwrap_or_else(|| exit(1));
log_success(&format!("pushed with tag '{tag}'"));
}

View file

@ -91,3 +91,9 @@ fn format_variable(input: &str) -> String {
color::Fg(color::Reset),
)
}
pub fn log_error(input: impl AsRef<str>) {
let input = input.as_ref();
log_pi_prefix();
println!("error: {input}");
}