diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-08-18 17:25:50 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-08-19 07:48:16 +0100 |
| commit | b7d4c5a81f0a008524dcc5b4f286f0cf700013c0 (patch) | |
| tree | 9efc97803252d1021df767fe781c2fc91babf80b /src/lib/git_events.rs | |
| parent | 4d68e64ac4f08274aba6ff225bd89a60eb62e225 (diff) | |
feat(list): add PR fetch and checkout support
abstracted git remote helper fetch functions
added support to `ngit list` to fetch PR data and checkout as proposal
branch
Diffstat (limited to 'src/lib/git_events.rs')
| -rw-r--r-- | src/lib/git_events.rs | 33 |
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 @@ | |||
| 1 | use std::{str::FromStr, sync::Arc}; | 1 | use std::{collections::HashMap, str::FromStr, sync::Arc}; |
| 2 | 2 | ||
| 3 | use anyhow::{Context, Result, bail}; | 3 | use anyhow::{Context, Result, bail}; |
| 4 | use nostr::{ | 4 | use 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 | ||
| 20 | pub fn tag_value(event: &Event, tag_name: &str) -> Result<String> { | 21 | pub fn tag_value(event: &Event, tag_name: &str) -> Result<String> { |
| @@ -925,6 +926,36 @@ pub fn get_status( | |||
| 925 | } | 926 | } |
| 926 | } | 927 | } |
| 927 | 928 | ||
| 929 | pub 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)] |
| 929 | mod tests { | 960 | mod tests { |
| 930 | use super::*; | 961 | use super::*; |