upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-07-25 15:52:19 +0100
committerDanConwayDev <DanConwayDev@protonmail.com>2025-07-25 16:11:01 +0100
commit0cad465dd3f78bd6c680067d12d396d4782829bf (patch)
tree521dbec8d259f7c982345b40bb128a21795a2012 /src
parent27cdea120e195b68d998764519ff3a472641c79b (diff)
fix(list): improve pr unsupport text
and show a more helpful message when proposal can be checked out using the remote
Diffstat (limited to 'src')
-rw-r--r--src/bin/ngit/sub_commands/list.rs35
-rw-r--r--src/lib/git/mod.rs20
2 files changed, 48 insertions, 7 deletions
diff --git a/src/bin/ngit/sub_commands/list.rs b/src/bin/ngit/sub_commands/list.rs
index c3c8c71..0083c91 100644
--- a/src/bin/ngit/sub_commands/list.rs
+++ b/src/bin/ngit/sub_commands/list.rs
@@ -206,13 +206,32 @@ pub async fn launch() -> Result<()> {
206 { 206 {
207 match Interactor::default().choice( 207 match Interactor::default().choice(
208 PromptChoiceParms::default() 208 PromptChoiceParms::default()
209 .with_prompt("this is new PR event kind which ngit doesnt yet support") 209 .with_prompt(
210 "this is new PR event kind which isn't supported in `ngit list` yet",
211 )
210 .with_default(0) 212 .with_default(0)
211 .with_choices(vec![ 213 .with_choices(
212 // TODO enable checkout by fetching oids, creating / updating branch and 214 if [Kind::GitStatusOpen, Kind::GitStatusDraft].contains(&selected_status)
213 // checking out 215 && git_repo
214 "back to proposals".to_string(), 216 .get_first_nostr_remote_when_in_ngit_binary()
215 ]), 217 .await
218 .is_ok_and(|r| r.is_some())
219 {
220 vec![
221 format!(
222 "I'll manually checkout the proposal at remote branch '{}'",
223 cover_letter
224 .get_branch_name_with_pr_prefix_and_shorthand_id()
225 .unwrap()
226 ),
227 // TODO fetch oids and follow similar logic for dealing with
228 // conflcts as with patches below
229 "back to proposals".to_string(),
230 ]
231 } else {
232 vec!["back to proposals".to_string()]
233 },
234 ),
216 )? { 235 )? {
217 0 => continue, 236 0 => continue,
218 _ => { 237 _ => {
@@ -251,7 +270,9 @@ pub async fn launch() -> Result<()> {
251 ]), 270 ]),
252 )? { 271 )? {
253 0 => { 272 0 => {
254 println!("Some proposals are posted as patch without listing a parent commit\n"); 273 println!(
274 "Some proposals are posted as patch without listing a parent commit\n"
275 );
255 println!( 276 println!(
256 "they are not anchored against a particular state of the code base like a standard patch or a pull request can be\n" 277 "they are not anchored against a particular state of the code base like a standard patch or a pull request can be\n"
257 ); 278 );
diff --git a/src/lib/git/mod.rs b/src/lib/git/mod.rs
index d4bf2f5..b275b49 100644
--- a/src/lib/git/mod.rs
+++ b/src/lib/git/mod.rs
@@ -10,6 +10,7 @@ use nostr_sdk::{
10 Tags, 10 Tags,
11 hashes::{Hash, sha1::Hash as Sha1Hash}, 11 hashes::{Hash, sha1::Hash as Sha1Hash},
12}; 12};
13use nostr_url::NostrUrlDecoded;
13 14
14use crate::git_events::{get_commit_id_from_patch, tag_value}; 15use crate::git_events::{get_commit_id_from_patch, tag_value};
15pub mod identify_ahead_behind; 16pub mod identify_ahead_behind;
@@ -92,6 +93,10 @@ pub trait RepoActions {
92 fn get_git_config_item(&self, item: &str, global: Option<bool>) -> Result<Option<String>>; 93 fn get_git_config_item(&self, item: &str, global: Option<bool>) -> Result<Option<String>>;
93 fn save_git_config_item(&self, item: &str, value: &str, global: bool) -> Result<()>; 94 fn save_git_config_item(&self, item: &str, value: &str, global: bool) -> Result<()>;
94 fn remove_git_config_item(&self, item: &str, global: bool) -> Result<bool>; 95 fn remove_git_config_item(&self, item: &str, global: bool) -> Result<bool>;
96 #[allow(async_fn_in_trait)]
97 async fn get_first_nostr_remote_when_in_ngit_binary(
98 &self,
99 ) -> Result<Option<(String, NostrUrlDecoded)>>;
95} 100}
96 101
97impl RepoActions for Repo { 102impl RepoActions for Repo {
@@ -796,6 +801,21 @@ impl RepoActions for Repo {
796 Ok(true) 801 Ok(true)
797 } 802 }
798 } 803 }
804
805 async fn get_first_nostr_remote_when_in_ngit_binary(
806 &self,
807 ) -> Result<Option<(String, NostrUrlDecoded)>> {
808 for remote_name in self.git_repo.remotes()?.iter().flatten() {
809 if let Some(remote_url) = self.git_repo.find_remote(remote_name)?.url() {
810 if let Ok(nostr_url_decoded) =
811 NostrUrlDecoded::parse_and_resolve(remote_url, &Some(self)).await
812 {
813 return Ok(Some((remote_name.to_string(), nostr_url_decoded)));
814 }
815 }
816 }
817 Ok(None)
818 }
799} 819}
800 820
801fn oid_to_u8_20_bytes(oid: &Oid) -> [u8; 20] { 821fn oid_to_u8_20_bytes(oid: &Oid) -> [u8; 20] {