use async_trait::async_trait;
use governor_core::domain::changelog::Changelog;
use governor_core::domain::version::SemanticVersion;
use governor_owners::{PackageOwnersConfig, WorkspaceOwnersConfig};
use serde::{Deserialize, Serialize};
use std::path::{Path, PathBuf};
use crate::error::ApplicationResult;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReleaseWorkspace {
pub root: PathBuf,
pub name: String,
pub current_version: SemanticVersion,
pub packages: Vec<ReleasePackage>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReleasePackage {
pub name: String,
pub version: SemanticVersion,
pub manifest_path: PathBuf,
pub dependencies: Vec<String>,
pub publish: bool,
}
#[derive(Debug, Clone)]
pub struct OwnersWorkspace {
pub root: PathBuf,
pub workspace: Option<WorkspaceOwnersConfig>,
pub packages: Vec<OwnerPackage>,
}
#[derive(Debug, Clone)]
pub struct OwnerPackage {
pub name: String,
pub owners: Option<PackageOwnersConfig>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VersionUpdate {
pub modified_files: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ChangelogUpdate {
pub updated: bool,
pub modified_files: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CommandReport {
pub name: String,
pub success: bool,
pub exit_code: Option<i32>,
pub stdout: String,
pub stderr: String,
}
#[async_trait]
pub trait WorkspacePort: Send + Sync {
fn name(&self) -> &str;
async fn load_release_workspace(
&self,
workspace_path: &Path,
) -> ApplicationResult<ReleaseWorkspace>;
async fn load_owners_workspace(
&self,
workspace_path: &Path,
) -> ApplicationResult<OwnersWorkspace>;
async fn update_workspace_version(
&self,
workspace_path: &Path,
version: &SemanticVersion,
dry_run: bool,
) -> ApplicationResult<VersionUpdate>;
async fn update_changelog(
&self,
workspace_path: &Path,
changelog: &Changelog,
dry_run: bool,
) -> ApplicationResult<ChangelogUpdate>;
}
#[async_trait]
pub trait CommandPort: Send + Sync {
fn name(&self) -> &str;
async fn run_check(
&self,
workspace_path: &Path,
check: &str,
capture_output: bool,
) -> ApplicationResult<CommandReport>;
}