From 675d44b8349078f2d231ca37a1621254a4c50ab5 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Mon, 22 Jan 2024 00:00:00 +0000 Subject: feat(git) save pgp sig in patch event so that commit ids can be maintained --- src/git.rs | 17 +++++++++++++++++ src/sub_commands/prs/create.rs | 8 ++++++++ 2 files changed, 25 insertions(+) (limited to 'src') diff --git a/src/git.rs b/src/git.rs index 29670eb..7292508 100644 --- a/src/git.rs +++ b/src/git.rs @@ -53,6 +53,7 @@ pub trait RepoActions { latest_commit: &Sha1Hash, ) -> Result<(Vec, Vec)>; fn make_patch_from_commit(&self, commit: &Sha1Hash) -> Result; + fn extract_commit_pgp_signature(&self, commit: &Sha1Hash) -> Result; fn checkout(&self, ref_name: &str) -> Result; fn create_branch_at_commit(&self, branch_name: &str, commit: &str) -> Result<()>; fn apply_patch_chain( @@ -225,6 +226,22 @@ impl RepoActions for Repo { .to_owned()) } + fn extract_commit_pgp_signature(&self, commit: &Sha1Hash) -> Result { + let oid = Oid::from_bytes(commit.as_byte_array()).context(format!( + "failed to convert commit_id format for {}", + &commit + ))?; + + let (sign, _data) = self + .git_repo + .extract_signature(&oid, None) + .context("failed to extract signature - perhaps there is no signature?")?; + + Ok(std::str::from_utf8(&sign) + .context("commit signature cannot be converted to a utf8 string")? + .to_owned()) + } + fn get_commits_ahead_behind( &self, base_commit: &Sha1Hash, diff --git a/src/sub_commands/prs/create.rs b/src/sub_commands/prs/create.rs index 5e41a56..e5d6262 100644 --- a/src/sub_commands/prs/create.rs +++ b/src/sub_commands/prs/create.rs @@ -382,6 +382,14 @@ pub fn generate_patch_event( TagKind::Custom("parent-commit".to_string()), vec![commit_parent.to_string()], ), + Tag::Generic( + TagKind::Custom("commit-sig".to_string()), + vec![ + git_repo + .extract_commit_pgp_signature(commit) + .unwrap_or_default(), + ], + ), Tag::Description(git_repo.get_commit_message(commit)?.to_string()), Tag::Generic( TagKind::Custom("author".to_string()), -- cgit v1.2.3