diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-01-22 00:00:00 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-01-22 00:00:00 +0000 |
| commit | 675d44b8349078f2d231ca37a1621254a4c50ab5 (patch) | |
| tree | 784286231dc6fade15266a6327b58daffe5bb1c8 /src | |
| parent | 9200b96bd8fe7ac254e41048790d7411937c3f95 (diff) | |
feat(git) save pgp sig in patch event
so that commit ids can be maintained
Diffstat (limited to 'src')
| -rw-r--r-- | src/git.rs | 17 | ||||
| -rw-r--r-- | src/sub_commands/prs/create.rs | 8 |
2 files changed, 25 insertions, 0 deletions
| @@ -53,6 +53,7 @@ pub trait RepoActions { | |||
| 53 | latest_commit: &Sha1Hash, | 53 | latest_commit: &Sha1Hash, |
| 54 | ) -> Result<(Vec<Sha1Hash>, Vec<Sha1Hash>)>; | 54 | ) -> Result<(Vec<Sha1Hash>, Vec<Sha1Hash>)>; |
| 55 | fn make_patch_from_commit(&self, commit: &Sha1Hash) -> Result<String>; | 55 | fn make_patch_from_commit(&self, commit: &Sha1Hash) -> Result<String>; |
| 56 | fn extract_commit_pgp_signature(&self, commit: &Sha1Hash) -> Result<String>; | ||
| 56 | fn checkout(&self, ref_name: &str) -> Result<Sha1Hash>; | 57 | fn checkout(&self, ref_name: &str) -> Result<Sha1Hash>; |
| 57 | fn create_branch_at_commit(&self, branch_name: &str, commit: &str) -> Result<()>; | 58 | fn create_branch_at_commit(&self, branch_name: &str, commit: &str) -> Result<()>; |
| 58 | fn apply_patch_chain( | 59 | fn apply_patch_chain( |
| @@ -225,6 +226,22 @@ impl RepoActions for Repo { | |||
| 225 | .to_owned()) | 226 | .to_owned()) |
| 226 | } | 227 | } |
| 227 | 228 | ||
| 229 | fn extract_commit_pgp_signature(&self, commit: &Sha1Hash) -> Result<String> { | ||
| 230 | let oid = Oid::from_bytes(commit.as_byte_array()).context(format!( | ||
| 231 | "failed to convert commit_id format for {}", | ||
| 232 | &commit | ||
| 233 | ))?; | ||
| 234 | |||
| 235 | let (sign, _data) = self | ||
| 236 | .git_repo | ||
| 237 | .extract_signature(&oid, None) | ||
| 238 | .context("failed to extract signature - perhaps there is no signature?")?; | ||
| 239 | |||
| 240 | Ok(std::str::from_utf8(&sign) | ||
| 241 | .context("commit signature cannot be converted to a utf8 string")? | ||
| 242 | .to_owned()) | ||
| 243 | } | ||
| 244 | |||
| 228 | fn get_commits_ahead_behind( | 245 | fn get_commits_ahead_behind( |
| 229 | &self, | 246 | &self, |
| 230 | base_commit: &Sha1Hash, | 247 | 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( | |||
| 382 | TagKind::Custom("parent-commit".to_string()), | 382 | TagKind::Custom("parent-commit".to_string()), |
| 383 | vec![commit_parent.to_string()], | 383 | vec![commit_parent.to_string()], |
| 384 | ), | 384 | ), |
| 385 | Tag::Generic( | ||
| 386 | TagKind::Custom("commit-sig".to_string()), | ||
| 387 | vec![ | ||
| 388 | git_repo | ||
| 389 | .extract_commit_pgp_signature(commit) | ||
| 390 | .unwrap_or_default(), | ||
| 391 | ], | ||
| 392 | ), | ||
| 385 | Tag::Description(git_repo.get_commit_message(commit)?.to_string()), | 393 | Tag::Description(git_repo.get_commit_message(commit)?.to_string()), |
| 386 | Tag::Generic( | 394 | Tag::Generic( |
| 387 | TagKind::Custom("author".to_string()), | 395 | TagKind::Custom("author".to_string()), |