diff options
Diffstat (limited to 'src/bin')
| -rw-r--r-- | src/bin/git_remote_nostr/utils.rs | 43 |
1 files changed, 35 insertions, 8 deletions
diff --git a/src/bin/git_remote_nostr/utils.rs b/src/bin/git_remote_nostr/utils.rs index 563c0d8..8433967 100644 --- a/src/bin/git_remote_nostr/utils.rs +++ b/src/bin/git_remote_nostr/utils.rs | |||
| @@ -18,8 +18,9 @@ use ngit::{ | |||
| 18 | nostr_url::{CloneUrl, NostrUrlDecoded, ServerProtocol}, | 18 | nostr_url::{CloneUrl, NostrUrlDecoded, ServerProtocol}, |
| 19 | }, | 19 | }, |
| 20 | git_events::{ | 20 | git_events::{ |
| 21 | event_is_revision_root, get_pr_tip_event_or_most_recent_patch_with_ancestors, | 21 | KIND_PULL_REQUEST, event_is_revision_root, |
| 22 | is_event_proposal_root_for_branch, status_kinds, | 22 | get_pr_tip_event_or_most_recent_patch_with_ancestors, is_event_proposal_root_for_branch, |
| 23 | status_kinds, | ||
| 23 | }, | 24 | }, |
| 24 | repo_ref::RepoRef, | 25 | repo_ref::RepoRef, |
| 25 | }; | 26 | }; |
| @@ -123,8 +124,8 @@ pub async fn get_open_or_draft_proposals( | |||
| 123 | }; | 124 | }; |
| 124 | let mut open_or_draft_proposals = HashMap::new(); | 125 | let mut open_or_draft_proposals = HashMap::new(); |
| 125 | 126 | ||
| 126 | for proposal in proposals { | 127 | let get_status = |proposal: &Event| { |
| 127 | let status = if let Some(e) = statuses | 128 | if let Some(e) = statuses |
| 128 | .iter() | 129 | .iter() |
| 129 | .filter(|e| { | 130 | .filter(|e| { |
| 130 | status_kinds().contains(&e.kind) | 131 | status_kinds().contains(&e.kind) |
| @@ -139,8 +140,32 @@ pub async fn get_open_or_draft_proposals( | |||
| 139 | e.kind | 140 | e.kind |
| 140 | } else { | 141 | } else { |
| 141 | Kind::GitStatusOpen | 142 | Kind::GitStatusOpen |
| 142 | }; | 143 | } |
| 143 | if [Kind::GitStatusOpen, Kind::GitStatusDraft].contains(&status) { | 144 | }; |
| 145 | |||
| 146 | let is_proposal_pr_revision_of_patch = |proposal: &Event, patch: &Event| { | ||
| 147 | proposal.kind.eq(&KIND_PULL_REQUEST) | ||
| 148 | && proposal.tags.clone().into_iter().any(|t| { | ||
| 149 | t.as_slice().len() > 1 | ||
| 150 | && t.as_slice()[0].eq("e") | ||
| 151 | && t.as_slice()[1].eq(&patch.id.to_string()) | ||
| 152 | && [Kind::GitStatusOpen, Kind::GitStatusDraft].contains(&get_status(proposal)) | ||
| 153 | }) | ||
| 154 | }; | ||
| 155 | |||
| 156 | for proposal in &proposals { | ||
| 157 | let status = get_status(proposal); | ||
| 158 | if [Kind::GitStatusOpen, Kind::GitStatusDraft].contains(&status) | ||
| 159 | || // or patch has been revised as a PR which is open or draft | ||
| 160 | ( | ||
| 161 | status.eq(&Kind::GitStatusClosed) && | ||
| 162 | proposal.kind.eq(&Kind::GitPatch) && | ||
| 163 | proposals.iter() | ||
| 164 | .any(|p| { | ||
| 165 | is_proposal_pr_revision_of_patch(p, proposal) | ||
| 166 | }) | ||
| 167 | ) | ||
| 168 | { | ||
| 144 | if let Ok(commits_events) = get_all_proposal_patch_pr_pr_update_events_from_cache( | 169 | if let Ok(commits_events) = get_all_proposal_patch_pr_pr_update_events_from_cache( |
| 145 | git_repo_path, | 170 | git_repo_path, |
| 146 | repo_ref, | 171 | repo_ref, |
| @@ -151,8 +176,10 @@ pub async fn get_open_or_draft_proposals( | |||
| 151 | if let Ok(most_recent_proposal_patch_chain) = | 176 | if let Ok(most_recent_proposal_patch_chain) = |
| 152 | get_pr_tip_event_or_most_recent_patch_with_ancestors(commits_events.clone()) | 177 | get_pr_tip_event_or_most_recent_patch_with_ancestors(commits_events.clone()) |
| 153 | { | 178 | { |
| 154 | open_or_draft_proposals | 179 | open_or_draft_proposals.insert( |
| 155 | .insert(proposal.id, (proposal, most_recent_proposal_patch_chain)); | 180 | proposal.id, |
| 181 | (proposal.clone(), most_recent_proposal_patch_chain), | ||
| 182 | ); | ||
| 156 | } | 183 | } |
| 157 | } | 184 | } |
| 158 | } | 185 | } |