This commit is contained in:
2026-09-04 08:16:05 +07:00
parent 212f35d6bb
commit 17de4f6376
43 changed files with 376 additions and 721 deletions
+7 -22
View File
@@ -28,7 +28,6 @@ pub struct Announcement {
pub euc: Option<String>,
/// Other recognized maintainers.
pub maintainers: Vec<PublicKey>,
/// Value of a `u` tag, if any.
/// Marks the repository as a subordinate fork of the upstream, per NIP-34.
pub upstream: Option<Upstream>,
/// Hashtags labelling the repository, the `t` tags.
@@ -36,9 +35,6 @@ pub struct Announcement {
}
/// The `u` tag of a fork announcement, per NIP-34.
/// The first value is the upstream coordinate or a git URL.
/// The coordinate form is `30617:<pubkey>:<id>`.
/// The second value is an optional relay hint for the upstream.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Upstream {
/// Raw first value of the `u` tag, a coordinate or git URL.
@@ -52,10 +48,6 @@ pub struct Upstream {
impl Upstream {
/// Parse the `u` tag values.
/// The first value is the upstream coordinate or a git URL.
/// The coordinate form may append `|git-url`.
/// The coordinate is the part before the first `|`.
/// The second value is an optional relay hint.
fn parse(raw: &str, relay_hint: Option<&str>) -> Self {
let coordinate = raw.split('|').next().unwrap_or(raw);
let addr = coordinate
@@ -70,7 +62,6 @@ impl Upstream {
}
/// Text for display.
/// The upstream coordinate for a NIP-34 repository, else the raw `u` value.
pub fn display(&self) -> SharedString {
match &self.addr {
Some(addr) => SharedString::from(addr.to_string()),
@@ -104,12 +95,7 @@ pub fn activity_subject(event: &Event) -> SharedString {
}
/// The patch set of a pull request.
/// The PR references the root patch event, kind `1617`, via its `e` tag.
/// Every patch of the set is chained to the previous one with NIP-10 `e` reply tags.
/// They are returned in series order, oldest first.
/// A PR without an `e` tag falls back to the patch producing its tip commit.
/// The tip commit is the PR's `commit` or `r` tag, per NIP-34.
/// The reply chain is then walked backward to the root.
///
/// Returns an empty list when no patch event can be linked to the PR.
pub fn pull_request_patches<'a>(
pr: &Event,
@@ -160,8 +146,6 @@ pub fn pull_request_patches<'a>(
}
/// The patch content of a pull request.
/// The contents of its patch set, see [`pull_request_patches`], joined in series order.
/// Older PRs that carried the patch inline fall back to their own content.
pub fn pull_request_patch<'a>(pr: &Event, patches: impl IntoIterator<Item = &'a Event>) -> String {
let patches: Vec<&'a Event> = patches.into_iter().collect();
let series = pull_request_patches(pr, patches.iter().copied());
@@ -209,6 +193,7 @@ fn current_commit_of(event: &Event) -> Option<String> {
}
/// Whether `patch` produces `commit`, found via its `commit` or `r` tag.
///
/// It lets clients find existing patches for a specific commit.
fn patch_produces_commit(patch: &Event, commit: &str) -> bool {
patch
@@ -222,6 +207,7 @@ fn patch_produces_commit(patch: &Event, commit: &str) -> bool {
impl Announcement {
/// Parse a kind `30617` event.
///
/// Returns `None` when the kind is wrong or the `d` tag is missing.
pub fn from_event(event: &Event) -> Option<Self> {
if event.kind != Kind::GitRepoAnnouncement {
@@ -289,8 +275,8 @@ impl Announcement {
/// Whether this announcement is a fork of the repository at `base`.
/// Its `u` tag points at `base`, which also covers permanent forks whose EUC diverged.
///
/// Or it shares `base`'s earliest unique commit and is not the base itself.
/// Read-only discovery input, nothing here is published back to nostr.
pub fn is_fork_of(&self, base: &RepoAddr, base_euc: Option<&str>) -> bool {
if self.addr() == *base {
return false;
@@ -308,9 +294,9 @@ impl Announcement {
.unwrap_or(SharedString::from("No description"))
}
/// The effective maintainers of this repository.
/// The announced `maintainers` plus the announcement author.
/// The author asserts themselves as a maintainer of the primary project.
/// The effective maintainers of this repository,
/// the announced `maintainers` plus the announcement author.
///
/// A `u` tag that marks the repository as a subordinate fork excludes them, per NIP-34.
pub fn effective_maintainers(&self) -> Vec<PublicKey> {
let mut maintainers = self.maintainers.clone();
@@ -321,7 +307,6 @@ impl Announcement {
}
/// The `git clone` URLs for this repository, deduplicated.
/// The announced order is preserved, making output deterministic across calls.
pub fn clone_urls(&self) -> Vec<SharedString> {
let mut seen = HashSet::new();
self.clone