Add the necessary serde mappings for the urci.yml format as it stands now
This commit is contained in:
parent
a70b49560e
commit
90f8018d7c
|
@ -4,13 +4,14 @@
|
||||||
*/
|
*/
|
||||||
use serde::de::{Deserialize, Deserializer};
|
use serde::de::{Deserialize, Deserializer};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub projects: Vec<Project>,
|
pub projects: Vec<Project>,
|
||||||
pub agents: Vec<Agent>,
|
pub agents: Vec<Agent>,
|
||||||
pub handlers: Vec<Handler>,
|
pub handlers: HashMap<String, Handler>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
|
@ -48,11 +49,26 @@ pub struct Scm {
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct Agent {}
|
pub enum AgentType {
|
||||||
|
Local,
|
||||||
|
Ssh,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct Handler {}
|
pub struct Agent {
|
||||||
|
name: String,
|
||||||
|
description: String,
|
||||||
|
r#type: AgentType,
|
||||||
|
params: Option<HashMap<String, String>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct Handler {
|
||||||
|
filename: String,
|
||||||
|
defaults: Option<HashMap<String, String>>,
|
||||||
|
}
|
||||||
|
|
||||||
fn deserialize_cron_schedule<'de, D>(deserializer: D) -> Result<Option<cron::Schedule>, D::Error>
|
fn deserialize_cron_schedule<'de, D>(deserializer: D) -> Result<Option<cron::Schedule>, D::Error>
|
||||||
where
|
where
|
||||||
|
@ -70,8 +86,19 @@ where
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::Read;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_deserialize_example_config() {
|
||||||
|
let mut f = File::open("urci.yml").unwrap();
|
||||||
|
let mut yaml = String::new();
|
||||||
|
f.read_to_string(&mut yaml).expect("Failed to read into string");
|
||||||
|
let _config: Config = serde_yaml::from_str(&yaml).expect("Failed to parse the yaml");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cron_deserialize() {
|
fn test_cron_deserialize() {
|
||||||
let trigger_yaml = r#"---
|
let trigger_yaml = r#"---
|
||||||
|
|
2
urci.yml
2
urci.yml
|
@ -5,7 +5,7 @@
|
||||||
projects:
|
projects:
|
||||||
- name: hotdog
|
- name: hotdog
|
||||||
trigger:
|
trigger:
|
||||||
cron: '*/10 * * * *'
|
cron: '10 * * * * *'
|
||||||
# The different types of handlers should be documented elsewhere. In this
|
# The different types of handlers should be documented elsewhere. In this
|
||||||
# case, the project is expected to use a simple .travis-ci.yml
|
# case, the project is expected to use a simple .travis-ci.yml
|
||||||
handler: travis-ci
|
handler: travis-ci
|
||||||
|
|
Loading…
Reference in New Issue