upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/lib/git_events.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/git_events.rs')
-rw-r--r--src/lib/git_events.rs33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/lib/git_events.rs b/src/lib/git_events.rs
index 5ea630a..56ebcef 100644
--- a/src/lib/git_events.rs
+++ b/src/lib/git_events.rs
@@ -1,4 +1,4 @@
1use std::{str::FromStr, sync::Arc}; 1use std::{collections::HashMap, str::FromStr, sync::Arc};
2 2
3use anyhow::{Context, Result, bail}; 3use anyhow::{Context, Result, bail};
4use nostr::{ 4use nostr::{
@@ -15,6 +15,7 @@ use crate::{
15 client::sign_event, 15 client::sign_event,
16 git::{Repo, RepoActions}, 16 git::{Repo, RepoActions},
17 repo_ref::RepoRef, 17 repo_ref::RepoRef,
18 utils::get_open_or_draft_proposals,
18}; 19};
19 20
20pub fn tag_value(event: &Event, tag_name: &str) -> Result<String> { 21pub fn tag_value(event: &Event, tag_name: &str) -> Result<String> {
@@ -925,6 +926,36 @@ pub fn get_status(
925 } 926 }
926} 927}
927 928
929pub async fn identify_clone_urls_for_oids_from_pr_pr_update_events(
930 oids: Vec<&String>,
931 git_repo: &Repo,
932 repo_ref: &RepoRef,
933) -> Result<HashMap<String, Vec<String>>> {
934 let mut map: HashMap<String, Vec<String>> = HashMap::new();
935
936 let open_and_draft_proposals = get_open_or_draft_proposals(git_repo, repo_ref).await?;
937
938 for (_, (_, events)) in open_and_draft_proposals {
939 for event in events {
940 if [KIND_PULL_REQUEST, KIND_PULL_REQUEST_UPDATE].contains(&event.kind) {
941 if let Ok(c) = tag_value(&event, "c") {
942 if oids.contains(&&c) {
943 for tag in event.tags.as_slice() {
944 if tag.kind().eq(&nostr::event::TagKind::Clone) {
945 for clone_url in tag.as_slice().iter().skip(1) {
946 map.entry(c.clone()).or_default().push(clone_url.clone());
947 }
948 }
949 }
950 }
951 }
952 }
953 }
954 }
955
956 Ok(map)
957}
958
928#[cfg(test)] 959#[cfg(test)]
929mod tests { 960mod tests {
930 use super::*; 961 use super::*;