Skip to main content

bitbucket_cli/models/
issue.rs

1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3
4use super::user::{Link, User};
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct Issue {
8    pub id: u64,
9    pub title: String,
10    pub content: Option<IssueContent>,
11    pub reporter: Option<User>,
12    pub assignee: Option<User>,
13    pub state: IssueState,
14    pub kind: IssueKind,
15    pub priority: IssuePriority,
16    pub milestone: Option<Milestone>,
17    pub component: Option<Component>,
18    pub version: Option<Version>,
19    pub votes: Option<u32>,
20    pub watches: Option<u32>,
21    pub created_on: DateTime<Utc>,
22    pub updated_on: Option<DateTime<Utc>>,
23    pub edited_on: Option<DateTime<Utc>>,
24    pub links: Option<IssueLinks>,
25}
26
27#[derive(Debug, Clone, Serialize, Deserialize)]
28pub struct IssueContent {
29    pub raw: Option<String>,
30    pub markup: Option<String>,
31    pub html: Option<String>,
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
35#[serde(rename_all = "lowercase")]
36pub enum IssueState {
37    New,
38    Open,
39    Resolved,
40    #[serde(rename = "on hold")]
41    OnHold,
42    Invalid,
43    Duplicate,
44    Wontfix,
45    Closed,
46}
47
48impl std::fmt::Display for IssueState {
49    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
50        match self {
51            IssueState::New => write!(f, "new"),
52            IssueState::Open => write!(f, "open"),
53            IssueState::Resolved => write!(f, "resolved"),
54            IssueState::OnHold => write!(f, "on hold"),
55            IssueState::Invalid => write!(f, "invalid"),
56            IssueState::Duplicate => write!(f, "duplicate"),
57            IssueState::Wontfix => write!(f, "wontfix"),
58            IssueState::Closed => write!(f, "closed"),
59        }
60    }
61}
62
63#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
64#[serde(rename_all = "lowercase")]
65pub enum IssueKind {
66    Bug,
67    Enhancement,
68    Proposal,
69    Task,
70}
71
72impl std::fmt::Display for IssueKind {
73    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
74        match self {
75            IssueKind::Bug => write!(f, "bug"),
76            IssueKind::Enhancement => write!(f, "enhancement"),
77            IssueKind::Proposal => write!(f, "proposal"),
78            IssueKind::Task => write!(f, "task"),
79        }
80    }
81}
82
83#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
84#[serde(rename_all = "lowercase")]
85pub enum IssuePriority {
86    Trivial,
87    Minor,
88    Major,
89    Critical,
90    Blocker,
91}
92
93impl std::fmt::Display for IssuePriority {
94    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
95        match self {
96            IssuePriority::Trivial => write!(f, "trivial"),
97            IssuePriority::Minor => write!(f, "minor"),
98            IssuePriority::Major => write!(f, "major"),
99            IssuePriority::Critical => write!(f, "critical"),
100            IssuePriority::Blocker => write!(f, "blocker"),
101        }
102    }
103}
104
105#[derive(Debug, Clone, Serialize, Deserialize)]
106pub struct Milestone {
107    pub id: u64,
108    pub name: String,
109}
110
111#[derive(Debug, Clone, Serialize, Deserialize)]
112pub struct Component {
113    pub id: u64,
114    pub name: String,
115}
116
117#[derive(Debug, Clone, Serialize, Deserialize)]
118pub struct Version {
119    pub id: u64,
120    pub name: String,
121}
122
123#[derive(Debug, Clone, Serialize, Deserialize)]
124pub struct IssueLinks {
125    #[serde(rename = "self")]
126    pub self_link: Option<Link>,
127    pub html: Option<Link>,
128    pub comments: Option<Link>,
129    pub attachments: Option<Link>,
130    pub watch: Option<Link>,
131    pub vote: Option<Link>,
132}
133
134#[derive(Debug, Clone, Serialize, Deserialize)]
135#[non_exhaustive]
136pub struct CreateIssueRequest {
137    pub title: String,
138    pub content: Option<IssueContentRequest>,
139    pub kind: Option<IssueKind>,
140    pub priority: Option<IssuePriority>,
141    pub assignee: Option<UserAccountId>,
142    pub component: Option<ComponentName>,
143    pub milestone: Option<MilestoneName>,
144    pub version: Option<VersionName>,
145}
146
147#[derive(Debug, Clone, Serialize, Deserialize)]
148pub struct IssueContentRequest {
149    pub raw: String,
150}
151
152#[derive(Debug, Clone, Serialize, Deserialize)]
153pub struct UserAccountId {
154    pub account_id: String,
155}
156
157#[derive(Debug, Clone, Serialize, Deserialize)]
158pub struct ComponentName {
159    pub name: String,
160}
161
162#[derive(Debug, Clone, Serialize, Deserialize)]
163pub struct MilestoneName {
164    pub name: String,
165}
166
167#[derive(Debug, Clone, Serialize, Deserialize)]
168pub struct VersionName {
169    pub name: String,
170}
171
172#[derive(Debug, Clone, Serialize, Deserialize)]
173pub struct IssueComment {
174    pub id: u64,
175    pub content: IssueContent,
176    pub user: User,
177    pub created_on: DateTime<Utc>,
178    pub updated_on: Option<DateTime<Utc>>,
179    pub links: Option<IssueCommentLinks>,
180}
181
182#[derive(Debug, Clone, Serialize, Deserialize)]
183pub struct IssueCommentLinks {
184    #[serde(rename = "self")]
185    pub self_link: Option<Link>,
186    pub html: Option<Link>,
187}
188
189#[derive(Debug, Clone, Serialize, Deserialize)]
190pub struct CreateIssueCommentRequest {
191    pub content: IssueContentRequest,
192}
193
194/// A single entry in an issue's change log (state transitions, reassignments,
195/// priority bumps, ...).
196#[derive(Debug, Clone, Serialize, Deserialize)]
197pub struct IssueChange {
198    pub id: Option<u64>,
199    pub user: Option<User>,
200    pub message: Option<IssueContent>,
201    pub created_on: Option<DateTime<Utc>>,
202    /// Map of changed field name to `{old, new}` values. Kept as raw JSON
203    /// because the API emits arbitrary field names here.
204    pub changes: Option<serde_json::Value>,
205}
206
207/// Shared shape for issue tracker metadata: components, milestones and
208/// versions all serialize as an id plus a name.
209#[derive(Debug, Clone, Serialize, Deserialize)]
210pub struct IssueMetaItem {
211    pub id: Option<u64>,
212    pub name: Option<String>,
213}
214
215/// A file attached to an issue.
216#[derive(Debug, Clone, Serialize, Deserialize)]
217pub struct IssueAttachment {
218    pub name: Option<String>,
219    /// Kept as raw JSON: the API serves `links.self.href` for attachments as
220    /// either a string or an array of strings.
221    pub links: Option<serde_json::Value>,
222}