use super::{Attendance, Basis, Runs};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[non_exhaustive]
pub enum ExecProfile {
#[default]
Session,
Strict,
Unattended,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[non_exhaustive]
pub struct Obligations {
pub scan_nested_repos: bool,
}
impl Obligations {
pub fn scanning_nested_repos(yes: bool) -> Self {
Self {
scan_nested_repos: yes,
}
}
pub fn after(runs: Option<Runs>, profile: ExecProfile) -> Self {
Self::scanning_nested_repos(runs.is_some() && profile != ExecProfile::Strict)
}
}
impl ExecProfile {
pub fn for_permit(basis: &Basis, runs: Option<Runs>, attendance: Attendance) -> Self {
match (basis, runs) {
(Basis::Contained | Basis::AcceptEdits, Some(_)) => Self::Strict,
(Basis::UnattendedConfined, _) => Self::Unattended,
_ if attendance == Attendance::Unattended => Self::Unattended,
_ => Self::Session,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct Approval {
pub basis: Basis,
pub profile: ExecProfile,
pub landing: Option<std::path::PathBuf>,
}
impl Approval {
pub fn new(basis: Basis, profile: ExecProfile) -> Self {
Self {
basis,
profile,
landing: None,
}
}
pub fn landing_at(mut self, landing: Option<std::path::PathBuf>) -> Self {
self.landing = landing;
self
}
}