1use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5
6use crate::pack::PackMetadata;
7use crate::values::Values;
8
9#[derive(Debug, Clone, Serialize, Deserialize)]
11#[serde(rename_all = "camelCase")]
12pub struct Release {
13 pub name: String,
15
16 pub namespace: String,
18
19 pub revision: u32,
21
22 pub status: ReleaseStatus,
24
25 pub pack: PackMetadata,
27
28 pub values: Values,
30
31 pub manifest: String,
33
34 pub created_at: DateTime<Utc>,
36
37 pub updated_at: DateTime<Utc>,
39}
40
41#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
45#[serde(rename_all = "kebab-case")]
46#[non_exhaustive]
47pub enum ReleaseStatus {
48 #[default]
49 Unknown,
50 Deployed,
51 Uninstalled,
52 Superseded,
53 Failed,
54 Uninstalling,
55 PendingInstall,
56 PendingUpgrade,
57 PendingRollback,
58}
59
60impl std::fmt::Display for ReleaseStatus {
61 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
62 let s = match self {
63 Self::Unknown => "unknown",
64 Self::Deployed => "deployed",
65 Self::Uninstalled => "uninstalled",
66 Self::Superseded => "superseded",
67 Self::Failed => "failed",
68 Self::Uninstalling => "uninstalling",
69 Self::PendingInstall => "pending-install",
70 Self::PendingUpgrade => "pending-upgrade",
71 Self::PendingRollback => "pending-rollback",
72 };
73 write!(f, "{}", s)
74 }
75}
76
77#[derive(Debug, Clone, Serialize, Deserialize)]
79#[serde(rename_all = "camelCase")]
80pub struct ReleaseInfo {
81 pub name: String,
83
84 pub namespace: String,
86
87 pub revision: u32,
89
90 pub is_install: bool,
92
93 pub is_upgrade: bool,
95
96 pub service: String,
98}
99
100impl ReleaseInfo {
101 pub fn for_install(name: &str, namespace: &str) -> Self {
103 Self {
104 name: name.to_string(),
105 namespace: namespace.to_string(),
106 revision: 1,
107 is_install: true,
108 is_upgrade: false,
109 service: "Sherpack".to_string(),
110 }
111 }
112
113 pub fn for_upgrade(name: &str, namespace: &str, revision: u32) -> Self {
115 Self {
116 name: name.to_string(),
117 namespace: namespace.to_string(),
118 revision,
119 is_install: false,
120 is_upgrade: true,
121 service: "Sherpack".to_string(),
122 }
123 }
124}