use std::cmp::Ordering;
use mogh_resolver::Resolve;
use serde::{Deserialize, Serialize};
use typeshare::typeshare;
use crate::entities::{
I64, Version,
build::{Build, BuildActionState, BuildListItem, BuildQuery},
};
use super::KomodoReadRequest;
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/GetBuild",
description = "Get a specific build.",
request_body(content = GetBuild),
responses(
(status = 200, description = "The build", body = crate::entities::build::BuildSchema),
),
)]
pub fn get_build() {}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(GetBuildResponse)]
#[error(mogh_error::Error)]
pub struct GetBuild {
#[serde(alias = "id", alias = "name")]
pub build: String,
}
#[typeshare]
pub type GetBuildResponse = Build;
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/ListBuilds",
description = "List builds matching optional query.",
request_body(content = ListBuilds),
responses(
(status = 200, description = "The list of builds", body = ListBuildsResponse),
),
)]
pub fn list_builds() {}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Default, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(ListBuildsResponse)]
#[error(mogh_error::Error)]
pub struct ListBuilds {
#[serde(default)]
pub query: BuildQuery,
}
#[typeshare]
pub type ListBuildsResponse = Vec<BuildListItem>;
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/ListFullBuilds",
description = "List builds matching optional query.",
request_body(content = ListFullBuilds),
responses(
(status = 200, description = "The list of builds", body = ListFullBuildsResponse),
),
)]
pub fn list_full_builds() {}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Default, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(ListFullBuildsResponse)]
#[error(mogh_error::Error)]
pub struct ListFullBuilds {
#[serde(default)]
pub query: BuildQuery,
}
#[typeshare]
pub type ListFullBuildsResponse = Vec<Build>;
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/GetBuildActionState",
description = "Get current action state for the build.",
request_body(content = GetBuildActionState),
responses(
(status = 200, description = "The build action state", body = GetBuildActionStateResponse),
),
)]
pub fn get_build_action_state() {}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(GetBuildActionStateResponse)]
#[error(mogh_error::Error)]
pub struct GetBuildActionState {
#[serde(alias = "id", alias = "name")]
pub build: String,
}
#[typeshare]
pub type GetBuildActionStateResponse = BuildActionState;
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/GetBuildsSummary",
description = "Gets a summary of data relating to all builds.",
request_body(content = GetBuildsSummary),
responses(
(status = 200, description = "The builds summary", body = GetBuildsSummaryResponse),
),
)]
pub fn get_builds_summary() {}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(GetBuildsSummaryResponse)]
#[error(mogh_error::Error)]
pub struct GetBuildsSummary {}
#[typeshare]
#[derive(Serialize, Deserialize, Default, Debug, Clone)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct GetBuildsSummaryResponse {
pub total: u32,
pub ok: u32,
pub failed: u32,
pub building: u32,
pub unknown: u32,
}
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/GetBuildMonthlyStats",
description = "Gets summary and timeseries breakdown of the last months build count / time for charting.",
request_body(content = GetBuildMonthlyStats),
responses(
(status = 200, description = "The build monthly stats", body = GetBuildMonthlyStatsResponse),
),
)]
pub fn get_build_monthly_stats() {}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(GetBuildMonthlyStatsResponse)]
#[error(mogh_error::Error)]
pub struct GetBuildMonthlyStats {
#[serde(default)]
pub page: u32,
}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct GetBuildMonthlyStatsResponse {
pub total_time: f64, pub total_count: f64, pub days: Vec<BuildStatsDay>,
}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct BuildStatsDay {
pub time: f64,
pub count: f64,
pub ts: f64,
}
impl GetBuildMonthlyStatsResponse {
pub fn new(
mut days: Vec<BuildStatsDay>,
) -> GetBuildMonthlyStatsResponse {
days.sort_by(|a, b| {
if a.ts < b.ts {
Ordering::Less
} else {
Ordering::Greater
}
});
let mut total_time = 0.0;
let mut total_count = 0.0;
for day in &days {
total_time += day.time;
total_count += day.count;
}
GetBuildMonthlyStatsResponse {
total_time,
total_count,
days,
}
}
}
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/ListBuildVersions",
description = "Retrieve versions of the build that were built in the past and available for deployment, sorted by most recent first.",
request_body(content = ListBuildVersions),
responses(
(status = 200, description = "The list of build versions", body = ListBuildVersionsResponse),
),
)]
pub fn list_build_versions() {}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Default, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(ListBuildVersionsResponse)]
#[error(mogh_error::Error)]
pub struct ListBuildVersions {
#[serde(alias = "id", alias = "name")]
pub build: String,
pub major: Option<i32>,
pub minor: Option<i32>,
pub patch: Option<i32>,
pub limit: Option<I64>,
}
#[typeshare]
pub type ListBuildVersionsResponse = Vec<BuildVersionResponseItem>;
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct BuildVersionResponseItem {
pub version: Version,
pub ts: I64,
}
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/ListCommonBuildExtraArgs",
description = "Gets a list of existing values used as extra args across other builds.",
request_body(content = ListCommonBuildExtraArgs),
responses(
(status = 200, description = "The common extra args", body = ListCommonBuildExtraArgsResponse),
),
)]
pub fn list_common_build_extra_args() {}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(ListCommonBuildExtraArgsResponse)]
#[error(mogh_error::Error)]
pub struct ListCommonBuildExtraArgs {
#[serde(default)]
pub query: BuildQuery,
}
#[typeshare]
pub type ListCommonBuildExtraArgsResponse = Vec<String>;