diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-06-19 09:30:16 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-06-19 09:30:16 +0100 |
| commit | 9386cc2e409cc4117ae1792411179a9cd986b3f3 (patch) | |
| tree | 79d7c002f24eae80bf9d274e081ea1f7435e27e7 /src/lib | |
| parent | 20f2680394e0b62864b1b192338b3cd7ecdad4ec (diff) | |
refactor: move build state function
in preparation for enforcing the inclusion of HEAD
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/repo_state.rs | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/src/lib/repo_state.rs b/src/lib/repo_state.rs index aa60f54..8eba1af 100644 --- a/src/lib/repo_state.rs +++ b/src/lib/repo_state.rs | |||
| @@ -1,7 +1,13 @@ | |||
| 1 | use std::collections::HashMap; | 1 | use std::{collections::HashMap, sync::Arc}; |
| 2 | 2 | ||
| 3 | use anyhow::{Context, Result}; | 3 | use anyhow::{Context, Result}; |
| 4 | use git2::Oid; | 4 | use git2::Oid; |
| 5 | use nostr::{ | ||
| 6 | event::{EventBuilder, Tag}, | ||
| 7 | signer::NostrSigner, | ||
| 8 | }; | ||
| 9 | |||
| 10 | use crate::client::{STATE_KIND, sign_event}; | ||
| 5 | 11 | ||
| 6 | pub struct RepoState { | 12 | pub struct RepoState { |
| 7 | pub identifier: String, | 13 | pub identifier: String, |
| @@ -58,4 +64,28 @@ impl RepoState { | |||
| 58 | event: event.clone(), | 64 | event: event.clone(), |
| 59 | }) | 65 | }) |
| 60 | } | 66 | } |
| 67 | |||
| 68 | pub async fn build( | ||
| 69 | identifier: String, | ||
| 70 | state: HashMap<String, String>, | ||
| 71 | signer: &Arc<dyn NostrSigner>, | ||
| 72 | ) -> Result<Self> { | ||
| 73 | let mut tags = vec![Tag::identifier(identifier.clone())]; | ||
| 74 | for (name, value) in &state { | ||
| 75 | tags.push(Tag::custom(nostr_sdk::TagKind::Custom(name.into()), vec![ | ||
| 76 | value.clone(), | ||
| 77 | ])); | ||
| 78 | } | ||
| 79 | let event = sign_event( | ||
| 80 | EventBuilder::new(STATE_KIND, "").tags(tags), | ||
| 81 | signer, | ||
| 82 | "git state".to_string(), | ||
| 83 | ) | ||
| 84 | .await?; | ||
| 85 | Ok(RepoState { | ||
| 86 | identifier, | ||
| 87 | state, | ||
| 88 | event, | ||
| 89 | }) | ||
| 90 | } | ||
| 61 | } | 91 | } |