use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct FetchOutcome {
pub remote: String,
pub refspecs: Vec<String>,
pub updated_refs: Vec<UpdatedRef>,
#[serde(default)]
pub checks_imported: usize,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct UpdatedRef {
pub ref_name: String,
pub previous_sha: String,
pub new_sha: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct PullOutcome {
pub mem: String,
pub source_ref: String,
pub branch_ref: String,
pub previous_sha: String,
pub new_sha: String,
pub updated_refs: Vec<UpdatedRef>,
#[serde(default)]
pub checks_imported: usize,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct PushOutcome {
pub mem: String,
pub remote: String,
pub branch_ref: String,
pub new_sha: String,
pub forced: bool,
#[serde(default)]
pub checks_published: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
pub struct PushAllOutcome {
pub remote: String,
pub pushed: Vec<PushedRef>,
pub in_sync: Vec<String>,
pub refused: Vec<RefusedRef>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct PushedRef {
pub ref_name: String,
pub mem: Option<String>,
pub previous_sha: String,
pub new_sha: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct RefusedRef {
pub ref_name: String,
pub mem: Option<String>,
pub code: String,
pub message: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct RemoteAddOutcome {
pub remote: String,
pub url: String,
pub updated: bool,
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum RemoteRefState {
InSync,
LocalAhead,
Behind,
Forked,
Unfetched,
MissingLocal,
UnmountedRemote,
NotOnRemote,
}
impl RemoteRefState {
pub fn as_wire(self) -> &'static str {
match self {
Self::InSync => "in_sync",
Self::LocalAhead => "local_ahead",
Self::Behind => "behind",
Self::Forked => "forked",
Self::Unfetched => "unfetched",
Self::MissingLocal => "missing_local",
Self::UnmountedRemote => "unmounted_remote",
Self::NotOnRemote => "not_on_remote",
}
}
pub fn is_stale(self) -> bool {
matches!(
self,
Self::Behind | Self::Forked | Self::Unfetched | Self::MissingLocal
)
}
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct RemoteRefStatus {
pub ref_name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub mem: Option<String>,
pub schemas_ref: bool,
pub state: RemoteRefState,
#[serde(skip_serializing_if = "Option::is_none")]
pub remote_sha: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub local_sha: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
pub struct RemoteStatusOutcome {
pub remote: String,
pub refs: Vec<RemoteRefStatus>,
pub notices: Vec<String>,
pub counts: std::collections::BTreeMap<String, usize>,
pub stale: bool,
}