1use crate::{config::CONFIG, git::Git, github::Github};
2use std::process::Command;
3use pretty_log::{log, PrettyError};
4
5#[derive(Debug, Clone, clap::Parser)]
6pub struct Fix {
7 #[clap(value_delimiter = ' ', num_args = 1..)]
8 message: Vec<String>,
9}
10
11impl Fix {
12 pub fn run(self) {
13 let message = self.message.join(" ");
14 let branch_name = format!("fix/{}", message.to_lowercase().replace(" ", "-"));
15 let target_branch = CONFIG.main_branch.clone();
16
17 CONFIG.build_command.as_ref().map(|cmd| {
18 log::info(
19 &format!("[gou] Running build command: {}", cmd)
20 );
21
22 let mut args = cmd.split_whitespace();
23 let mut cmd = Command::new(args.nth(0).unwrap());
24
25 for arg in args {
26 cmd.arg(arg);
27 }
28
29 cmd.spawn()
30 .expect_p("[gou] Failed to run build command")
31 .wait()
32 .expect_p("[gou] Failed to wait for build command");
33 });
34
35 Git::add();
36 Git::stash();
37 Git::checkout_create(&branch_name);
38 Git::stash_pop();
39 Git::add();
40 Git::commit(&format!("fix: {}", message));
41 Git::push_set_upstream(&branch_name);
42
43 Github::create_pr(&format!("fix: {}", message), &target_branch);
44
45 Git::checkout(&target_branch);
46 }
47}