From 97de61aef110414bad8a1a3f8506e9c1efb37402 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Fri, 20 Dec 2024 10:25:22 +0000 Subject: feat(remote): include draft PRs show draft as well as open PRs as remote branches --- src/bin/git_remote_nostr/fetch.rs | 12 ++++++------ src/bin/git_remote_nostr/list.rs | 10 +++++----- src/bin/git_remote_nostr/utils.rs | 10 +++++----- 3 files changed, 16 insertions(+), 16 deletions(-) (limited to 'src/bin/git_remote_nostr') 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}; use crate::utils::{ Direction, fetch_or_list_error_is_not_authentication_failure, - find_proposal_and_patches_by_branch_name, get_oids_from_fetch_batch, get_open_proposals, - get_read_protocols_to_try, join_with_and, set_protocol_preference, + find_proposal_and_patches_by_branch_name, get_oids_from_fetch_batch, + get_open_or_draft_proposals, get_read_protocols_to_try, join_with_and, set_protocol_preference, }; pub async fn run_fetch( @@ -79,7 +79,7 @@ pub async fn run_fetch( fetch_batch.retain(|refstr, _| refstr.contains("refs/heads/pr/")); - fetch_proposals(git_repo, &term, repo_ref, &fetch_batch).await?; + fetch_open_or_draft_proposals(git_repo, &term, repo_ref, &fetch_batch).await?; term.flush()?; println!(); Ok(()) @@ -128,21 +128,21 @@ pub fn make_commits_for_proposal( Ok(tip_commit_id) } -async fn fetch_proposals( +async fn fetch_open_or_draft_proposals( git_repo: &Repo, term: &console::Term, repo_ref: &RepoRef, proposal_refs: &HashMap, ) -> Result<()> { if !proposal_refs.is_empty() { - let open_proposals = get_open_proposals(git_repo, repo_ref).await?; + let open_and_draft_proposals = get_open_or_draft_proposals(git_repo, repo_ref).await?; let current_user = get_curent_user(git_repo)?; for refstr in proposal_refs.keys() { if let Some((_, (_, patches))) = find_proposal_and_patches_by_branch_name( refstr, - &open_proposals, + &open_and_draft_proposals, current_user.as_ref(), ) { 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::{ fetch::{fetch_from_git_server, make_commits_for_proposal}, git::Repo, utils::{ - Direction, fetch_or_list_error_is_not_authentication_failure, get_open_proposals, + Direction, fetch_or_list_error_is_not_authentication_failure, get_open_or_draft_proposals, get_read_protocols_to_try, get_short_git_server_name, join_with_and, set_protocol_preference, }, @@ -93,7 +93,7 @@ pub async fn run_list( state.retain(|k, _| !k.starts_with("refs/heads/pr/")); let proposals_state = - get_open_proposals_state(&term, git_repo, repo_ref, &remote_states).await?; + get_open_and_draft_proposals_state(&term, git_repo, repo_ref, &remote_states).await?; state.extend(proposals_state); @@ -113,7 +113,7 @@ pub async fn run_list( Ok(remote_states) } -async fn get_open_proposals_state( +async fn get_open_and_draft_proposals_state( term: &console::Term, git_repo: &Repo, repo_ref: &RepoRef, @@ -145,9 +145,9 @@ async fn get_open_proposals_state( } let mut state = HashMap::new(); - let open_proposals = get_open_proposals(git_repo, repo_ref).await?; + let open_and_draft_proposals = get_open_or_draft_proposals(git_repo, repo_ref).await?; let current_user = get_curent_user(git_repo)?; - for (_, (proposal, patches)) in open_proposals { + for (_, (proposal, patches)) in open_and_draft_proposals { if let Ok(cl) = event_to_cover_letter(&proposal) { if let Ok(mut branch_name) = cl.get_branch_name_with_pr_prefix_and_shorthand_id() { 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 Result)>> { @@ -118,7 +118,7 @@ pub async fn get_open_proposals( statuses.reverse(); statuses }; - let mut open_proposals = HashMap::new(); + let mut open_or_draft_proposals = HashMap::new(); for proposal in proposals { let status = if let Some(e) = statuses @@ -136,7 +136,7 @@ pub async fn get_open_proposals( } else { Kind::GitStatusOpen }; - if status.eq(&Kind::GitStatusOpen) { + if [Kind::GitStatusOpen, Kind::GitStatusDraft].contains(&status) { if let Ok(commits_events) = get_all_proposal_patch_events_from_cache(git_repo_path, repo_ref, &proposal.id) .await @@ -144,13 +144,13 @@ pub async fn get_open_proposals( if let Ok(most_recent_proposal_patch_chain) = get_most_recent_patch_with_ancestors(commits_events.clone()) { - open_proposals + open_or_draft_proposals .insert(proposal.id, (proposal, most_recent_proposal_patch_chain)); } } } } - Ok(open_proposals) + Ok(open_or_draft_proposals) } pub async fn get_all_proposals( -- cgit v1.2.3