clean up
This commit is contained in:
@@ -5,5 +5,4 @@ edition.workspace = true
|
||||
publish.workspace = true
|
||||
|
||||
[dependencies]
|
||||
gpui.workspace = true
|
||||
nostr.workspace = true
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use std::collections::HashSet;
|
||||
|
||||
use gpui::SharedString;
|
||||
use nostr::prelude::*;
|
||||
|
||||
use crate::RepoAddr;
|
||||
@@ -16,8 +15,8 @@ pub struct Announcement {
|
||||
pub owner: PublicKey,
|
||||
/// When the announcement was published, used for latest-wins resolution.
|
||||
pub created_at: Timestamp,
|
||||
pub name: Option<SharedString>,
|
||||
pub description: Option<SharedString>,
|
||||
pub name: Option<String>,
|
||||
pub description: Option<String>,
|
||||
/// Webpage URLs for browsing.
|
||||
pub web: Vec<Url>,
|
||||
/// URLs for `git clone`.
|
||||
@@ -62,17 +61,17 @@ impl Upstream {
|
||||
}
|
||||
|
||||
/// Text for display.
|
||||
pub fn display(&self) -> SharedString {
|
||||
pub fn display(&self) -> String {
|
||||
match &self.addr {
|
||||
Some(addr) => SharedString::from(addr.to_string()),
|
||||
None => SharedString::from(self.raw.clone()),
|
||||
Some(addr) => addr.to_string(),
|
||||
None => self.raw.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Subject of a NIP-34 issue or pull request event.
|
||||
/// Taken from the `subject` tag, else the first non-empty line of the content.
|
||||
pub fn activity_subject(event: &Event) -> SharedString {
|
||||
pub fn activity_subject(event: &Event) -> String {
|
||||
let subject = event
|
||||
.tags
|
||||
.iter()
|
||||
@@ -82,16 +81,15 @@ pub fn activity_subject(event: &Event) -> SharedString {
|
||||
});
|
||||
|
||||
subject
|
||||
.map(SharedString::from)
|
||||
.or_else(|| {
|
||||
event
|
||||
.content
|
||||
.lines()
|
||||
.map(str::trim)
|
||||
.find(|line| !line.is_empty())
|
||||
.map(SharedString::from)
|
||||
.map(|value| value.to_string())
|
||||
})
|
||||
.unwrap_or(SharedString::from("Untitled"))
|
||||
.unwrap_or("Untitled".to_string())
|
||||
}
|
||||
|
||||
/// The patch set of a pull request.
|
||||
@@ -219,8 +217,8 @@ impl Announcement {
|
||||
let mut hashtags: Vec<String> = Vec::new();
|
||||
hashtags.extend(event.tags.hashtags().map(|t| t.to_string()));
|
||||
|
||||
let mut name: Option<SharedString> = None;
|
||||
let mut description: Option<SharedString> = None;
|
||||
let mut name: Option<String> = None;
|
||||
let mut description: Option<String> = None;
|
||||
let mut web: Vec<Url> = Vec::new();
|
||||
let mut clone: Vec<Url> = Vec::new();
|
||||
let mut relays: Vec<RelayUrl> = Vec::new();
|
||||
@@ -230,8 +228,8 @@ impl Announcement {
|
||||
|
||||
for tag in event.tags.iter() {
|
||||
match Nip34Tag::parse(tag.as_slice()) {
|
||||
Ok(Nip34Tag::Name(value)) => name = Some(value.into()),
|
||||
Ok(Nip34Tag::Description(value)) => description = Some(value.into()),
|
||||
Ok(Nip34Tag::Name(value)) => name = Some(value),
|
||||
Ok(Nip34Tag::Description(value)) => description = Some(value),
|
||||
Ok(Nip34Tag::Web(urls)) => web.extend(urls),
|
||||
Ok(Nip34Tag::Clone(urls)) => clone.extend(urls),
|
||||
Ok(Nip34Tag::Relays(urls)) => relays.extend(urls),
|
||||
@@ -288,10 +286,10 @@ impl Announcement {
|
||||
}
|
||||
|
||||
/// The description of the repository, or a default if none is provided.
|
||||
pub fn description(&self) -> SharedString {
|
||||
pub fn description(&self) -> String {
|
||||
self.description
|
||||
.clone()
|
||||
.unwrap_or(SharedString::from("No description"))
|
||||
.unwrap_or("No description".to_string())
|
||||
}
|
||||
|
||||
/// The effective maintainers of this repository,
|
||||
@@ -307,11 +305,11 @@ impl Announcement {
|
||||
}
|
||||
|
||||
/// The `git clone` URLs for this repository, deduplicated.
|
||||
pub fn clone_urls(&self) -> Vec<SharedString> {
|
||||
pub fn clone_urls(&self) -> Vec<String> {
|
||||
let mut seen = HashSet::new();
|
||||
self.clone
|
||||
.iter()
|
||||
.map(|url| SharedString::from(format!("git clone {url}")))
|
||||
.map(|url| format!("git clone {url}"))
|
||||
.filter(|command| seen.insert(command.clone()))
|
||||
.collect()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user