Skip to main content

ephemeris_forge_github/operation/
variables.rs

1use std::fmt;
2
3use crate::api::request::VariableScope;
4
5/// One write to the repository's Actions variables.
6#[derive(Clone, Debug, Eq, PartialEq)]
7pub enum Operation {
8    /// Create the variable.
9    Create {
10        /// Where the variable lives.
11        scope: VariableScope,
12        /// The variable's name.
13        name: String,
14        /// The value to set.
15        value: String,
16    },
17    /// Change the value of the variable.
18    Update {
19        /// Where the variable lives.
20        scope: VariableScope,
21        /// The variable's name.
22        name: String,
23        /// The value to set.
24        value: String,
25    },
26    /// Delete the variable.
27    Delete {
28        /// Where the variable lives.
29        scope: VariableScope,
30        /// The variable's name.
31        name: String,
32    },
33}
34
35impl fmt::Display for Operation {
36    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37        let (Self::Create {
38            scope,
39            name,
40            value: _,
41        }
42        | Self::Update {
43            scope,
44            name,
45            value: _,
46        }
47        | Self::Delete { scope, name }) = self;
48        match scope {
49            VariableScope::Repository => write!(f, "variable {name}"),
50            VariableScope::Environment(environment) => {
51                write!(f, "environment {environment} variable {name}")
52            }
53        }
54    }
55}