Skip to content

Commit

Permalink
feat: allow setting default target branch
Browse files Browse the repository at this point in the history
  • Loading branch information
cnwangjie committed Dec 12, 2020
1 parent 1691bce commit b6d1ae0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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())
Expand All @@ -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?
Expand Down
4 changes: 4 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ pub fn get_latest_commit_message() -> Result<String> {
spawn("git log -1 --pretty=%B").map(|x| x.trim().to_string())
}

pub fn get_git_config(key: &str) -> Result<String> {
spawn(&format!("git config --get {}", key)).map(|x| x.trim().to_string())
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit b6d1ae0

Please sign in to comment.