upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/git.rs31
-rw-r--r--src/sub_commands/prs/create.rs20
2 files changed, 45 insertions, 6 deletions
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 {
30pub trait RepoActions { 30pub trait RepoActions {
31 fn get_local_branch_names(&self) -> Result<Vec<String>>; 31 fn get_local_branch_names(&self) -> Result<Vec<String>>;
32 fn get_main_or_master_branch(&self) -> Result<(&str, Sha1Hash)>; 32 fn get_main_or_master_branch(&self) -> Result<(&str, Sha1Hash)>;
33 fn get_checked_out_branch_name(&self) -> Result<String>;
33 fn get_tip_of_local_branch(&self, branch_name: &str) -> Result<Sha1Hash>; 34 fn get_tip_of_local_branch(&self, branch_name: &str) -> Result<Sha1Hash>;
34 fn get_root_commit(&self, branch_name: &str) -> Result<Sha1Hash>; 35 fn get_root_commit(&self, branch_name: &str) -> Result<Sha1Hash>;
35 fn get_head_commit(&self) -> Result<Sha1Hash>; 36 fn get_head_commit(&self) -> Result<Sha1Hash>;
@@ -83,6 +84,15 @@ impl RepoActions for Repo {
83 Ok(branch_names) 84 Ok(branch_names)
84 } 85 }
85 86
87 fn get_checked_out_branch_name(&self) -> Result<String> {
88 Ok(self
89 .git_repo
90 .head()?
91 .shorthand()
92 .context("an object without a shorthand is checked out")?
93 .to_string())
94 }
95
86 fn get_tip_of_local_branch(&self, branch_name: &str) -> Result<Sha1Hash> { 96 fn get_tip_of_local_branch(&self, branch_name: &str) -> Result<Sha1Hash> {
87 let branch = self 97 let branch = self
88 .git_repo 98 .git_repo
@@ -378,6 +388,27 @@ mod tests {
378 } 388 }
379 } 389 }
380 390
391 mod get_checked_out_branch_name {
392 use super::*;
393
394 #[test]
395 fn returns_checked_out_branch_name() -> Result<()> {
396 let test_repo = GitTestRepo::default();
397 let _ = test_repo.populate()?;
398 // create feature branch
399 test_repo.create_branch("example-feature")?;
400 test_repo.checkout("example-feature")?;
401
402 let git_repo = Repo::from_path(&test_repo.dir)?;
403
404 assert_eq!(
405 git_repo.get_checked_out_branch_name()?,
406 "example-feature".to_string()
407 );
408 Ok(())
409 }
410 }
411
381 mod get_commits_ahead_behind { 412 mod get_commits_ahead_behind {
382 use super::*; 413 use super::*;
383 mod returns_main { 414 mod returns_main {
diff --git a/src/sub_commands/prs/create.rs b/src/sub_commands/prs/create.rs
index 655978e..ce30c12 100644
--- a/src/sub_commands/prs/create.rs
+++ b/src/sub_commands/prs/create.rs
@@ -313,15 +313,23 @@ fn generate_pr_and_patch_events(
313 .get_root_commit(to_branch) 313 .get_root_commit(to_branch)
314 .context("failed to get root commit of the repository")?; 314 .context("failed to get root commit of the repository")?;
315 315
316 let mut pr_tags = vec![
317 Tag::Reference(format!("r-{root_commit}")),
318 Tag::Name(title.to_string()),
319 Tag::Description(description.to_string()),
320 ];
321
322 if let Ok(branch_name) = git_repo.get_checked_out_branch_name() {
323 pr_tags.push(Tag::Generic(
324 TagKind::Custom("branch-name".to_string()),
325 vec![branch_name],
326 ));
327 }
328
316 let pr_event = EventBuilder::new( 329 let pr_event = EventBuilder::new(
317 nostr::event::Kind::Custom(PR_KIND), 330 nostr::event::Kind::Custom(PR_KIND),
318 format!("{title}\r\n\r\n{description}"), 331 format!("{title}\r\n\r\n{description}"),
319 &[Tag::Reference(format!("r-{root_commit}"))], 332 &pr_tags,
320 // TODO: suggested branch name
321 // Tag::Generic(
322 // TagKind::Custom("suggested-branch-name".to_string()),
323 // vec![],
324 // ),
325 // TODO: add Repo event as root 333 // TODO: add Repo event as root
326 // TODO: people tag maintainers 334 // TODO: people tag maintainers
327 // TODO: add relay tags 335 // TODO: add relay tags