upleb.uk

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

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-12-20 10:25:22 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2024-12-20 10:25:22 +0000
commit97de61aef110414bad8a1a3f8506e9c1efb37402 (patch)
treeeee50aff78624b30ff9960d181df5adefdd29ea8
parent4bab25d575fa82785a424038e517b09e9485bad3 (diff)
feat(remote): include draft PRs
show draft as well as open PRs as remote branches
-rw-r--r--src/bin/git_remote_nostr/fetch.rs12
-rw-r--r--src/bin/git_remote_nostr/list.rs10
-rw-r--r--src/bin/git_remote_nostr/utils.rs10
3 files changed, 16 insertions, 16 deletions
diff --git a/src/bin/git_remote_nostr/fetch.rs b/src/bin/git_remote_nostr/fetch.rs
index 024a923..5ee4271 100644
--- a/src/bin/git_remote_nostr/fetch.rs
+++ b/src/bin/git_remote_nostr/fetch.rs
@@ -25,8 +25,8 @@ use nostr_sdk::{Event, ToBech32};
25 25
26use crate::utils::{ 26use crate::utils::{
27 Direction, fetch_or_list_error_is_not_authentication_failure, 27 Direction, fetch_or_list_error_is_not_authentication_failure,
28 find_proposal_and_patches_by_branch_name, get_oids_from_fetch_batch, get_open_proposals, 28 find_proposal_and_patches_by_branch_name, get_oids_from_fetch_batch,
29 get_read_protocols_to_try, join_with_and, set_protocol_preference, 29 get_open_or_draft_proposals, get_read_protocols_to_try, join_with_and, set_protocol_preference,
30}; 30};
31 31
32pub async fn run_fetch( 32pub async fn run_fetch(
@@ -79,7 +79,7 @@ pub async fn run_fetch(
79 79
80 fetch_batch.retain(|refstr, _| refstr.contains("refs/heads/pr/")); 80 fetch_batch.retain(|refstr, _| refstr.contains("refs/heads/pr/"));
81 81
82 fetch_proposals(git_repo, &term, repo_ref, &fetch_batch).await?; 82 fetch_open_or_draft_proposals(git_repo, &term, repo_ref, &fetch_batch).await?;
83 term.flush()?; 83 term.flush()?;
84 println!(); 84 println!();
85 Ok(()) 85 Ok(())
@@ -128,21 +128,21 @@ pub fn make_commits_for_proposal(
128 Ok(tip_commit_id) 128 Ok(tip_commit_id)
129} 129}
130 130
131async fn fetch_proposals( 131async fn fetch_open_or_draft_proposals(
132 git_repo: &Repo, 132 git_repo: &Repo,
133 term: &console::Term, 133 term: &console::Term,
134 repo_ref: &RepoRef, 134 repo_ref: &RepoRef,
135 proposal_refs: &HashMap<String, String>, 135 proposal_refs: &HashMap<String, String>,
136) -> Result<()> { 136) -> Result<()> {
137 if !proposal_refs.is_empty() { 137 if !proposal_refs.is_empty() {
138 let open_proposals = get_open_proposals(git_repo, repo_ref).await?; 138 let open_and_draft_proposals = get_open_or_draft_proposals(git_repo, repo_ref).await?;
139 139
140 let current_user = get_curent_user(git_repo)?; 140 let current_user = get_curent_user(git_repo)?;
141 141
142 for refstr in proposal_refs.keys() { 142 for refstr in proposal_refs.keys() {
143 if let Some((_, (_, patches))) = find_proposal_and_patches_by_branch_name( 143 if let Some((_, (_, patches))) = find_proposal_and_patches_by_branch_name(
144 refstr, 144 refstr,
145 &open_proposals, 145 &open_and_draft_proposals,
146 current_user.as_ref(), 146 current_user.as_ref(),
147 ) { 147 ) {
148 if let Err(error) = make_commits_for_proposal(git_repo, repo_ref, patches) { 148 if let Err(error) = make_commits_for_proposal(git_repo, repo_ref, patches) {
diff --git a/src/bin/git_remote_nostr/list.rs b/src/bin/git_remote_nostr/list.rs
index f361272..b802a4a 100644
--- a/src/bin/git_remote_nostr/list.rs
+++ b/src/bin/git_remote_nostr/list.rs
@@ -22,7 +22,7 @@ use crate::{
22 fetch::{fetch_from_git_server, make_commits_for_proposal}, 22 fetch::{fetch_from_git_server, make_commits_for_proposal},
23 git::Repo, 23 git::Repo,
24 utils::{ 24 utils::{
25 Direction, fetch_or_list_error_is_not_authentication_failure, get_open_proposals, 25 Direction, fetch_or_list_error_is_not_authentication_failure, get_open_or_draft_proposals,
26 get_read_protocols_to_try, get_short_git_server_name, join_with_and, 26 get_read_protocols_to_try, get_short_git_server_name, join_with_and,
27 set_protocol_preference, 27 set_protocol_preference,
28 }, 28 },
@@ -93,7 +93,7 @@ pub async fn run_list(
93 state.retain(|k, _| !k.starts_with("refs/heads/pr/")); 93 state.retain(|k, _| !k.starts_with("refs/heads/pr/"));
94 94
95 let proposals_state = 95 let proposals_state =
96 get_open_proposals_state(&term, git_repo, repo_ref, &remote_states).await?; 96 get_open_and_draft_proposals_state(&term, git_repo, repo_ref, &remote_states).await?;
97 97
98 state.extend(proposals_state); 98 state.extend(proposals_state);
99 99
@@ -113,7 +113,7 @@ pub async fn run_list(
113 Ok(remote_states) 113 Ok(remote_states)
114} 114}
115 115
116async fn get_open_proposals_state( 116async fn get_open_and_draft_proposals_state(
117 term: &console::Term, 117 term: &console::Term,
118 git_repo: &Repo, 118 git_repo: &Repo,
119 repo_ref: &RepoRef, 119 repo_ref: &RepoRef,
@@ -145,9 +145,9 @@ async fn get_open_proposals_state(
145 } 145 }
146 146
147 let mut state = HashMap::new(); 147 let mut state = HashMap::new();
148 let open_proposals = get_open_proposals(git_repo, repo_ref).await?; 148 let open_and_draft_proposals = get_open_or_draft_proposals(git_repo, repo_ref).await?;
149 let current_user = get_curent_user(git_repo)?; 149 let current_user = get_curent_user(git_repo)?;
150 for (_, (proposal, patches)) in open_proposals { 150 for (_, (proposal, patches)) in open_and_draft_proposals {
151 if let Ok(cl) = event_to_cover_letter(&proposal) { 151 if let Ok(cl) = event_to_cover_letter(&proposal) {
152 if let Ok(mut branch_name) = cl.get_branch_name_with_pr_prefix_and_shorthand_id() { 152 if let Ok(mut branch_name) = cl.get_branch_name_with_pr_prefix_and_shorthand_id() {
153 branch_name = if let Some(public_key) = current_user { 153 branch_name = if let Some(public_key) = current_user {
diff --git a/src/bin/git_remote_nostr/utils.rs b/src/bin/git_remote_nostr/utils.rs
index 316fedb..5048ce2 100644
--- a/src/bin/git_remote_nostr/utils.rs
+++ b/src/bin/git_remote_nostr/utils.rs
@@ -94,7 +94,7 @@ pub fn read_line<'a>(stdin: &io::Stdin, line: &'a mut String) -> io::Result<Vec<
94 Ok(tokens) 94 Ok(tokens)
95} 95}
96 96
97pub async fn get_open_proposals( 97pub async fn get_open_or_draft_proposals(
98 git_repo: &Repo, 98 git_repo: &Repo,
99 repo_ref: &RepoRef, 99 repo_ref: &RepoRef,
100) -> Result<HashMap<EventId, (Event, Vec<Event>)>> { 100) -> Result<HashMap<EventId, (Event, Vec<Event>)>> {
@@ -118,7 +118,7 @@ pub async fn get_open_proposals(
118 statuses.reverse(); 118 statuses.reverse();
119 statuses 119 statuses
120 }; 120 };
121 let mut open_proposals = HashMap::new(); 121 let mut open_or_draft_proposals = HashMap::new();
122 122
123 for proposal in proposals { 123 for proposal in proposals {
124 let status = if let Some(e) = statuses 124 let status = if let Some(e) = statuses
@@ -136,7 +136,7 @@ pub async fn get_open_proposals(
136 } else { 136 } else {
137 Kind::GitStatusOpen 137 Kind::GitStatusOpen
138 }; 138 };
139 if status.eq(&Kind::GitStatusOpen) { 139 if [Kind::GitStatusOpen, Kind::GitStatusDraft].contains(&status) {
140 if let Ok(commits_events) = 140 if let Ok(commits_events) =
141 get_all_proposal_patch_events_from_cache(git_repo_path, repo_ref, &proposal.id) 141 get_all_proposal_patch_events_from_cache(git_repo_path, repo_ref, &proposal.id)
142 .await 142 .await
@@ -144,13 +144,13 @@ pub async fn get_open_proposals(
144 if let Ok(most_recent_proposal_patch_chain) = 144 if let Ok(most_recent_proposal_patch_chain) =
145 get_most_recent_patch_with_ancestors(commits_events.clone()) 145 get_most_recent_patch_with_ancestors(commits_events.clone())
146 { 146 {
147 open_proposals 147 open_or_draft_proposals
148 .insert(proposal.id, (proposal, most_recent_proposal_patch_chain)); 148 .insert(proposal.id, (proposal, most_recent_proposal_patch_chain));
149 } 149 }
150 } 150 }
151 } 151 }
152 } 152 }
153 Ok(open_proposals) 153 Ok(open_or_draft_proposals)
154} 154}
155 155
156pub async fn get_all_proposals( 156pub async fn get_all_proposals(