99 lines
2.6 KiB
Rust
99 lines
2.6 KiB
Rust
use anyhow::Result;
|
|
use nostr::prelude::*;
|
|
use signed_core::Announcement;
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
pub enum Nip34Kind {
|
|
Initialized,
|
|
Cloned,
|
|
ToolingOnly,
|
|
}
|
|
|
|
#[derive(serde::Deserialize)]
|
|
pub(crate) struct Nip34Json {
|
|
pub(crate) identifier: Option<String>,
|
|
pub(crate) owner: Option<String>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
|
|
pub struct GraspSignals {
|
|
pub nip34_json: bool,
|
|
pub nip34_excluded: bool,
|
|
pub nostr_repo_config: bool,
|
|
pub nostr_remote: bool,
|
|
pub grasp_remote: bool,
|
|
pub nip34_grasp_remote: bool,
|
|
pub nip34_state_refs: bool,
|
|
pub nostr_cache: bool,
|
|
pub nostr_aux_config: bool,
|
|
pub maintainers_yaml: bool,
|
|
}
|
|
|
|
impl GraspSignals {
|
|
/// Returns whether any Nostr tooling marker was found.
|
|
pub fn any(&self) -> bool {
|
|
*self != Self::default()
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
|
pub struct Nip34Binding {
|
|
pub kind: Nip34Kind,
|
|
pub signals: GraspSignals,
|
|
pub owner: Option<PublicKey>,
|
|
pub identifier: Option<String>,
|
|
pub grasp_urls: Vec<String>,
|
|
}
|
|
|
|
impl Nip34Binding {
|
|
/// Creates a binding from its kind, detected signals, and recovered coordinates.
|
|
pub fn new(
|
|
kind: Nip34Kind,
|
|
signals: GraspSignals,
|
|
owner: Option<PublicKey>,
|
|
identifier: Option<String>,
|
|
grasp_urls: Vec<String>,
|
|
) -> Self {
|
|
Self {
|
|
kind,
|
|
signals,
|
|
owner,
|
|
identifier,
|
|
grasp_urls,
|
|
}
|
|
}
|
|
}
|
|
|
|
/// A repository's `nip34.json`, the local metadata `nak git` keeps.
|
|
#[derive(serde::Serialize)]
|
|
pub struct Nip34Metadata {
|
|
pub identifier: String,
|
|
pub name: String,
|
|
pub description: String,
|
|
/// The owner's public key, encoded as `npub`.
|
|
pub owner: String,
|
|
/// Grasp server hostnames.
|
|
#[serde(rename = "grasp-servers")]
|
|
pub grasp_servers: Vec<String>,
|
|
#[serde(rename = "earliest-unique-commit")]
|
|
pub earliest_unique_commit: String,
|
|
}
|
|
|
|
impl Nip34Metadata {
|
|
/// The metadata of an announced repository.
|
|
pub fn from_announcement(announcement: &Announcement) -> Result<Self> {
|
|
Ok(Self {
|
|
identifier: announcement.id.clone(),
|
|
name: announcement.name.clone().unwrap_or_default(),
|
|
description: announcement.description.clone().unwrap_or_default(),
|
|
owner: announcement.owner.to_bech32()?,
|
|
grasp_servers: announcement
|
|
.relays
|
|
.iter()
|
|
.filter_map(|relay| relay.domain().map(str::to_owned))
|
|
.collect(),
|
|
earliest_unique_commit: announcement.euc.clone().unwrap_or_default(),
|
|
})
|
|
}
|
|
}
|