1use crate::log_debug;
2use schemars::JsonSchema;
3use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5
6#[derive(Serialize, Deserialize, JsonSchema, Debug)]
8pub struct ChangelogResponse {
9 pub version: Option<String>,
11 pub release_date: Option<String>,
13 pub sections: HashMap<ChangelogType, Vec<ChangeEntry>>,
15 pub breaking_changes: Vec<BreakingChange>,
17 pub metrics: ChangeMetrics,
19}
20
21#[derive(Clone, Serialize, Deserialize, JsonSchema, Debug, PartialEq, Eq, Hash)]
23pub enum ChangelogType {
24 Added,
25 Changed,
26 Deprecated,
27 Removed,
28 Fixed,
29 Security,
30}
31
32#[derive(Serialize, Deserialize, JsonSchema, Debug)]
34pub struct ChangeEntry {
35 pub description: String,
37 pub commit_hashes: Vec<String>,
39 pub associated_issues: Vec<String>,
41 pub pull_request: Option<String>,
43}
44
45#[derive(Serialize, Deserialize, JsonSchema, Debug)]
47pub struct BreakingChange {
48 pub description: String,
50 pub commit_hash: String,
52}
53
54#[derive(Clone, Serialize, Deserialize, JsonSchema, Debug)]
56pub struct ChangeMetrics {
57 pub total_commits: usize,
59 pub files_changed: usize,
61 pub insertions: usize,
63 pub deletions: usize,
65 pub total_lines_changed: usize,
67}
68
69#[derive(Serialize, Deserialize, JsonSchema, Debug)]
71pub struct ReleaseNotesResponse {
72 pub version: Option<String>,
74 pub release_date: Option<String>,
76 pub summary: String,
78 pub highlights: Vec<Highlight>,
80 pub sections: Vec<Section>,
82 pub breaking_changes: Vec<BreakingChange>,
84 pub upgrade_notes: Vec<String>,
86 pub metrics: ChangeMetrics,
88}
89
90#[derive(Serialize, Deserialize, JsonSchema, Debug)]
92pub struct Highlight {
93 pub title: String,
95 pub description: String,
97}
98
99#[derive(Serialize, Deserialize, JsonSchema, Debug)]
101pub struct Section {
102 pub title: String,
104 pub items: Vec<SectionItem>,
106}
107
108#[derive(Serialize, Deserialize, JsonSchema, Debug)]
110pub struct SectionItem {
111 pub description: String,
113 pub associated_issues: Vec<String>,
115 pub pull_request: Option<String>,
117}
118
119impl From<String> for ChangelogResponse {
120 fn from(value: String) -> Self {
122 serde_json::from_str(&value).unwrap_or_else(|e| {
123 log_debug!("Failed to parse ChangelogResponse: {}", e);
124 Self {
125 version: Some("Error".to_string()),
126 release_date: Some("Error".to_string()),
127 sections: HashMap::new(),
128 breaking_changes: Vec::new(),
129 metrics: ChangeMetrics {
130 total_commits: 0,
131 files_changed: 0,
132 insertions: 0,
133 deletions: 0,
134 total_lines_changed: 0,
135 },
136 }
137 })
138 }
139}
140
141impl From<String> for ReleaseNotesResponse {
142 fn from(value: String) -> Self {
144 serde_json::from_str(&value).unwrap_or_else(|e| {
145 log_debug!("Failed to parse ReleaseNotesResponse: {}", e);
146 Self {
147 version: Some("Error".to_string()),
148 release_date: Some("Error".to_string()),
149 summary: format!("Error parsing response: {e}"),
150 highlights: Vec::new(),
151 sections: Vec::new(),
152 breaking_changes: Vec::new(),
153 upgrade_notes: Vec::new(),
154 metrics: ChangeMetrics {
155 total_commits: 0,
156 files_changed: 0,
157 insertions: 0,
158 deletions: 0,
159 total_lines_changed: 0,
160 },
161 }
162 })
163 }
164}