From b6d1ae0bdcaf7b98a84071c75510794bf598f719 Mon Sep 17 00:00:00 2001 From: Wang Jie Date: Sat, 12 Dec 2020 19:52:59 +0800 Subject: [PATCH] feat: allow setting default target branch --- src/command.rs | 12 ++++++++++-- src/utils.rs | 4 ++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/command.rs b/src/command.rs index cbc1eda..c29ae62 100644 --- a/src/command.rs +++ b/src/command.rs @@ -19,7 +19,7 @@ fn get_app<'a, 'b>() -> App<'a, 'b> { ) .subcommand( SubCommand::with_name("pr") - .about("Manage requests") + .about("Manage pull requests (aka. merge request for GitLab)") .alias("mr") .subcommand( SubCommand::with_name("get") @@ -83,6 +83,14 @@ pub async fn run() -> Result<()> { Some(head) => head.to_string(), _ => utils::get_current_branch()?, }; + + let target_branch = matches.value_of("base") + .map(|base| base.to_string()) + .or_else(|| { + utils::get_git_config("yag.pr.target").ok() + }) + .unwrap_or("master".to_string()); + let title = matches .value_of("title") .map(|title| title.to_string()) @@ -93,7 +101,7 @@ pub async fn run() -> Result<()> { repo.create_pull_request( &source_branch, - matches.value_of("base").unwrap_or("master"), + &target_branch, &title, ) .await? diff --git a/src/utils.rs b/src/utils.rs index cdcfffd..e07127c 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -29,6 +29,10 @@ pub fn get_latest_commit_message() -> Result { spawn("git log -1 --pretty=%B").map(|x| x.trim().to_string()) } +pub fn get_git_config(key: &str) -> Result { + spawn(&format!("git config --get {}", key)).map(|x| x.trim().to_string()) +} + #[cfg(test)] mod tests { use super::*;