git_iris/changes/
models.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3use std::collections::HashMap;
4
5/// Represents the structured response for a changelog
6#[derive(Serialize, Deserialize, JsonSchema, Debug)]
7pub struct ChangelogResponse {
8    /// The version number of the release
9    pub version: Option<String>,
10    /// The date of the release
11    pub release_date: Option<String>,
12    /// Categorized changes, grouped by type
13    pub sections: HashMap<ChangelogType, Vec<ChangeEntry>>,
14    /// List of breaking changes in this release
15    pub breaking_changes: Vec<BreakingChange>,
16    /// Metrics summarizing the changes in this release
17    pub metrics: ChangeMetrics,
18}
19
20/// Enumeration of possible change types for changelog entries
21#[derive(Clone, Serialize, Deserialize, JsonSchema, Debug, PartialEq, Eq, Hash)]
22pub enum ChangelogType {
23    Added,
24    Changed,
25    Deprecated,
26    Removed,
27    Fixed,
28    Security,
29}
30
31/// Represents a single change entry in the changelog
32#[derive(Serialize, Deserialize, JsonSchema, Debug)]
33pub struct ChangeEntry {
34    /// Description of the change
35    pub description: String,
36    /// List of commit hashes associated with this change
37    pub commit_hashes: Vec<String>,
38    /// List of issue numbers associated with this change
39    pub associated_issues: Vec<String>,
40    /// Pull request number associated with this change, if any
41    pub pull_request: Option<String>,
42}
43
44/// Represents a breaking change in the release
45#[derive(Serialize, Deserialize, JsonSchema, Debug)]
46pub struct BreakingChange {
47    /// Description of the breaking change
48    pub description: String,
49    /// Commit hash associated with this breaking change
50    pub commit_hash: String,
51}
52
53/// Metrics summarizing the changes in a release
54#[derive(Clone, Serialize, Deserialize, JsonSchema, Debug)]
55pub struct ChangeMetrics {
56    /// Total number of commits in this release
57    pub total_commits: usize,
58    /// Number of files changed in this release
59    pub files_changed: usize,
60    /// Number of lines inserted in this release
61    pub insertions: usize,
62    /// Number of lines deleted in this release
63    pub deletions: usize,
64    /// Total lines changed in this release
65    pub total_lines_changed: usize,
66}
67
68/// Represents the structured response for release notes
69#[derive(Serialize, Deserialize, JsonSchema, Debug)]
70pub struct ReleaseNotesResponse {
71    /// The version number of the release
72    pub version: Option<String>,
73    /// The date of the release
74    pub release_date: Option<String>,
75    /// A brief summary of the release
76    pub summary: String,
77    /// List of highlighted changes or features in this release
78    pub highlights: Vec<Highlight>,
79    /// Detailed sections of changes
80    pub sections: Vec<Section>,
81    /// List of breaking changes in this release
82    pub breaking_changes: Vec<BreakingChange>,
83    /// Notes for upgrading to this version
84    pub upgrade_notes: Vec<String>,
85    /// Metrics summarizing the changes in this release
86    pub metrics: ChangeMetrics,
87}
88
89/// Represents a highlight in the release notes
90#[derive(Serialize, Deserialize, JsonSchema, Debug)]
91pub struct Highlight {
92    /// Title of the highlight
93    pub title: String,
94    /// Detailed description of the highlight
95    pub description: String,
96}
97
98/// Represents a section in the release notes
99#[derive(Serialize, Deserialize, JsonSchema, Debug)]
100pub struct Section {
101    /// Title of the section
102    pub title: String,
103    /// List of items in this section
104    pub items: Vec<SectionItem>,
105}
106
107/// Represents an item in a section of the release notes
108#[derive(Serialize, Deserialize, JsonSchema, Debug)]
109pub struct SectionItem {
110    /// Description of the change
111    pub description: String,
112    /// List of issue numbers associated with this change
113    pub associated_issues: Vec<String>,
114    /// Pull request number associated with this change, if any
115    pub pull_request: Option<String>,
116}
117
118impl From<String> for ChangelogResponse {
119    /// Converts a JSON string to a `ChangelogResponse`
120    #[allow(clippy::unwrap_used)] // todo: handle unwrap maybe use try_from instead
121    fn from(value: String) -> Self {
122        serde_json::from_str(&value).unwrap()
123    }
124}
125
126impl From<String> for ReleaseNotesResponse {
127    /// Converts a JSON string to a `ReleaseNotesResponse`
128    #[allow(clippy::unwrap_used)] // todo: handle unwrap maybe use try_from instead
129    fn from(value: String) -> Self {
130        serde_json::from_str(&value).unwrap()
131    }
132}