upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/lib/repo_state.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-06-19 09:30:16 +0100
committerDanConwayDev <DanConwayDev@protonmail.com>2025-06-19 09:30:16 +0100
commit9386cc2e409cc4117ae1792411179a9cd986b3f3 (patch)
tree79d7c002f24eae80bf9d274e081ea1f7435e27e7 /src/lib/repo_state.rs
parent20f2680394e0b62864b1b192338b3cd7ecdad4ec (diff)
refactor: move build state function
in preparation for enforcing the inclusion of HEAD
Diffstat (limited to 'src/lib/repo_state.rs')
-rw-r--r--src/lib/repo_state.rs32
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 @@
1use std::collections::HashMap; 1use std::{collections::HashMap, sync::Arc};
2 2
3use anyhow::{Context, Result}; 3use anyhow::{Context, Result};
4use git2::Oid; 4use git2::Oid;
5use nostr::{
6 event::{EventBuilder, Tag},
7 signer::NostrSigner,
8};
9
10use crate::client::{STATE_KIND, sign_event};
5 11
6pub struct RepoState { 12pub 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}