use crate::templating::DocumentVariant;
use crate::ticket_abstraction::AbstractTicket;
impl AbstractTicket {
#[must_use]
pub fn release_note(&self, variant: DocumentVariant, with_priv_footnote: bool) -> String {
let anchor = self.anchor_declaration();
let debug_info = format!(
"| {} | {} | link:{}[]",
&self.docs_contact, self.doc_text_status, &self.url
);
let empty = format!(
"{}\n🚧 {}::\n+\n--\n**No release note.**\n--\n+\n{} {}\n",
anchor,
self.summary,
self.all_signatures(with_priv_footnote),
&debug_info
);
if content_lines(&self.doc_text).is_empty() {
empty
} else {
let doc_text_unix = self.doc_text.replace('\r', "");
let lines: Vec<&str> = doc_text_unix.lines().collect();
let processed_text = if let Some((idx, first_line)) = lines.iter().enumerate().find(|(_, l)| !l.trim().is_empty() && !l.starts_with("//")) {
let trimmed = first_line.trim();
if trimmed.ends_with("::") {
doc_text_unix
} else if trimmed.starts_with('.') {
let title = &trimmed[1..];
let body = lines[idx+1..].join("\n");
format!("{}::\n+\n--\n{}\n--", title, body.trim())
} else {
format!("<missing_title>::\n+\n--\n{}\n--", doc_text_unix.trim())
}
} else {
doc_text_unix };
format!(
"{}\n{}\n\n+\n{} {}\n",
anchor,
processed_text,
self.all_signatures(with_priv_footnote),
if variant == DocumentVariant::Internal {
&debug_info
} else {
""
},
)
}
}
#[must_use]
pub fn signature(&self, with_priv_footnote: bool) -> String {
let id = &self.id;
if self.public {
format!("link:{}[{}]", &self.url, id)
} else {
if with_priv_footnote {
format!("{id}footnoteref:[PrivateTicketFootnote]")
} else {
id.to_string()
}
}
}
#[must_use]
fn all_signatures(&self, with_priv_footnote: bool) -> String {
let mut signatures = vec![self.signature(with_priv_footnote)];
if let Some(references) = self.references.as_ref() {
signatures.append(&mut references.clone());
}
signatures.join(", ")
}
#[must_use]
pub fn anchor(&self) -> String {
let service = self.id.tracker.short_name();
let key = &self.id.key;
format!("{service}-{key}")
}
fn anchor_declaration(&self) -> String {
let anchor = self.anchor();
format!("[id=\"{anchor}\"]")
}
#[must_use]
pub fn xref(&self) -> String {
let anchor = self.anchor();
let id = self.id.to_string();
format!("xref:{anchor}[{id}]")
}
}
pub fn content_lines(doc_text: &str) -> Vec<&str> {
doc_text
.lines()
.filter(|line| !line.trim().is_empty() && !line.starts_with("//"))
.collect()
}