gitea_sdk/model/
issues.rs

1use std::fmt::{self, Display};
2
3use serde::{Deserialize, Serialize};
4
5use crate::model::user::User;
6
7/// Represents an attachment.
8/// Attachments are used in issues, pull requests, and releases.
9#[derive(Default, Debug, Clone, Serialize, Deserialize)]
10#[serde(default)]
11pub struct Attachment {
12    pub browser_download_url: String,
13    pub created_at: String,
14    pub download_count: i64,
15    pub id: i64,
16    pub name: String,
17    pub size: i64,
18    pub uuid: String,
19}
20
21/// Represents a label.
22/// Labels are used in issues and pull requests.
23#[derive(Default, Debug, Clone, Serialize, Deserialize)]
24#[serde(default)]
25pub struct Label {
26    pub color: String,
27    pub description: String,
28    pub exclusive: bool,
29    pub id: i64,
30    pub is_archived: bool,
31    pub name: String,
32    pub url: String,
33}
34
35#[derive(Default, Debug, Clone, Serialize, Deserialize)]
36/// Represents the state of an issue.
37pub enum State {
38    #[serde(rename = "open")]
39    Open,
40    #[serde(rename = "closed")]
41    Closed,
42    #[serde(rename = "all")]
43    #[default]
44    All,
45}
46impl Display for State {
47    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48        match self {
49            State::Open => write!(f, "open"),
50            State::Closed => write!(f, "closed"),
51            State::All => write!(f, "all"),
52        }
53    }
54}
55
56/// Represents an issue in a repository.
57#[derive(Default, Debug, Clone, Serialize, Deserialize)]
58#[serde(default)]
59pub struct Issue {
60    pub assets: Vec<Attachment>,
61    pub assignee: Option<User>,
62    pub assignees: Option<Vec<User>>,
63    pub body: Option<String>,
64    pub closed_at: Option<String>,
65    pub comments: i64,
66    pub created_at: String,
67    pub due_date: Option<String>,
68    pub html_url: String,
69    pub id: i64,
70    pub is_locked: bool,
71    pub labels: Vec<Label>,
72    pub number: i64,
73    pub original_author: String,
74    pub original_author_id: i64,
75    pub pin_order: i64,
76    pub r#ref: String,
77    pub state: StateType,
78    pub updated_at: String,
79    pub title: String,
80    pub url: String,
81    pub user: User,
82}
83
84#[derive(Default, Debug, Clone, Serialize, Deserialize)]
85pub struct Comment {
86    pub assets: Vec<Attachment>,
87    pub body: String,
88    pub created_at: String,
89    pub html_url: String,
90    pub id: i64,
91    pub issue_url: String,
92    pub original_author: String,
93    pub original_author_id: i64,
94    pub pull_request_url: String,
95    pub updated_at: String,
96    pub user: User,
97}
98
99#[derive(Default, Debug, Clone, Serialize, Deserialize)]
100pub enum StateType {
101    #[default]
102    #[serde(rename = "open")]
103    Open,
104    #[serde(rename = "closed")]
105    Closed,
106}
107
108#[derive(Debug, Clone, Serialize, Deserialize)]
109pub enum IssueType {
110    #[serde(rename = "issues")]
111    Issues,
112    #[serde(rename = "pulls")]
113    Pulls,
114}
115
116impl Display for IssueType {
117    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
118        match self {
119            IssueType::Issues => write!(f, "issues"),
120            IssueType::Pulls => write!(f, "pulls"),
121        }
122    }
123}