1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
use serde::{Deserialize, Serialize};
use std::collections::{HashMap, HashSet};
#[derive(Deserialize, Debug, Clone)]
pub struct GitLabUser {
pub username: String,
pub name: String,
}
/// A GitLab milestone as returned by the milestones API endpoint.
#[derive(Deserialize, Debug, Clone)]
pub struct GitLabMilestone {
pub title: String,
/// Due date in `YYYY-MM-DD` format, or `None` when not set.
pub due_date: Option<String>,
}
/// Represents the GitLab-side lifecycle state of a merge request.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
#[serde(rename_all = "lowercase")]
pub enum GitlabMrState {
#[default]
Opened,
Merged,
Closed,
}
/// Represents the mergeability status of an open merge request as reported by GitLab.
///
/// Only meaningful for MRs in the `Opened` state — ignored for Merged/Closed.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
pub enum MergeabilityStatus {
/// GitLab reports the MR can be merged cleanly.
Mergeable,
/// The MR has conflicts that must be resolved before merging.
Conflict,
/// The MR branch is behind the target branch and needs a rebase.
NeedsRebase,
/// The MR is not open (already merged or closed in GitLab).
NotOpen,
/// The MR is a draft — intentionally not ready to merge.
Draft,
/// There are unresolved discussion threads on the MR.
DiscussionsNotResolved,
/// A CI pipeline is required before this MR can be merged.
CiMustPass,
/// A CI pipeline is currently running.
CiStillRunning,
/// Required approvals are missing.
NotApproved,
/// A reviewer has explicitly requested changes before the MR can be merged.
RequestedChanges,
/// Status not yet fetched, not applicable, or an unrecognised value.
#[default]
Unknown,
}
#[derive(Deserialize, Debug, Clone)]
pub struct GitLabMr {
pub title: String,
pub state: Option<GitlabMrState>,
pub description: Option<String>,
pub author: Option<GitLabUser>,
pub assignee: Option<GitLabUser>,
/// List of reviewers assigned to this MR (GitLab returns an array).
pub reviewers: Option<Vec<GitLabUser>>,
/// User who merged the MR — populated by GitLab only when `state == merged`.
pub merged_by: Option<GitLabUser>,
/// ISO 8601 timestamp when the MR was merged — `None` for open/closed MRs.
pub merged_at: Option<String>,
pub milestone: Option<GitLabMilestone>,
pub merge_commit_sha: Option<String>,
pub squash_commit_sha: Option<String>,
pub web_url: Option<String>,
pub labels: Option<Vec<String>>,
pub updated_at: Option<String>,
/// Source branch of the MR (the feature branch).
pub source_branch: Option<String>,
/// Target branch that this MR is intended to be merged into.
pub target_branch: Option<String>,
/// Legacy mergeability field (GitLab < 15.6): `"can_be_merged"`, `"cannot_be_merged"`, …
pub merge_status: Option<String>,
/// Detailed mergeability field (GitLab ≥ 15.6): `"mergeable"`, `"need_rebase"`,
/// `"conflict"`, `"checking"`, `"not_open"`, etc. Takes priority over `merge_status`.
pub detailed_merge_status: Option<String>,
/// Whether the MR has unresolved merge conflicts (complementary signal from GitLab).
pub has_conflicts: Option<bool>,
/// Total number of user notes (comments + discussion threads) on this MR.
/// Returned natively by the GitLab API — no extra request needed.
pub user_notes_count: Option<u32>,
}
#[derive(Deserialize, Debug, Clone)]
pub struct GitLabRef {
pub name: String,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct SavedMr {
pub id: String,
pub title: String,
pub sha: Option<String>,
pub found_branches: HashSet<String>,
pub description: Option<String>,
pub author: Option<String>,
pub assignee: Option<String>,
/// Reviewer display strings — persisted across restarts.
#[serde(default)]
pub reviewers: Vec<String>,
pub milestone: Option<String>,
/// Milestone due date in `YYYY-MM-DD` format — persisted across restarts.
#[serde(default)]
pub milestone_due_date: Option<String>,
pub web_url: Option<String>,
pub labels: Option<Vec<String>>,
#[serde(default)]
pub updated_at: Option<String>,
/// Source branch of the MR (the feature branch) — persisted across restarts.
#[serde(default)]
pub source_branch: Option<String>,
/// Target branch that this MR is intended to be merged into — persisted across restarts.
#[serde(default)]
pub target_branch: Option<String>,
#[serde(default)]
pub state: GitlabMrState,
/// User who merged the MR — `None` for open/closed MRs. Persisted across restarts.
#[serde(default)]
pub merged_by: Option<String>,
/// ISO 8601 timestamp when the MR was merged — `None` for open/closed MRs.
#[serde(default)]
pub merged_at: Option<String>,
/// Persisted pipeline snapshots — restored on startup, refreshed on each MR fetch.
#[serde(default)]
pub pipelines: Vec<Pipeline>,
/// Total number of user notes (comments + threads) — persisted across restarts.
#[serde(default)]
pub user_notes_count: u32,
/// Whether the MR has been manually flagged by the user — persisted across restarts.
#[serde(default)]
pub flagged: bool,
/// Last resolved tracker ticket — persisted to avoid re-fetching the tracker on every restart.
/// Re-fetched only when the detected ticket ID changes (title/description update).
/// `None` when no tracker provider is configured or no ticket reference was found.
#[serde(default)]
pub linked_ticket: Option<gitlab_tracker_core::LinkedTicket>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct SavedState {
pub mrs: Vec<SavedMr>,
pub branches: Vec<String>,
#[serde(default)]
pub last_known_branches: HashMap<String, HashSet<String>>,
}
#[derive(Clone, Debug, PartialEq)]
pub enum MrStatus {
Loading,
Error,
MergedIn(HashSet<String>),
}
#[derive(Clone, Debug)]
pub struct TrackedMr {
pub id: String,
pub title: String,
pub status: MrStatus,
pub sha: Option<String>,
pub description: String,
pub author: String,
pub assignee: String,
/// Reviewer display strings — may be empty when no reviewer is assigned.
pub reviewers: Vec<String>,
pub milestone: String,
/// Milestone due date in `YYYY-MM-DD` format — `None` when not set.
pub milestone_due_date: Option<String>,
pub web_url: String,
pub labels: Vec<String>,
pub updated_at: Option<String>,
/// Source branch of the MR (the feature branch).
pub source_branch: String,
pub target_branch: String,
pub state: GitlabMrState,
/// User who merged the MR — None for open/closed MRs.
pub merged_by: Option<String>,
/// ISO 8601 timestamp when the MR was merged — None for open/closed MRs.
pub merged_at: Option<String>,
/// Mergeability state for open MRs — drives the animated status badge.
pub mergeability: MergeabilityStatus,
/// Pipelines fetched alongside the MR data and persisted across restarts.
pub pipelines: Vec<Pipeline>,
/// Set to `true` when `updated_at` changed during the last refresh cycle.
/// Drives the row highlight animation in the table. Reset after the fade window expires.
pub recently_updated: bool,
/// Total number of user notes (comments + discussion threads) on this MR.
pub user_notes_count: u32,
/// Manually flagged by the user (Space key) — persisted across restarts.
/// Flagged MRs display a coloured chevron and can be isolated via the Flagged filter.
pub flagged: bool,
/// Ticket linked to this MR, resolved by the active [`TrackerProvider`].
/// `None` when no tracker provider is configured or no ticket reference was found.
pub linked_ticket: Option<gitlab_tracker_core::LinkedTicket>,
}
#[derive(Debug, Clone)]
pub struct MrLoadedData {
pub id: String,
pub title: String,
pub sha: Option<String>,
pub branches: HashSet<String>,
pub description: String,
pub author: String,
pub assignee: String,
/// Reviewer display strings resolved from the GitLab API response.
pub reviewers: Vec<String>,
pub milestone: String,
/// Milestone due date in `YYYY-MM-DD` format — `None` when not set.
pub milestone_due_date: Option<String>,
pub web_url: String,
pub labels: Vec<String>,
pub updated_at: Option<String>,
/// Source branch of the MR (the feature branch).
pub source_branch: String,
pub target_branch: String,
pub state: GitlabMrState,
/// User who merged the MR — None for open/closed MRs.
pub merged_by: Option<String>,
/// ISO 8601 timestamp when the MR was merged — None for open/closed MRs.
pub merged_at: Option<String>,
/// Mergeability resolved from the GitLab API response.
pub mergeability: MergeabilityStatus,
/// Pipelines fetched in the same request batch as the MR data.
pub pipelines: Vec<Pipeline>,
/// Total number of user notes (comments + discussion threads) on this MR.
pub user_notes_count: u32,
}
/// Lifecycle state of a GitLab pipeline run.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
#[serde(rename_all = "lowercase")]
pub enum PipelineState {
Created,
Pending,
Running,
Success,
Failed,
Canceled,
Skipped,
#[serde(other)]
#[default]
Unknown,
}
/// A single job within a pipeline, as returned by the GitLab API.
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PipelineJob {
#[serde(default)]
pub name: String,
#[serde(default)]
pub stage: String,
#[serde(default)]
pub status: String,
/// Duration in seconds, null while running.
pub duration: Option<f64>,
}
/// A GitLab pipeline attached to a merge request.
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Pipeline {
pub id: u64,
#[serde(default)]
pub status: PipelineState,
/// ISO 8601 timestamp when the pipeline was created (i.e. triggered).
/// Populated directly from the GitLab API — `None` when not provided.
pub created_at: Option<String>,
/// Jobs are fetched alongside the pipeline and persisted across restarts.
#[serde(default)]
pub jobs: Vec<PipelineJob>,
}
pub enum AppEvent {
MrLoaded(Box<MrLoadedData>),
MrFailed {
id: String,
error: String,
},
/// Fired when the milestone list has been fetched from GitLab.
MilestonesLoaded(Vec<GitLabMilestone>),
/// Fired when the MR IDs linked to a milestone have been resolved.
MilestoneMrsLoaded {
milestone_title: String,
mr_ids: Vec<String>,
},
/// Fired when a tracker plugin has resolved the ticket linked to a MR.
/// Emitted by any active tracker provider (Redmine, Jira, Trello, …).
TrackerTicketLoaded {
mr_id: String,
ticket: gitlab_tracker_core::LinkedTicket,
},
/// Fired when the list of time-tracking activity categories has been fetched.
/// Stored in `App` for use in the Log Time popup selector.
ActivitiesLoaded(Vec<gitlab_tracker_core::Activity>),
/// Fired when time entries for a ticket have been fetched from the tracker.
TimeEntriesLoaded {
entries: Vec<gitlab_tracker_core::TimeEntry>,
},
/// Fired when a time entry has been successfully submitted to the tracker.
/// Carries both the MR id (to update the right `linked_ticket` in memory) and the
/// raw ticket id (to re-fetch time entries and the updated spent total).
TimeLogSubmitted {
/// The GitLab MR id that owns the ticket (used to route `TrackerTicketLoaded`).
mr_id: String,
/// The tracker ticket id that received the new time entry.
ticket_id: String,
},
/// Fired when a time entry submission failed.
/// The error string is shown inline in the popup.
TimeLogFailed {
error: String,
},
Tick,
}