finished push
This commit is contained in:
parent
9d7fa48390
commit
7aea0241e6
2 changed files with 37 additions and 8 deletions
39
src/push.rs
39
src/push.rs
|
@ -1,35 +1,58 @@
|
||||||
use std::process::Command;
|
use std::process::{exit, Command};
|
||||||
|
|
||||||
use chrono::Utc;
|
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>) {
|
pub fn main(message: Option<String>) {
|
||||||
let message = message.unwrap_or_else(|| Utc::now().format("pi - %d/%m/%Y %H:%M").to_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
|
// commit
|
||||||
|
log_process("committing changes");
|
||||||
Command::new("git")
|
Command::new("git")
|
||||||
.args(["commit", "-m", &message])
|
.args(["commit", "-m", &message])
|
||||||
.status()
|
.status()
|
||||||
.unwrap();
|
.unwrap()
|
||||||
|
.success()
|
||||||
|
.then_some(())
|
||||||
|
.unwrap_or_else(|| exit(1));
|
||||||
|
|
||||||
// push
|
// push
|
||||||
Command::new("git").arg("push").status().unwrap();
|
Command::new("git").arg("push").status().unwrap();
|
||||||
|
|
||||||
// tag
|
// tag
|
||||||
let timestamp = Utc::now().timestamp();
|
log_process("tagging");
|
||||||
let suffix = format!("pi-{timestamp}");
|
|
||||||
let tag = Config::get_local().unwrap().identifier().to_string() + &suffix;
|
|
||||||
Command::new("git")
|
Command::new("git")
|
||||||
.args(["tag", "-a", &tag, "-m", ""])
|
.args(["tag", "-a", &tag, "-m", ""])
|
||||||
.status()
|
.status()
|
||||||
.unwrap();
|
.unwrap()
|
||||||
|
.success()
|
||||||
|
.then_some(())
|
||||||
|
.unwrap_or_else(|| exit(1));
|
||||||
|
|
||||||
// push tag
|
// push tag
|
||||||
Command::new("git")
|
Command::new("git")
|
||||||
.args(["push", "--follow-tags"])
|
.args(["push", "--follow-tags"])
|
||||||
.status()
|
.status()
|
||||||
.unwrap();
|
.unwrap()
|
||||||
|
.success()
|
||||||
|
.then_some(())
|
||||||
|
.unwrap_or_else(|| exit(1));
|
||||||
|
|
||||||
log_success(&format!("pushed with tag '{tag}'"));
|
log_success(&format!("pushed with tag '{tag}'"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,3 +91,9 @@ fn format_variable(input: &str) -> String {
|
||||||
color::Fg(color::Reset),
|
color::Fg(color::Reset),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn log_error(input: impl AsRef<str>) {
|
||||||
|
let input = input.as_ref();
|
||||||
|
log_pi_prefix();
|
||||||
|
println!("error: {input}");
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue