From 39ad36115d368d79d4723b3a6b1cefe4874813a3 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Wed, 1 Nov 2023 00:00:00 +0000 Subject: feat(prs-create) add pr tag branch-name and title tag pr event with title, description and the name of the current checkedout branch --- src/git.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/git.rs') diff --git a/src/git.rs b/src/git.rs index 337444a..f9121f2 100644 --- a/src/git.rs +++ b/src/git.rs @@ -30,6 +30,7 @@ impl Repo { pub trait RepoActions { fn get_local_branch_names(&self) -> Result>; fn get_main_or_master_branch(&self) -> Result<(&str, Sha1Hash)>; + fn get_checked_out_branch_name(&self) -> Result; fn get_tip_of_local_branch(&self, branch_name: &str) -> Result; fn get_root_commit(&self, branch_name: &str) -> Result; fn get_head_commit(&self) -> Result; @@ -83,6 +84,15 @@ impl RepoActions for Repo { Ok(branch_names) } + fn get_checked_out_branch_name(&self) -> Result { + Ok(self + .git_repo + .head()? + .shorthand() + .context("an object without a shorthand is checked out")? + .to_string()) + } + fn get_tip_of_local_branch(&self, branch_name: &str) -> Result { let branch = self .git_repo @@ -378,6 +388,27 @@ mod tests { } } + mod get_checked_out_branch_name { + use super::*; + + #[test] + fn returns_checked_out_branch_name() -> Result<()> { + let test_repo = GitTestRepo::default(); + let _ = test_repo.populate()?; + // create feature branch + test_repo.create_branch("example-feature")?; + test_repo.checkout("example-feature")?; + + let git_repo = Repo::from_path(&test_repo.dir)?; + + assert_eq!( + git_repo.get_checked_out_branch_name()?, + "example-feature".to_string() + ); + Ok(()) + } + } + mod get_commits_ahead_behind { use super::*; mod returns_main { -- cgit v1.2.3