Skip to content
Snippets Groups Projects

io: support verifying all hook configuration blocks

2 files
+ 58
1
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 56
0
@@ -6,6 +6,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate itertools;
use self::itertools::Itertools;
extern crate serde;
use self::serde::{Deserialize, Deserializer};
use self::serde::Error as SerdeError;
@@ -14,6 +17,7 @@ extern crate serde_json;
use self::serde_json::Value;
use super::defaults;
use super::hooks;
use std::collections::hash_map::HashMap;
use std::error::Error;
@@ -202,4 +206,56 @@ impl Config {
pub fn archive_dir(&self) -> &Path {
Path::new(self.archive.as_ref().unwrap_or(&self.queue))
}
/// Verify all of the hook configuration blocks in the configuration file.
pub fn verify_all_hook_configs(self) -> Result<(), Box<Error>> {
// Check the hooks in each host.
self.hosts
.into_iter()
.map(|(_, host)| {
// And in each project.
host.projects
.into_iter()
.map(|(_, project)| {
// First get the project-wide hooks.
let project_hooks = project.hooks
.values()
.cloned()
.collect_vec();
project_hooks.into_iter()
// And merge them with the branch-specific hooks.
.chain(project.branches
.into_iter()
.map(|(_, branch)| {
branch.hooks
.into_iter()
.map(|(_, hook)| {
hook
})
})
.flatten())
})
.flatten()
})
.flatten()
// Split the hook configuration into an owned name and configuration block.
.map(|hook_config| {
(hook_config.name.clone(), hook_config.config)
})
// Parse each hook configuration section out.
.map(|(hook_name, config): (Option<String>, Value)| {
hook_name.map(|name| {
let mut hooks = Vec::new();
let mut branch_hook = Vec::new();
hooks::create_hook(&name, config, &mut hooks, &mut branch_hook)
})
})
// Skip any branch hooks which are deleting a project-level hook.
.filter_map(|x| x)
// Collect them up as results.
.collect::<Result<Vec<_>, _>>()
// And drop the actual hook results.
.map(|_| ())
}
}
Loading