use std::collections::BTreeMap;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Changelog {
#[serde(default)]
pub format: crate::Format,
pub metadata: Metadata,
pub releases: Vec<Release>,
pub links: Vec<LinkDefinition>,
pub source: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Metadata {
pub title: Option<String>,
pub description: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Release {
pub version: Option<String>,
pub date: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub date_span: Option<Span>,
pub yanked: bool,
pub heading: String,
pub link: Option<String>,
pub sections: Vec<Section>,
pub span: Span,
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub attributes: BTreeMap<String, String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Section {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub component: Option<String>,
pub category: Option<Category>,
pub heading: Option<String>,
pub entries: Vec<Entry>,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "kind", content = "name", rename_all = "snake_case")]
#[non_exhaustive]
pub enum Category {
Added,
Changed,
Deprecated,
Removed,
Fixed,
Security,
Custom(String),
}
impl Category {
#[must_use]
pub fn as_str(&self) -> &str {
match self {
Self::Added => "Added",
Self::Changed => "Changed",
Self::Deprecated => "Deprecated",
Self::Removed => "Removed",
Self::Fixed => "Fixed",
Self::Security => "Security",
Self::Custom(name) => name,
}
}
pub(crate) fn from_name(name: &str) -> Self {
match name.to_ascii_lowercase().as_str() {
"added" => Self::Added,
"changed" => Self::Changed,
"deprecated" => Self::Deprecated,
"removed" => Self::Removed,
"fixed" => Self::Fixed,
"security" => Self::Security,
_ => Self::Custom(name.to_owned()),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Entry {
pub markdown: String,
pub kind: EntryKind,
pub span: Span,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum EntryKind {
ListItem,
Markdown,
Text,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct LinkDefinition {
pub label: String,
pub destination: String,
pub title: Option<String>,
pub span: Span,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub struct Span {
pub start: usize,
pub end: usize,
pub line: usize,
}