use serde::Serialize;
use crate::contract::schema::{Adapter, Ecosystem, Registry};
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct ReleasePlan {
pub plan_id: String,
pub contract_schema_version: u32,
pub head_sha: String,
pub version: String,
pub targets: Vec<PlanTarget>,
pub phases: Vec<PlanPhase>,
#[serde(skip_serializing_if = "Option::is_none")]
pub bump: Option<BumpPlan>,
pub homebrew_tap: Option<String>,
pub license: Option<String>,
pub description: Option<String>,
pub homebrew_platforms: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct PlanTarget {
pub ecosystem: Ecosystem,
pub package: Option<String>,
pub registry: Registry,
pub adapter: Adapter,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct BumpPlan {
pub level: BumpLevel,
pub from_version: String,
pub to_version: String,
pub pin_rewrites: Vec<PinRewrite>,
pub changelog_finalize: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub changelog: Option<ChangelogFinalizePlan>,
#[serde(skip_serializing_if = "Option::is_none")]
pub bump_hook: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct ChangelogFinalizePlan {
pub mode: crate::contract::schema::ChangelogMode,
pub source: crate::contract::schema::ChangelogSource,
pub fragment_dir: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub issuectl_range: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct PinRewrite {
pub in_package: String,
#[serde(default, skip_serializing_if = "is_false")]
pub workspace_root: bool,
pub dependency: String,
pub from: String,
pub to: String,
}
#[allow(clippy::trivially_copy_pass_by_ref)] fn is_false(value: &bool) -> bool {
!value
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum BumpLevel {
Major,
Minor,
Patch,
}
impl BumpLevel {
#[must_use]
pub fn as_str(self) -> &'static str {
match self {
Self::Major => "major",
Self::Minor => "minor",
Self::Patch => "patch",
}
}
#[must_use]
pub fn parse(s: &str) -> Option<Self> {
match s {
"major" => Some(Self::Major),
"minor" => Some(Self::Minor),
"patch" => Some(Self::Patch),
_ => None,
}
}
pub const VALID: &'static [&'static str] = &["major", "minor", "patch"];
}
impl serde::Serialize for BumpLevel {
fn serialize<S: serde::Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> {
ser.serialize_str(self.as_str())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PlanPhase {
Bump,
DryRunAll,
BuildAll,
PublishAll,
Tag,
Dist,
Verify,
AdvanceBranch,
}
impl From<crate::protocol::journal::Phase> for PlanPhase {
fn from(value: crate::protocol::journal::Phase) -> Self {
Self::from_coordinator(value)
}
}
impl PlanPhase {
#[must_use]
pub const fn from_coordinator(value: crate::protocol::journal::Phase) -> Self {
match value {
crate::protocol::journal::Phase::Bump => Self::Bump,
crate::protocol::journal::Phase::DryRun => Self::DryRunAll,
crate::protocol::journal::Phase::Build => Self::BuildAll,
crate::protocol::journal::Phase::Publish => Self::PublishAll,
crate::protocol::journal::Phase::Tag => Self::Tag,
crate::protocol::journal::Phase::Dist => Self::Dist,
crate::protocol::journal::Phase::Verify => Self::Verify,
crate::protocol::journal::Phase::AdvanceBranch => Self::AdvanceBranch,
}
}
#[must_use]
pub fn as_str(self) -> &'static str {
match self {
Self::Bump => "bump",
Self::DryRunAll => "dry-run-all",
Self::BuildAll => "build-all",
Self::PublishAll => "publish-all",
Self::Tag => "tag",
Self::Dist => "dist",
Self::Verify => "verify",
Self::AdvanceBranch => "advance-branch",
}
}
pub const SEQUENCE: [PlanPhase; crate::protocol::journal::Phase::CUT_SEQUENCE.len()] = [
Self::from_coordinator(crate::protocol::journal::Phase::CUT_SEQUENCE[0]),
Self::from_coordinator(crate::protocol::journal::Phase::CUT_SEQUENCE[1]),
Self::from_coordinator(crate::protocol::journal::Phase::CUT_SEQUENCE[2]),
Self::from_coordinator(crate::protocol::journal::Phase::CUT_SEQUENCE[3]),
Self::from_coordinator(crate::protocol::journal::Phase::CUT_SEQUENCE[4]),
Self::from_coordinator(crate::protocol::journal::Phase::CUT_SEQUENCE[5]),
Self::from_coordinator(crate::protocol::journal::Phase::CUT_SEQUENCE[6]),
];
#[must_use]
pub fn sequence() -> &'static [PlanPhase] {
&Self::SEQUENCE
}
}
impl serde::Serialize for PlanPhase {
fn serialize<S: serde::Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> {
ser.serialize_str(self.as_str())
}
}