diff --git a/workspace/gh-workflow-gen/build.rs b/workspace/gh-workflow-gen/build.rs index 6427453..284eff6 100644 --- a/workspace/gh-workflow-gen/build.rs +++ b/workspace/gh-workflow-gen/build.rs @@ -1,6 +1,6 @@ use std::time::Duration; -use gh_workflow::{Job, PermissionLevel, Permissions, Step}; +use gh_workflow::{Job, Permissions, Step}; fn main() { // TODO: replace `with` with RustToolchain struct. diff --git a/workspace/gh-workflow/src/workflow.rs b/workspace/gh-workflow/src/workflow.rs index 4f4b6ea..f0ed002 100644 --- a/workspace/gh-workflow/src/workflow.rs +++ b/workspace/gh-workflow/src/workflow.rs @@ -135,15 +135,47 @@ impl Workflow { } } -impl, W: Apply> Apply for Vec<(S, W)> { - fn apply(self, workflow: Workflow) -> Workflow { - todo!() +impl Into> for &str { + fn into(self) -> OneOrManyOrObject { + OneOrManyOrObject::Single(self.to_string()) + } +} + +impl Into> for Vec<&str> { + fn into(self) -> OneOrManyOrObject { + OneOrManyOrObject::Multiple(self.into_iter().map(|s| s.to_string()).collect()) + } +} + +impl>> Into> for Vec<(&str, V)> { + fn into(self) -> OneOrManyOrObject { + let mut map = IndexMap::new(); + for (key, value) in self { + map.insert(key.to_string(), value.into()); + } + OneOrManyOrObject::KeyValue(map) + } +} + +impl, W: Into>> Apply for Vec<(S, W)> { + fn apply(self, mut workflow: Workflow) -> Workflow { + let val = self.into_iter().map(|(s, w)| (s.as_ref().to_string(), w.into())).collect(); + workflow.on = Some(OneOrManyOrObject::KeyValue(val)); + workflow } } impl Apply for Vec<&str> { fn apply(self, workflow: Workflow) -> Workflow { - todo!() + let on = self.into_iter().map(|s| s.to_string()).collect(); + Workflow { on: Some(OneOrManyOrObject::Multiple(on)), ..workflow } + } +} + +impl Apply for &str { + fn apply(self, workflow: Workflow) -> Workflow { + let on = self.to_string(); + Workflow { on: Some(OneOrManyOrObject::Single(on)), ..workflow } } } @@ -448,7 +480,7 @@ impl Permissions { pub fn read() -> Self { Self { contents: Some(PermissionLevel::Read), ..Default::default() } } - + pub fn write() -> Self { Self { contents: Some(PermissionLevel::Write), ..Default::default() } }