Skip to content

Commit

Permalink
implement todos and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ssddOnTop committed Nov 5, 2024
1 parent 057a5d3 commit c3e5005
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
2 changes: 1 addition & 1 deletion workspace/gh-workflow-gen/build.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
42 changes: 37 additions & 5 deletions workspace/gh-workflow/src/workflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,47 @@ impl Workflow {
}
}

impl<S: AsRef<str>, W: Apply<Workflow>> Apply<Workflow> for Vec<(S, W)> {
fn apply(self, workflow: Workflow) -> Workflow {
todo!()
impl Into<OneOrManyOrObject<String>> for &str {
fn into(self) -> OneOrManyOrObject<String> {
OneOrManyOrObject::Single(self.to_string())
}
}

impl Into<OneOrManyOrObject<String>> for Vec<&str> {
fn into(self) -> OneOrManyOrObject<String> {
OneOrManyOrObject::Multiple(self.into_iter().map(|s| s.to_string()).collect())
}
}

impl<V: Into<OneOrManyOrObject<String>>> Into<OneOrManyOrObject<String>> for Vec<(&str, V)> {
fn into(self) -> OneOrManyOrObject<String> {
let mut map = IndexMap::new();
for (key, value) in self {
map.insert(key.to_string(), value.into());
}
OneOrManyOrObject::KeyValue(map)
}
}

impl<S: AsRef<str>, W: Into<OneOrManyOrObject<String>>> Apply<Workflow> 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<Workflow> 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<Workflow> for &str {
fn apply(self, workflow: Workflow) -> Workflow {
let on = self.to_string();
Workflow { on: Some(OneOrManyOrObject::Single(on)), ..workflow }
}
}

Expand Down Expand Up @@ -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() }
}
Expand Down

0 comments on commit c3e5005

Please sign in to comment.