diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2026-02-20 20:09:09 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2026-02-20 21:21:48 +0000 |
| commit | 64747526c9f6ab43f9dac461d056bb42992573b4 (patch) | |
| tree | c2506828ae7b188e3e4b569cd73202ec37779278 /src/lib/repo_ref.rs | |
| parent | 365dfb9a1e986b68bc2389e2a3cd3da30b0d4636 (diff) | |
extract grasp/maintainership helpers to lib and auto-accept on push
move apply_grasp_infrastructure, latest_event_repo_ref to lib/repo_ref.rs
and wait_for_grasp_servers + grasp_servers_from_user_or_fallback to a
new lib/accept_maintainership.rs so both binaries can share them.
add accept_maintainership_with_defaults which publishes the co-maintainer's
own Kind:30617 announcement with defaults (user grasp servers, shared
metadata from existing events) then waits for grasp server provisioning
and updates nostr.repo config and origin remote.
replace the push error block with a call to accept_maintainership_with_defaults
so pushing now silently accepts co-maintainership instead of failing.
Diffstat (limited to 'src/lib/repo_ref.rs')
| -rw-r--r-- | src/lib/repo_ref.rs | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/lib/repo_ref.rs b/src/lib/repo_ref.rs index 9573238..c0f9136 100644 --- a/src/lib/repo_ref.rs +++ b/src/lib/repo_ref.rs | |||
| @@ -814,6 +814,71 @@ pub fn format_grasp_server_url_as_clone_url( | |||
| 814 | )) | 814 | )) |
| 815 | } | 815 | } |
| 816 | 816 | ||
| 817 | /// Find the latest announcement event (by `created_at`) across all maintainer | ||
| 818 | /// events and parse it into a `RepoRef` for shared metadata (name, description, | ||
| 819 | /// web, etc.). | ||
| 820 | pub fn latest_event_repo_ref(repo_ref: &RepoRef) -> Option<RepoRef> { | ||
| 821 | repo_ref | ||
| 822 | .events | ||
| 823 | .values() | ||
| 824 | .max_by_key(|e| e.created_at) | ||
| 825 | .and_then(|e| RepoRef::try_from((e.clone(), None)).ok()) | ||
| 826 | } | ||
| 827 | |||
| 828 | /// Derive clone-URLs and relay URLs from selected grasp servers. | ||
| 829 | /// | ||
| 830 | /// For each grasp server, adds or replaces the corresponding clone URL in | ||
| 831 | /// `git_servers` and prepends a relay URL in `relays`. Grasp-derived | ||
| 832 | /// infrastructure always takes priority — the other lists contain *additional* | ||
| 833 | /// infrastructure beyond what grasp servers provide. | ||
| 834 | pub fn apply_grasp_infrastructure( | ||
| 835 | grasp_servers: &[String], | ||
| 836 | git_servers: &mut Vec<String>, | ||
| 837 | relays: &mut Vec<String>, | ||
| 838 | public_key: &PublicKey, | ||
| 839 | identifier: &str, | ||
| 840 | ) -> Result<()> { | ||
| 841 | for (grasp_relay_insert_idx, grasp_server) in grasp_servers.iter().enumerate() { | ||
| 842 | // Always add grasp-derived clone URL | ||
| 843 | let clone_url = format_grasp_server_url_as_clone_url(grasp_server, public_key, identifier)?; | ||
| 844 | |||
| 845 | let grasp_server_clone_root = if clone_url.contains("https://") { | ||
| 846 | format!("https://{grasp_server}") | ||
| 847 | } else { | ||
| 848 | grasp_server.to_string() | ||
| 849 | }; | ||
| 850 | |||
| 851 | let matching_positions: Vec<usize> = git_servers | ||
| 852 | .iter() | ||
| 853 | .enumerate() | ||
| 854 | .filter_map(|(idx, url)| { | ||
| 855 | if url.contains(&grasp_server_clone_root) { | ||
| 856 | Some(idx) | ||
| 857 | } else { | ||
| 858 | None | ||
| 859 | } | ||
| 860 | }) | ||
| 861 | .collect(); | ||
| 862 | |||
| 863 | if matching_positions.is_empty() { | ||
| 864 | git_servers.push(clone_url); | ||
| 865 | } else { | ||
| 866 | git_servers[matching_positions[0]] = clone_url; | ||
| 867 | for &position in matching_positions.iter().skip(1).rev() { | ||
| 868 | git_servers.remove(position); | ||
| 869 | } | ||
| 870 | } | ||
| 871 | |||
| 872 | // Prepend grasp-derived relay in order (for relay hint) so that the | ||
| 873 | // first grasp server in the list ends up at relays[0]. | ||
| 874 | let relay_url = format_grasp_server_url_as_relay_url(grasp_server)?; | ||
| 875 | if !relays.contains(&relay_url) { | ||
| 876 | relays.insert(grasp_relay_insert_idx, relay_url); | ||
| 877 | } | ||
| 878 | } | ||
| 879 | Ok(()) | ||
| 880 | } | ||
| 881 | |||
| 817 | #[cfg(test)] | 882 | #[cfg(test)] |
| 818 | mod tests { | 883 | mod tests { |
| 819 | use test_utils::*; | 884 | use test_utils::*; |