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/claim.rs52
-rw-r--r--src/sub_commands/prs/create.rs2
-rw-r--r--src/sub_commands/prs/list.rs1
-rw-r--r--src/sub_commands/pull.rs1
-rw-r--r--src/sub_commands/push.rs1
5 files changed, 50 insertions, 7 deletions
diff --git a/src/sub_commands/claim.rs b/src/sub_commands/claim.rs
index c0d26dd..2573267 100644
--- a/src/sub_commands/claim.rs
+++ b/src/sub_commands/claim.rs
@@ -10,7 +10,7 @@ use crate::{
10 client::Connect, 10 client::Connect,
11 git::{Repo, RepoActions}, 11 git::{Repo, RepoActions},
12 login, 12 login,
13 repo_ref::RepoRef, 13 repo_ref::{extract_pks, get_repo_config_from_yaml, save_repo_config_to_yaml, RepoRef},
14 Cli, 14 Cli,
15}; 15};
16 16
@@ -22,6 +22,9 @@ pub struct SubCommandArgs {
22 #[clap(short, long)] 22 #[clap(short, long)]
23 /// optional description 23 /// optional description
24 description: Option<String>, 24 description: Option<String>,
25 #[clap(short, long, value_parser, num_args = 1..)]
26 /// relays contributors push patches and comments to
27 relays: Vec<String>,
25} 28}
26 29
27pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { 30pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> {
@@ -37,6 +40,8 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> {
37 40
38 // TODO: check for empty repo 41 // TODO: check for empty repo
39 // TODO: check for existing maintaiers file 42 // TODO: check for existing maintaiers file
43
44 let repo_config_result = get_repo_config_from_yaml(&git_repo);
40 // TODO: check for other claims 45 // TODO: check for other claims
41 46
42 let name = match &args.title { 47 let name = match &args.title {
@@ -50,6 +55,8 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> {
50 .input(PromptInputParms::default().with_prompt("description (Optional)"))?, 55 .input(PromptInputParms::default().with_prompt("description (Optional)"))?,
51 }; 56 };
52 57
58 let git_server = git_repo.get_origin_url()?;
59
53 #[cfg(not(test))] 60 #[cfg(not(test))]
54 let mut client = Client::default(); 61 let mut client = Client::default();
55 #[cfg(test)] 62 #[cfg(test)]
@@ -59,11 +66,41 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> {
59 66
60 client.set_keys(&keys).await; 67 client.set_keys(&keys).await;
61 68
62 // TODO: choice input defaulting to user relay list filtered by non paid relays 69 let mut maintainers = vec![keys.public_key()];
63 let repo_relays: Vec<String> = vec![ 70
64 "ws://localhost:8055".to_string(), 71 let repo_relays: Vec<String> = if !args.relays.is_empty() {
65 "ws://localhost:8056".to_string(), 72 args.relays.clone()
66 ]; 73 } else if let Ok(config) = &repo_config_result {
74 config.relays.clone()
75 } else {
76 // TODO: choice input defaulting to user relay list filtered by non paid relays
77 // TODO: allow manual input for more relays
78 // TODO: reccommend some free relays
79 user_ref.relays.write()
80 };
81
82 if let Ok(config) = &repo_config_result {
83 maintainers = extract_pks(config.maintainers.clone())?;
84 }
85
86 // if yaml file doesnt exist or needs updating
87 if match &repo_config_result {
88 Ok(config) => {
89 !(extract_pks(config.maintainers.clone())?.eq(&maintainers)
90 && config.relays.eq(&repo_relays))
91 }
92 Err(_) => true,
93 } {
94 save_repo_config_to_yaml(&git_repo, maintainers.clone(), repo_relays.clone())?;
95 println!(
96 "maintainers.yaml {}. commit and push.",
97 if repo_config_result.is_err() {
98 "created"
99 } else {
100 "updated"
101 }
102 );
103 }
67 104
68 println!("publishing repostory reference..."); 105 println!("publishing repostory reference...");
69 106
@@ -71,10 +108,13 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> {
71 name, 108 name,
72 description, 109 description,
73 root_commit: root_commit.to_string(), 110 root_commit: root_commit.to_string(),
111 git_server,
74 relays: repo_relays.clone(), 112 relays: repo_relays.clone(),
113 maintainers,
75 } 114 }
76 .to_event(&keys)?; 115 .to_event(&keys)?;
77 116
117 // TODO: send repo event to blaster
78 send_events( 118 send_events(
79 &client, 119 &client,
80 vec![repo_event], 120 vec![repo_event],
diff --git a/src/sub_commands/prs/create.rs b/src/sub_commands/prs/create.rs
index 5c4e578..5e41a56 100644
--- a/src/sub_commands/prs/create.rs
+++ b/src/sub_commands/prs/create.rs
@@ -100,12 +100,12 @@ pub async fn launch(
100 generate_pr_and_patch_events(&title, &description, &to_branch, &git_repo, &ahead, &keys)?; 100 generate_pr_and_patch_events(&title, &description, &to_branch, &git_repo, &ahead, &keys)?;
101 101
102 let repo_ref = repo_ref::fetch( 102 let repo_ref = repo_ref::fetch(
103 &git_repo,
103 git_repo 104 git_repo
104 .get_root_commit(&to_branch) 105 .get_root_commit(&to_branch)
105 .context("failed to get root commit of the repository")? 106 .context("failed to get root commit of the repository")?
106 .to_string(), 107 .to_string(),
107 &client, 108 &client,
108 // TODO: get relay list from local yaml file
109 user_ref.relays.write(), 109 user_ref.relays.write(),
110 ) 110 )
111 .await?; 111 .await?;
diff --git a/src/sub_commands/prs/list.rs b/src/sub_commands/prs/list.rs
index 13f29fd..a6aa8b7 100644
--- a/src/sub_commands/prs/list.rs
+++ b/src/sub_commands/prs/list.rs
@@ -45,6 +45,7 @@ pub async fn launch(
45 let client = <MockConnect as std::default::Default>::default(); 45 let client = <MockConnect as std::default::Default>::default();
46 46
47 let repo_ref = repo_ref::fetch( 47 let repo_ref = repo_ref::fetch(
48 &git_repo,
48 root_commit.to_string(), 49 root_commit.to_string(),
49 &client, 50 &client,
50 client.get_more_fallback_relays().clone(), 51 client.get_more_fallback_relays().clone(),
diff --git a/src/sub_commands/pull.rs b/src/sub_commands/pull.rs
index a6513e8..a656e09 100644
--- a/src/sub_commands/pull.rs
+++ b/src/sub_commands/pull.rs
@@ -38,6 +38,7 @@ pub async fn launch() -> Result<()> {
38 let client = <MockConnect as std::default::Default>::default(); 38 let client = <MockConnect as std::default::Default>::default();
39 39
40 let repo_ref = repo_ref::fetch( 40 let repo_ref = repo_ref::fetch(
41 &git_repo,
41 root_commit.to_string(), 42 root_commit.to_string(),
42 &client, 43 &client,
43 client.get_more_fallback_relays().clone(), 44 client.get_more_fallback_relays().clone(),
diff --git a/src/sub_commands/push.rs b/src/sub_commands/push.rs
index 968aa0a..7c64bb2 100644
--- a/src/sub_commands/push.rs
+++ b/src/sub_commands/push.rs
@@ -41,6 +41,7 @@ pub async fn launch(cli_args: &Cli) -> Result<()> {
41 let mut client = <MockConnect as std::default::Default>::default(); 41 let mut client = <MockConnect as std::default::Default>::default();
42 42
43 let repo_ref = repo_ref::fetch( 43 let repo_ref = repo_ref::fetch(
44 &git_repo,
44 root_commit.to_string(), 45 root_commit.to_string(),
45 &client, 46 &client,
46 client.get_more_fallback_relays().clone(), 47 client.get_more_fallback_relays().clone(),