upleb.uk

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

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/sub_commands/init.rs27
-rw-r--r--tests/init.rs80
2 files changed, 101 insertions, 6 deletions
diff --git a/src/sub_commands/init.rs b/src/sub_commands/init.rs
index db90acd..44e288f 100644
--- a/src/sub_commands/init.rs
+++ b/src/sub_commands/init.rs
@@ -1,7 +1,8 @@
1use std::collections::HashMap; 1use std::collections::HashMap;
2 2
3use anyhow::{Context, Result}; 3use anyhow::{Context, Result};
4use nostr::{FromBech32, PublicKey, ToBech32}; 4use nostr::{nips::nip01::Coordinate, FromBech32, PublicKey, ToBech32};
5use nostr_sdk::Kind;
5 6
6use super::send::send_events; 7use super::send::send_events;
7#[cfg(not(test))] 8#[cfg(not(test))]
@@ -13,7 +14,10 @@ use crate::{
13 client::Connect, 14 client::Connect,
14 git::{Repo, RepoActions}, 15 git::{Repo, RepoActions},
15 login, 16 login,
16 repo_ref::{self, extract_pks, get_repo_config_from_yaml, save_repo_config_to_yaml, RepoRef}, 17 repo_ref::{
18 self, extract_pks, get_repo_config_from_yaml, save_repo_config_to_yaml, RepoRef,
19 REPO_REF_KIND,
20 },
17 Cli, 21 Cli,
18}; 22};
19 23
@@ -292,7 +296,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> {
292 296
293 println!("publishing repostory reference..."); 297 println!("publishing repostory reference...");
294 298
295 let repo_event = RepoRef { 299 let repo_ref = RepoRef {
296 identifier: identifier.clone(), 300 identifier: identifier.clone(),
297 name, 301 name,
298 description, 302 description,
@@ -302,9 +306,8 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> {
302 relays: relays.clone(), 306 relays: relays.clone(),
303 maintainers: maintainers.clone(), 307 maintainers: maintainers.clone(),
304 events: HashMap::new(), 308 events: HashMap::new(),
305 } 309 };
306 .to_event(&signer) 310 let repo_event = repo_ref.to_event(&signer).await?;
307 .await?;
308 311
309 client.set_signer(signer).await; 312 client.set_signer(signer).await;
310 313
@@ -317,6 +320,18 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> {
317 ) 320 )
318 .await?; 321 .await?;
319 322
323 git_repo.save_git_config_item(
324 "nostr.repo",
325 &Coordinate {
326 kind: Kind::Custom(REPO_REF_KIND),
327 public_key: user_ref.public_key,
328 identifier: identifier.clone(),
329 relays: vec![],
330 }
331 .to_bech32()?,
332 false,
333 )?;
334
320 // if yaml file doesnt exist or needs updating 335 // if yaml file doesnt exist or needs updating
321 if match &repo_config_result { 336 if match &repo_config_result {
322 Ok(config) => { 337 Ok(config) => {
diff --git a/tests/init.rs b/tests/init.rs
index d7ba164..5209898 100644
--- a/tests/init.rs
+++ b/tests/init.rs
@@ -276,6 +276,86 @@ mod when_repo_not_previously_claimed {
276 } 276 }
277 } 277 }
278 278
279 mod git_config_updated {
280
281 use nostr::nips::nip01::Coordinate;
282 use nostr_sdk::ToBech32;
283
284 use super::*;
285
286 async fn async_run_test() -> Result<()> {
287 let git_repo = prep_git_repo()?;
288 // fallback (51,52) user write (53, 55) repo (55, 56) blaster (57)
289 let (mut r51, mut r52, mut r53, mut r55, mut r56, mut r57) = (
290 Relay::new(
291 8051,
292 None,
293 Some(&|relay, client_id, subscription_id, _| -> Result<()> {
294 relay.respond_events(
295 client_id,
296 &subscription_id,
297 &vec![
298 generate_test_key_1_metadata_event("fred"),
299 generate_test_key_1_relay_list_event(),
300 ],
301 )?;
302 Ok(())
303 }),
304 ),
305 Relay::new(8052, None, None),
306 Relay::new(8053, None, None),
307 Relay::new(8055, None, None),
308 Relay::new(8056, None, None),
309 Relay::new(8057, None, None),
310 );
311
312 // // check relay had the right number of events
313 let cli_tester_handle = std::thread::spawn(move || -> Result<()> {
314 let mut p = cli_tester_init(&git_repo);
315 p.expect_end_eventually()?;
316 for p in [51, 52, 53, 55, 56, 57] {
317 relay::shutdown_relay(8000 + p)?;
318 }
319 assert_eq!(
320 git_repo
321 .git_repo
322 .config()?
323 .get_entry("nostr.repo")?
324 .value()
325 .unwrap(),
326 Coordinate {
327 kind: nostr_sdk::Kind::Custom(REPOSITORY_KIND),
328 identifier: "example-identifier".to_string(),
329 public_key: TEST_KEY_1_KEYS.public_key(),
330 relays: vec![],
331 }
332 .to_bech32()?,
333 );
334
335 Ok(())
336 });
337
338 // launch relay
339 let _ = join!(
340 r51.listen_until_close(),
341 r52.listen_until_close(),
342 r53.listen_until_close(),
343 r55.listen_until_close(),
344 r56.listen_until_close(),
345 r57.listen_until_close(),
346 );
347 cli_tester_handle.join().unwrap()?;
348 Ok(())
349 }
350
351 #[tokio::test]
352 #[serial]
353 async fn with_nostr_repo_set_to_user_and_identifer_naddr() -> Result<()> {
354 async_run_test().await?;
355 Ok(())
356 }
357 }
358
279 mod tags_as_specified_in_args { 359 mod tags_as_specified_in_args {
280 use super::*; 360 use super::*;
281 361