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 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/git.rs') 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, -- cgit v1.2.3