diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-07-23 10:33:20 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-07-23 10:33:20 +0100 |
| commit | f7299cc5fd2276db8d9bb7778c34ddbe5b3a8e48 (patch) | |
| tree | 5dabff678d0502766a78c04422e90611f8c3fcbb /src/bin/git_remote_nostr/utils.rs | |
| parent | b4253bb0c543ceef896e0a95482b5403a29a7878 (diff) | |
feat(pr): patch upgraded to pr inherit pr status
when a patch is upgraded to a pr, eg because new commits would be
too large to be additional patches, the patch receives a closed
staus and the new pr 'e' tags the original root patch.
we therefore need to inherit the new pr's status instead of using
the closed status.
the closed status was used so that clients don't have to support
pr revisions of patches, and still have a good UX.
Diffstat (limited to 'src/bin/git_remote_nostr/utils.rs')
| -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 | } |