upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/sub_commands
diff options
context:
space:
mode:
Diffstat (limited to 'src/sub_commands')
-rw-r--r--src/sub_commands/fetch.rs46
-rw-r--r--src/sub_commands/init.rs12
-rw-r--r--src/sub_commands/list.rs2
-rw-r--r--src/sub_commands/mod.rs1
4 files changed, 58 insertions, 3 deletions
diff --git a/src/sub_commands/fetch.rs b/src/sub_commands/fetch.rs
new file mode 100644
index 0000000..07fd6f9
--- /dev/null
+++ b/src/sub_commands/fetch.rs
@@ -0,0 +1,46 @@
1use std::collections::HashSet;
2
3use anyhow::{Context, Result};
4use clap;
5use nostr::nips::nip01::Coordinate;
6
7#[cfg(not(test))]
8use crate::client::Client;
9#[cfg(test)]
10use crate::client::MockConnect;
11use crate::{
12 client::Connect,
13 git::{Repo, RepoActions},
14 repo_ref::get_repo_coordinates,
15 Cli,
16};
17
18#[derive(clap::Args)]
19pub struct SubCommandArgs {
20 /// address pointer to repo announcement
21 #[arg(long, action)]
22 repo: Vec<String>,
23}
24
25pub async fn launch(args: &Cli, command_args: &SubCommandArgs) -> Result<()> {
26 let _ = args;
27 let git_repo = Repo::discover().context("cannot find a git repository")?;
28 #[cfg(not(test))]
29 let client = Client::default();
30 #[cfg(test)]
31 let client = <MockConnect as std::default::Default>::default();
32 let repo_coordinates = if command_args.repo.is_empty() {
33 get_repo_coordinates(&git_repo, &client).await?
34 } else {
35 let mut repo_coordinates = HashSet::new();
36 for repo in &command_args.repo {
37 repo_coordinates.insert(Coordinate::parse(repo.clone())?);
38 }
39 repo_coordinates
40 };
41 client
42 .fetch_all(git_repo.get_path()?, &repo_coordinates)
43 .await?;
44 client.disconnect().await?;
45 Ok(())
46}
diff --git a/src/sub_commands/init.rs b/src/sub_commands/init.rs
index 57785db..db90acd 100644
--- a/src/sub_commands/init.rs
+++ b/src/sub_commands/init.rs
@@ -1,3 +1,5 @@
1use std::collections::HashMap;
2
1use anyhow::{Context, Result}; 3use anyhow::{Context, Result};
2use nostr::{FromBech32, PublicKey, ToBech32}; 4use nostr::{FromBech32, PublicKey, ToBech32};
3 5
@@ -291,7 +293,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> {
291 println!("publishing repostory reference..."); 293 println!("publishing repostory reference...");
292 294
293 let repo_event = RepoRef { 295 let repo_event = RepoRef {
294 identifier, 296 identifier: identifier.clone(),
295 name, 297 name,
296 description, 298 description,
297 root_commit: earliest_unique_commit, 299 root_commit: earliest_unique_commit,
@@ -299,6 +301,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> {
299 web, 301 web,
300 relays: relays.clone(), 302 relays: relays.clone(),
301 maintainers: maintainers.clone(), 303 maintainers: maintainers.clone(),
304 events: HashMap::new(),
302 } 305 }
303 .to_event(&signer) 306 .to_event(&signer)
304 .await?; 307 .await?;
@@ -322,7 +325,12 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> {
322 } 325 }
323 Err(_) => true, 326 Err(_) => true,
324 } { 327 } {
325 save_repo_config_to_yaml(&git_repo, maintainers.clone(), relays.clone())?; 328 save_repo_config_to_yaml(
329 &git_repo,
330 identifier.clone(),
331 maintainers.clone(),
332 relays.clone(),
333 )?;
326 println!( 334 println!(
327 "maintainers.yaml {}. commit and push.", 335 "maintainers.yaml {}. commit and push.",
328 if repo_config_result.is_err() { 336 if repo_config_result.is_err() {
diff --git a/src/sub_commands/list.rs b/src/sub_commands/list.rs
index 5dc868c..d3f583f 100644
--- a/src/sub_commands/list.rs
+++ b/src/sub_commands/list.rs
@@ -820,7 +820,7 @@ pub static STATUS_KIND_APPLIED: u16 = 1631;
820pub static STATUS_KIND_CLOSED: u16 = 1632; 820pub static STATUS_KIND_CLOSED: u16 = 1632;
821pub static STATUS_KIND_DRAFT: u16 = 1633; 821pub static STATUS_KIND_DRAFT: u16 = 1633;
822 822
823fn status_kinds() -> Vec<nostr::Kind> { 823pub fn status_kinds() -> Vec<nostr::Kind> {
824 vec![ 824 vec![
825 nostr::Kind::Custom(STATUS_KIND_OPEN), 825 nostr::Kind::Custom(STATUS_KIND_OPEN),
826 nostr::Kind::Custom(STATUS_KIND_APPLIED), 826 nostr::Kind::Custom(STATUS_KIND_APPLIED),
diff --git a/src/sub_commands/mod.rs b/src/sub_commands/mod.rs
index 9f97b7e..29a60f9 100644
--- a/src/sub_commands/mod.rs
+++ b/src/sub_commands/mod.rs
@@ -1,3 +1,4 @@
1pub mod fetch;
1pub mod init; 2pub mod init;
2pub mod list; 3pub mod list;
3pub mod login; 4pub mod login;