1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

/// Represents the structured response for a changelog
#[derive(Serialize, Deserialize, JsonSchema, Debug)]
pub struct ChangelogResponse {
    /// The version number of the release
    pub version: Option<String>,
    /// The date of the release
    pub release_date: Option<String>,
    /// Categorized changes, grouped by type
    pub sections: HashMap<ChangelogType, Vec<ChangeEntry>>,
    /// List of breaking changes in this release
    pub breaking_changes: Vec<BreakingChange>,
    /// Metrics summarizing the changes in this release
    pub metrics: ChangeMetrics,
}

/// Enumeration of possible change types for changelog entries
#[derive(Clone, Serialize, Deserialize, JsonSchema, Debug, PartialEq, Eq, Hash)]
pub enum ChangelogType {
    Added,
    Changed,
    Deprecated,
    Removed,
    Fixed,
    Security,
}

/// Represents a single change entry in the changelog
#[derive(Serialize, Deserialize, JsonSchema, Debug)]
pub struct ChangeEntry {
    /// Description of the change
    pub description: String,
    /// List of commit hashes associated with this change
    pub commit_hashes: Vec<String>,
    /// List of issue numbers associated with this change
    pub associated_issues: Vec<String>,
    /// Pull request number associated with this change, if any
    pub pull_request: Option<String>,
}

/// Represents a breaking change in the release
#[derive(Serialize, Deserialize, JsonSchema, Debug)]
pub struct BreakingChange {
    /// Description of the breaking change
    pub description: String,
    /// Commit hash associated with this breaking change
    pub commit_hash: String,
}

/// Metrics summarizing the changes in a release
#[derive(Clone, Serialize, Deserialize, JsonSchema, Debug)]
pub struct ChangeMetrics {
    /// Total number of commits in this release
    pub total_commits: usize,
    /// Number of files changed in this release
    pub files_changed: usize,
    /// Number of lines inserted in this release
    pub insertions: usize,
    /// Number of lines deleted in this release
    pub deletions: usize,
    /// Total lines changed in this release
    pub total_lines_changed: usize,
}

/// Represents the structured response for release notes
#[derive(Serialize, Deserialize, JsonSchema, Debug)]
pub struct ReleaseNotesResponse {
    /// The version number of the release
    pub version: Option<String>,
    /// The date of the release
    pub release_date: Option<String>,
    /// A brief summary of the release
    pub summary: String,
    /// List of highlighted changes or features in this release
    pub highlights: Vec<Highlight>,
    /// Detailed sections of changes
    pub sections: Vec<Section>,
    /// List of breaking changes in this release
    pub breaking_changes: Vec<BreakingChange>,
    /// Notes for upgrading to this version
    pub upgrade_notes: Vec<String>,
    /// Metrics summarizing the changes in this release
    pub metrics: ChangeMetrics,
}

/// Represents a highlight in the release notes
#[derive(Serialize, Deserialize, JsonSchema, Debug)]
pub struct Highlight {
    /// Title of the highlight
    pub title: String,
    /// Detailed description of the highlight
    pub description: String,
}

/// Represents a section in the release notes
#[derive(Serialize, Deserialize, JsonSchema, Debug)]
pub struct Section {
    /// Title of the section
    pub title: String,
    /// List of items in this section
    pub items: Vec<SectionItem>,
}

/// Represents an item in a section of the release notes
#[derive(Serialize, Deserialize, JsonSchema, Debug)]
pub struct SectionItem {
    /// Description of the change
    pub description: String,
    /// List of issue numbers associated with this change
    pub associated_issues: Vec<String>,
    /// Pull request number associated with this change, if any
    pub pull_request: Option<String>,
}

impl From<String> for ChangelogResponse {
    /// Converts a JSON string to a ChangelogResponse
    fn from(value: String) -> Self {
        serde_json::from_str(&value).unwrap()
    }
}

impl From<String> for ReleaseNotesResponse {
    /// Converts a JSON string to a ReleaseNotesResponse
    fn from(value: String) -> Self {
        serde_json::from_str(&value).unwrap()
    }
}