upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/nostr
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-11-26 05:45:47 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2025-11-26 07:38:58 +0000
commit30411a938d072a59d68815c975735d40366ad874 (patch)
treef802d1bf9f9959105d2d18af81c528722fa7a675 /src/nostr
parenta005132ab806b7177d4eb3e3306914841704ffec (diff)
feat: push authorization from state event
Diffstat (limited to 'src/nostr')
-rw-r--r--src/nostr/events.rs68
1 files changed, 36 insertions, 32 deletions
diff --git a/src/nostr/events.rs b/src/nostr/events.rs
index 21dd2dd..ddbb8f0 100644
--- a/src/nostr/events.rs
+++ b/src/nostr/events.rs
@@ -199,23 +199,25 @@ impl RepositoryState {
199 .to_string(); 199 .to_string();
200 200
201 // Extract branches (refs/heads/*) 201 // Extract branches (refs/heads/*)
202 // Tag format: ["refs/heads/main", "commit_hash"]
202 let branches = event 203 let branches = event
203 .tags 204 .tags
204 .iter() 205 .iter()
205 .filter(|t| {
206 if let TagKind::Custom(s) = t.kind() {
207 s.as_ref() == "ref"
208 } else {
209 false
210 }
211 })
212 .filter_map(|t| { 206 .filter_map(|t| {
213 let parts = t.clone().to_vec(); 207 if let TagKind::Custom(s) = t.kind() {
214 if parts.len() >= 3 && parts[1].starts_with("refs/heads/") { 208 if s.as_ref().starts_with("refs/heads/") {
215 Some(BranchState { 209 let parts = t.clone().to_vec();
216 name: parts[1].strip_prefix("refs/heads/").unwrap().to_string(), 210 if parts.len() >= 2 {
217 commit: parts[2].clone(), 211 Some(BranchState {
218 }) 212 name: s.as_ref().strip_prefix("refs/heads/").unwrap().to_string(),
213 commit: parts[1].clone(),
214 })
215 } else {
216 None
217 }
218 } else {
219 None
220 }
219 } else { 221 } else {
220 None 222 None
221 } 223 }
@@ -223,23 +225,25 @@ impl RepositoryState {
223 .collect(); 225 .collect();
224 226
225 // Extract tags (refs/tags/*) 227 // Extract tags (refs/tags/*)
228 // Tag format: ["refs/tags/v1.0", "commit_hash"]
226 let tags = event 229 let tags = event
227 .tags 230 .tags
228 .iter() 231 .iter()
229 .filter(|t| {
230 if let TagKind::Custom(s) = t.kind() {
231 s.as_ref() == "ref"
232 } else {
233 false
234 }
235 })
236 .filter_map(|t| { 232 .filter_map(|t| {
237 let parts = t.clone().to_vec(); 233 if let TagKind::Custom(s) = t.kind() {
238 if parts.len() >= 3 && parts[1].starts_with("refs/tags/") { 234 if s.as_ref().starts_with("refs/tags/") {
239 Some(TagState { 235 let parts = t.clone().to_vec();
240 name: parts[1].strip_prefix("refs/tags/").unwrap().to_string(), 236 if parts.len() >= 2 {
241 commit: parts[2].clone(), 237 Some(TagState {
242 }) 238 name: s.as_ref().strip_prefix("refs/tags/").unwrap().to_string(),
239 commit: parts[1].clone(),
240 })
241 } else {
242 None
243 }
244 } else {
245 None
246 }
243 } else { 247 } else {
244 None 248 None
245 } 249 }
@@ -384,8 +388,8 @@ mod tests {
384 388
385 for (branch, commit) in branches { 389 for (branch, commit) in branches {
386 tags.push(Tag::custom( 390 tags.push(Tag::custom(
387 nostr_sdk::TagKind::Custom("ref".into()), 391 nostr_sdk::TagKind::Custom(format!("refs/heads/{}", branch).into()),
388 vec![format!("refs/heads/{}", branch), commit.to_string()], 392 vec![commit.to_string()],
389 )); 393 ));
390 } 394 }
391 395
@@ -566,14 +570,14 @@ mod tests {
566 570
567 // Add branch 571 // Add branch
568 tags.push(Tag::custom( 572 tags.push(Tag::custom(
569 nostr_sdk::TagKind::Custom("ref".into()), 573 nostr_sdk::TagKind::Custom("refs/heads/main".into()),
570 vec!["refs/heads/main".to_string(), "a1b2c3d4".to_string()], 574 vec!["a1b2c3d4".to_string()],
571 )); 575 ));
572 576
573 // Add tag 577 // Add tag
574 tags.push(Tag::custom( 578 tags.push(Tag::custom(
575 nostr_sdk::TagKind::Custom("ref".into()), 579 nostr_sdk::TagKind::Custom("refs/tags/v1.0.0".into()),
576 vec!["refs/tags/v1.0.0".to_string(), "e5f6g7h8".to_string()], 580 vec!["e5f6g7h8".to_string()],
577 )); 581 ));
578 582
579 let event = EventBuilder::new(Kind::from(KIND_REPOSITORY_STATE), "") 583 let event = EventBuilder::new(Kind::from(KIND_REPOSITORY_STATE), "")