use serde::{Deserialize, Serialize};
use std::collections::{HashMap, HashSet};
#[derive(Deserialize, Debug, Clone)]
pub struct GitLabUser {
pub username: String,
}
#[derive(Deserialize, Debug, Clone)]
pub struct GitLabMilestone {
pub title: String,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
#[serde(rename_all = "lowercase")]
pub enum GitlabMrState {
#[default]
Opened,
Merged,
Closed,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
pub enum MergeabilityStatus {
Mergeable,
Conflict,
NeedsRebase,
#[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>,
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>,
pub target_branch: Option<String>,
pub merge_status: Option<String>,
pub detailed_merge_status: Option<String>,
pub has_conflicts: Option<bool>,
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>,
pub milestone: Option<String>,
pub web_url: Option<String>,
pub labels: Option<Vec<String>>,
#[serde(default)]
pub updated_at: Option<String>,
#[serde(default)]
pub target_branch: Option<String>,
#[serde(default)]
pub state: GitlabMrState,
#[serde(default)]
pub pipelines: Vec<Pipeline>,
#[serde(default)]
pub user_notes_count: u32,
}
#[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,
pub milestone: String,
pub web_url: String,
pub labels: Vec<String>,
pub updated_at: Option<String>,
pub target_branch: String,
pub state: GitlabMrState,
pub mergeability: MergeabilityStatus,
pub pipelines: Vec<Pipeline>,
pub recently_updated: bool,
pub user_notes_count: u32,
}
#[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,
pub milestone: String,
pub web_url: String,
pub labels: Vec<String>,
pub updated_at: Option<String>,
pub target_branch: String,
pub state: GitlabMrState,
pub mergeability: MergeabilityStatus,
pub pipelines: Vec<Pipeline>,
pub user_notes_count: u32,
}
#[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,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PipelineJob {
pub name: String,
pub stage: String,
pub status: String,
pub duration: Option<f64>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Pipeline {
pub id: u64,
#[serde(default)]
pub status: PipelineState,
#[serde(skip)]
pub jobs: Vec<PipelineJob>,
}
pub enum AppEvent {
MrLoaded(Box<MrLoadedData>),
MrFailed { id: String, error: String },
Tick,
}