feat: write nip34.json when publishing a repository
This commit is contained in:
@@ -2,8 +2,10 @@ use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
|
||||
use nostr::prelude::*;
|
||||
use signed_core::RepoAddr;
|
||||
use signed_git::{DiffStatus, GitCache, LocalRepo, Nip34Binding, Nip34Kind, PatchParser, Repo};
|
||||
use signed_core::{Announcement, RepoAddr};
|
||||
use signed_git::{
|
||||
DiffStatus, GitCache, LocalRepo, Nip34Binding, Nip34Kind, Nip34Metadata, PatchParser, Repo,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn blocks_parent_components() {
|
||||
@@ -1234,6 +1236,58 @@ fn the_written_nostr_repo_marker_is_detected() {
|
||||
assert_eq!(binding.identifier.as_deref(), Some("my-repo"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn written_nip34_json_matches_nak_and_stays_out_of_git() {
|
||||
let (_dir, path) = init_repo();
|
||||
let owner = key();
|
||||
let announcement = Announcement {
|
||||
event_id: EventId::from_hex(
|
||||
"0000000000000000000000000000000000000000000000000000000000000000",
|
||||
)
|
||||
.expect("event id"),
|
||||
id: "my-repo".to_owned(),
|
||||
owner,
|
||||
created_at: Timestamp::now(),
|
||||
name: Some("My Repo".to_owned()),
|
||||
description: None,
|
||||
web: Vec::new(),
|
||||
clone: Vec::new(),
|
||||
relays: vec![RelayUrl::parse("wss://relay.ngit.dev/").expect("relay")],
|
||||
euc: Some("0123456789abcdef0123456789abcdef01234567".to_owned()),
|
||||
maintainers: Vec::new(),
|
||||
upstream: None,
|
||||
hashtags: Vec::new(),
|
||||
};
|
||||
let metadata = Nip34Metadata::from_announcement(&announcement).expect("metadata");
|
||||
|
||||
Repo::open(&path)
|
||||
.expect("open")
|
||||
.write_nip34_json(&metadata)
|
||||
.expect("write");
|
||||
|
||||
let json: serde_json::Value =
|
||||
serde_json::from_str(&std::fs::read_to_string(path.join("nip34.json")).expect("read"))
|
||||
.expect("json");
|
||||
|
||||
assert_eq!(
|
||||
json,
|
||||
serde_json::json!({
|
||||
"identifier": "my-repo",
|
||||
"name": "My Repo",
|
||||
"description": "",
|
||||
"owner": owner.to_bech32().expect("npub"),
|
||||
"grasp-servers": ["relay.ngit.dev"],
|
||||
"earliest-unique-commit": "0123456789abcdef0123456789abcdef01234567",
|
||||
})
|
||||
);
|
||||
|
||||
let exclude = std::fs::read_to_string(path.join(".git/info/exclude")).expect("exclude");
|
||||
assert!(exclude.lines().any(|line| line == "nip34.json"));
|
||||
|
||||
let status = git_in(&path, &["status", "--porcelain"]).expect("status");
|
||||
assert!(status.is_empty(), "{status}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nostr_remote_is_a_nip34_clone() {
|
||||
let (_dir, path) = init_repo();
|
||||
|
||||
Reference in New Issue
Block a user