upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-11-11 12:30:00 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2025-11-13 14:55:50 +0000
commitebab8d2aa487d1814e802c5a51b19d4bb1592e01 (patch)
tree0b0e8e0b179ac365da9182a01f2a7b26929d7dba /src/lib
parent65f3bd360c065aca493eddf7eb5d3d8191a84b56 (diff)
refactor: simplify get_short_git_server_name
so it doesnt use the git_repo
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/list.rs5
-rw-r--r--src/lib/push.rs2
-rw-r--r--src/lib/utils.rs39
3 files changed, 32 insertions, 14 deletions
diff --git a/src/lib/list.rs b/src/lib/list.rs
index b4d6a5e..08b197c 100644
--- a/src/lib/list.rs
+++ b/src/lib/list.rs
@@ -237,7 +237,7 @@ pub fn identify_remote_sync_issues(
237 237
238 for (name, value) in &nostr_state.state { 238 for (name, value) in &nostr_state.state {
239 for (url, (remote_state, _is_grasp_server)) in remote_states { 239 for (url, (remote_state, _is_grasp_server)) in remote_states {
240 let remote_name = get_short_git_server_name(git_repo, url); 240 let remote_name = get_short_git_server_name(url);
241 let issues = remote_issues.entry(remote_name.clone()).or_default(); 241 let issues = remote_issues.entry(remote_name.clone()).or_default();
242 242
243 let is_branch = name.starts_with("refs/heads/"); 243 let is_branch = name.starts_with("refs/heads/");
@@ -416,7 +416,6 @@ pub fn format_ref_issue_simple(
416 416
417/// Generate warning messages for remote sync issues 417/// Generate warning messages for remote sync issues
418pub fn generate_remote_sync_warnings( 418pub fn generate_remote_sync_warnings(
419 git_repo: &Repo,
420 remote_issues: &HashMap<String, RemoteIssues>, 419 remote_issues: &HashMap<String, RemoteIssues>,
421 remote_states: &HashMap<String, (HashMap<String, String>, bool)>, 420 remote_states: &HashMap<String, (HashMap<String, String>, bool)>,
422) -> Vec<String> { 421) -> Vec<String> {
@@ -430,7 +429,7 @@ pub fn generate_remote_sync_warnings(
430 // Find remote state for this remote 429 // Find remote state for this remote
431 let remote_state = remote_states 430 let remote_state = remote_states
432 .iter() 431 .iter()
433 .find(|(url, _)| &get_short_git_server_name(git_repo, url) == remote_name) 432 .find(|(url, _)| &get_short_git_server_name(url) == remote_name)
434 .map(|(_, (state, _))| state); 433 .map(|(_, (state, _))| state);
435 434
436 if let Some(state) = remote_state { 435 if let Some(state) = remote_state {
diff --git a/src/lib/push.rs b/src/lib/push.rs
index bd45553..274a16a 100644
--- a/src/lib/push.rs
+++ b/src/lib/push.rs
@@ -181,7 +181,7 @@ pub fn push_to_remote_url(
181 let existing_lines = reporter.count_all_existing_lines(); 181 let existing_lines = reporter.count_all_existing_lines();
182 reporter.update_reference_errors.push(format!( 182 reporter.update_reference_errors.push(format!(
183 "WARNING: {} failed to push {name} error: {error}", 183 "WARNING: {} failed to push {name} error: {error}",
184 get_short_git_server_name(git_repo, git_server_url), 184 get_short_git_server_name(git_server_url),
185 )); 185 ));
186 reporter.write_all(existing_lines); 186 reporter.write_all(existing_lines);
187 } 187 }
diff --git a/src/lib/utils.rs b/src/lib/utils.rs
index 431a14f..11ea8a6 100644
--- a/src/lib/utils.rs
+++ b/src/lib/utils.rs
@@ -10,7 +10,7 @@ use std::{
10use anyhow::{Context, Result, bail}; 10use anyhow::{Context, Result, bail};
11use git2::Repository; 11use git2::Repository;
12use nostr::nips::nip19::ToBech32; 12use nostr::nips::nip19::ToBech32;
13use nostr_sdk::{Event, EventId, Kind, PublicKey, Url}; 13use nostr_sdk::{Event, EventId, Kind, PublicKey};
14 14
15use crate::{ 15use crate::{
16 client::{ 16 client::{
@@ -26,19 +26,38 @@ use crate::{
26 get_pr_tip_event_or_most_recent_patch_with_ancestors, get_status, 26 get_pr_tip_event_or_most_recent_patch_with_ancestors, get_status,
27 is_event_proposal_root_for_branch, status_kinds, 27 is_event_proposal_root_for_branch, status_kinds,
28 }, 28 },
29 repo_ref::RepoRef, 29 repo_ref::{RepoRef, extract_npub, is_grasp_server_clone_url},
30}; 30};
31 31
32pub fn get_short_git_server_name(git_repo: &Repo, url: &str) -> std::string::String { 32pub fn get_short_git_server_name(url: &str) -> std::string::String {
33 if let Ok(name) = get_remote_name_by_url(&git_repo.git_repo, url) { 33 // Check if this is a grasp server URL
34 return name; 34 if is_grasp_server_clone_url(url) {
35 } 35 // Try to extract and format the grasp server URL
36 if let Ok(url) = Url::parse(url) { 36 if let Ok(npub) = extract_npub(url) {
37 if let Some(domain) = url.domain() { 37 // Parse the URL to get the domain and identifier
38 return domain.to_string(); 38 if let Ok(clone_url) = CloneUrl::from_str(url) {
39 let domain = clone_url.domain();
40 let path = clone_url.short_name();
41
42 // Extract the identifier from the path (after /{npub}/)
43 if let Some(after_npub) = path.split(&format!("/{}/", npub)).nth(1) {
44 // Truncate npub to show first 10 and last 5 characters
45 let truncated_npub = if npub.len() > 20 {
46 format!("{}...{}", &npub[..4], &npub[npub.len() - 5..])
47 } else {
48 npub.to_string()
49 };
50
51 return format!("{}/{}/{}", domain, truncated_npub, after_npub);
52 }
53 }
39 } 54 }
40 } 55 }
41 url.to_string() 56
57 // Fall back to default behavior for non-grasp server URLs
58 CloneUrl::from_str(url)
59 .map(|u| u.short_name())
60 .unwrap_or_else(|_| url.to_string())
42} 61}
43 62
44pub fn get_remote_name_by_url(git_repo: &Repository, url: &str) -> Result<String> { 63pub fn get_remote_name_by_url(git_repo: &Repository, url: &str) -> Result<String> {