gou_git/
feat.rs

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