Skip to main content

ephemeris_forge_github/operation/
environments.rs

1use std::fmt;
2
3use crate::BranchPolicy;
4use crate::api::request::EnvironmentBody;
5
6/// One write to the repository's deployment environments.
7#[derive(Clone, Debug, Eq, PartialEq)]
8pub enum Operation {
9    /// Create the environment or replace its settings.
10    Put {
11        /// The environment's name.
12        name: String,
13        /// The complete settings.
14        body: EnvironmentBody,
15    },
16    /// Delete the environment.
17    Delete {
18        /// The environment's name.
19        name: String,
20    },
21    /// Add a branch policy to the environment.
22    CreateBranchPolicy {
23        /// The environment's name.
24        environment: String,
25        /// The policy to add.
26        policy: BranchPolicy,
27    },
28    /// Remove a branch policy from the environment.
29    DeleteBranchPolicy {
30        /// The environment's name.
31        environment: String,
32        /// The id GitHub gave the policy.
33        id: u64,
34        /// The policy's name pattern.
35        name: String,
36    },
37}
38
39impl fmt::Display for Operation {
40    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41        match self {
42            Self::Put { name, body: _ } | Self::Delete { name } => {
43                write!(f, "environment {name}")
44            }
45            Self::CreateBranchPolicy {
46                environment,
47                policy,
48            } => write!(f, "environment {environment} branch policy {}", policy.name),
49            Self::DeleteBranchPolicy {
50                environment,
51                id: _,
52                name,
53            } => write!(f, "environment {environment} branch policy {name}"),
54        }
55    }
56}