lib_client_gitlab/
types.rs

1use serde::{Deserialize, Serialize};
2
3/// Project in GitLab.
4#[derive(Debug, Clone, Deserialize)]
5pub struct Project {
6    pub id: u64,
7    pub name: String,
8    pub name_with_namespace: String,
9    pub path: String,
10    pub path_with_namespace: String,
11    pub description: Option<String>,
12    pub default_branch: Option<String>,
13    pub web_url: String,
14    pub ssh_url_to_repo: String,
15    pub http_url_to_repo: String,
16    pub visibility: String,
17    pub created_at: String,
18    pub last_activity_at: String,
19}
20
21/// Merge request.
22#[derive(Debug, Clone, Deserialize)]
23pub struct MergeRequest {
24    pub id: u64,
25    pub iid: u64,
26    pub title: String,
27    pub description: Option<String>,
28    pub state: String,
29    pub source_branch: String,
30    pub target_branch: String,
31    pub author: User,
32    pub assignee: Option<User>,
33    pub web_url: String,
34    pub created_at: String,
35    pub updated_at: String,
36    pub merged_at: Option<String>,
37    pub closed_at: Option<String>,
38    pub draft: bool,
39    pub merge_status: String,
40}
41
42/// Issue in GitLab.
43#[derive(Debug, Clone, Deserialize)]
44pub struct Issue {
45    pub id: u64,
46    pub iid: u64,
47    pub title: String,
48    pub description: Option<String>,
49    pub state: String,
50    pub author: User,
51    pub assignee: Option<User>,
52    pub labels: Vec<String>,
53    pub web_url: String,
54    pub created_at: String,
55    pub updated_at: String,
56    pub closed_at: Option<String>,
57}
58
59/// User in GitLab.
60#[derive(Debug, Clone, Deserialize)]
61pub struct User {
62    pub id: u64,
63    pub username: String,
64    pub name: String,
65    pub avatar_url: Option<String>,
66    pub web_url: String,
67}
68
69/// Pipeline.
70#[derive(Debug, Clone, Deserialize)]
71pub struct Pipeline {
72    pub id: u64,
73    pub iid: u64,
74    #[serde(rename = "ref")]
75    pub git_ref: String,
76    pub sha: String,
77    pub status: String,
78    pub source: String,
79    pub web_url: String,
80    pub created_at: String,
81    pub updated_at: String,
82}
83
84/// Pipeline job.
85#[derive(Debug, Clone, Deserialize)]
86pub struct Job {
87    pub id: u64,
88    pub name: String,
89    pub stage: String,
90    pub status: String,
91    pub web_url: String,
92    pub created_at: String,
93    pub started_at: Option<String>,
94    pub finished_at: Option<String>,
95}
96
97/// Branch.
98#[derive(Debug, Clone, Deserialize)]
99pub struct Branch {
100    pub name: String,
101    pub commit: Commit,
102    pub protected: bool,
103    pub default: bool,
104    pub web_url: String,
105}
106
107/// Commit.
108#[derive(Debug, Clone, Deserialize)]
109pub struct Commit {
110    pub id: String,
111    pub short_id: String,
112    pub title: String,
113    pub message: String,
114    pub author_name: String,
115    pub author_email: String,
116    pub authored_date: String,
117    pub committed_date: String,
118    pub web_url: Option<String>,
119}
120
121/// File content.
122#[derive(Debug, Clone, Deserialize)]
123pub struct FileContent {
124    pub file_name: String,
125    pub file_path: String,
126    pub size: u64,
127    pub encoding: String,
128    pub content: String,
129    pub content_sha256: String,
130    #[serde(rename = "ref")]
131    pub git_ref: String,
132    pub blob_id: String,
133    pub commit_id: String,
134    pub last_commit_id: String,
135}
136
137/// Input for creating a merge request.
138#[derive(Debug, Clone, Default, Serialize)]
139pub struct CreateMergeRequestInput {
140    pub source_branch: String,
141    pub target_branch: String,
142    pub title: String,
143    #[serde(skip_serializing_if = "Option::is_none")]
144    pub description: Option<String>,
145    #[serde(skip_serializing_if = "Option::is_none")]
146    pub assignee_id: Option<u64>,
147    #[serde(skip_serializing_if = "Option::is_none")]
148    pub remove_source_branch: Option<bool>,
149    #[serde(skip_serializing_if = "Option::is_none")]
150    pub squash: Option<bool>,
151    #[serde(skip_serializing_if = "Option::is_none")]
152    pub labels: Option<String>,
153}
154
155impl CreateMergeRequestInput {
156    pub fn new(
157        source_branch: impl Into<String>,
158        target_branch: impl Into<String>,
159        title: impl Into<String>,
160    ) -> Self {
161        Self {
162            source_branch: source_branch.into(),
163            target_branch: target_branch.into(),
164            title: title.into(),
165            ..Default::default()
166        }
167    }
168
169    pub fn description(mut self, desc: impl Into<String>) -> Self {
170        self.description = Some(desc.into());
171        self
172    }
173
174    pub fn assignee(mut self, id: u64) -> Self {
175        self.assignee_id = Some(id);
176        self
177    }
178
179    pub fn remove_source_branch(mut self, remove: bool) -> Self {
180        self.remove_source_branch = Some(remove);
181        self
182    }
183}
184
185/// Input for creating an issue.
186#[derive(Debug, Clone, Default, Serialize)]
187pub struct CreateIssueInput {
188    pub title: String,
189    #[serde(skip_serializing_if = "Option::is_none")]
190    pub description: Option<String>,
191    #[serde(skip_serializing_if = "Option::is_none")]
192    pub assignee_id: Option<u64>,
193    #[serde(skip_serializing_if = "Option::is_none")]
194    pub labels: Option<String>,
195    #[serde(skip_serializing_if = "Option::is_none")]
196    pub milestone_id: Option<u64>,
197    #[serde(skip_serializing_if = "Option::is_none")]
198    pub confidential: Option<bool>,
199}
200
201impl CreateIssueInput {
202    pub fn new(title: impl Into<String>) -> Self {
203        Self {
204            title: title.into(),
205            ..Default::default()
206        }
207    }
208
209    pub fn description(mut self, desc: impl Into<String>) -> Self {
210        self.description = Some(desc.into());
211        self
212    }
213
214    pub fn assignee(mut self, id: u64) -> Self {
215        self.assignee_id = Some(id);
216        self
217    }
218
219    pub fn labels(mut self, labels: impl Into<String>) -> Self {
220        self.labels = Some(labels.into());
221        self
222    }
223}
224
225/// Merge request state filter.
226#[derive(Debug, Clone, Copy, Serialize)]
227#[serde(rename_all = "lowercase")]
228pub enum MergeRequestState {
229    Opened,
230    Closed,
231    Merged,
232    All,
233}
234
235/// Issue state filter.
236#[derive(Debug, Clone, Copy, Serialize)]
237#[serde(rename_all = "lowercase")]
238pub enum IssueState {
239    Opened,
240    Closed,
241    All,
242}