Move config to Runtime
This commit is contained in:
parent
2ef530b462
commit
9ed13f265d
2 changed files with 30 additions and 10 deletions
|
@ -29,7 +29,6 @@ pub struct CreateHook<'a> {
|
||||||
repository: Option<Repository>,
|
repository: Option<Repository>,
|
||||||
|
|
||||||
position: HookPosition,
|
position: HookPosition,
|
||||||
config: Option<Value>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> CreateHook<'a> {
|
impl<'a> CreateHook<'a> {
|
||||||
|
@ -46,7 +45,6 @@ impl<'a> CreateHook<'a> {
|
||||||
storepath: storepath,
|
storepath: storepath,
|
||||||
repository: r,
|
repository: r,
|
||||||
position: p,
|
position: p,
|
||||||
config: None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +72,7 @@ impl<'a> Debug for CreateHook<'a> {
|
||||||
self.storepath,
|
self.storepath,
|
||||||
(if self.repository.is_some() { "Some(_)" } else { "None" }),
|
(if self.repository.is_some() { "Some(_)" } else { "None" }),
|
||||||
self.position,
|
self.position,
|
||||||
self.config)
|
self.runtime.has_config())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +83,9 @@ impl<'a> Hook for CreateHook<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_config(&mut self, config: &Value) {
|
fn set_config(&mut self, config: &Value) {
|
||||||
self.config = Some(config.clone());
|
if let Err(e) = self.runtime.set_config(config) {
|
||||||
|
trace_error(&e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,8 @@ pub struct Runtime<'a> {
|
||||||
repository: Option<Repository>,
|
repository: Option<Repository>,
|
||||||
author: Option<Person<'a>>,
|
author: Option<Person<'a>>,
|
||||||
committer: Option<Person<'a>>,
|
committer: Option<Person<'a>>,
|
||||||
|
|
||||||
|
config: Option<Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Runtime<'a> {
|
impl<'a> Runtime<'a> {
|
||||||
|
@ -43,20 +45,38 @@ impl<'a> Runtime<'a> {
|
||||||
|
|
||||||
author: None,
|
author: None,
|
||||||
committer: None,
|
committer: None,
|
||||||
|
config: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn configure(&mut self, config: &Value) -> Result<()> {
|
pub fn set_config(&mut self, cfg: &Value) -> Result<()> {
|
||||||
author_name(cfg)
|
let config = cfg.clone();
|
||||||
.and_then(|n| author_mail(cfg).map(|m| Person::new(n, m)))
|
let res = author_name(&config)
|
||||||
|
.and_then(|n| author_mail(&config).map(|m| Person::new(n, m)))
|
||||||
.and_then(|author| {
|
.and_then(|author| {
|
||||||
committer_name(cfg)
|
committer_name(&config)
|
||||||
.and_then(|n| committer_mail(cfg).map(|m| (author, Person::new(n, m))))
|
.and_then(|n| committer_mail(&config).map(|m| (author, Person::new(n, m))))
|
||||||
})
|
})
|
||||||
.map(|(author, committer)| {
|
.map(|(author, committer)| {
|
||||||
self.author = Some(author);
|
self.author = Some(author);
|
||||||
self.committer = Some(committer);
|
self.committer = Some(committer);
|
||||||
})
|
});
|
||||||
|
self.config = Some(config);
|
||||||
|
res
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn has_config(&self) -> bool {
|
||||||
|
self.config.is_some()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn config_value_or_err(&self) -> HookResult<&Value> {
|
||||||
|
self.config
|
||||||
|
.as_ref()
|
||||||
|
.ok_or(GHEK::NoConfigError.into_error())
|
||||||
|
.map_err_into(GHEK::ConfigError)
|
||||||
|
.map_err(Box::new)
|
||||||
|
.map_err(|e| HEK::HookExecutionError.into_error_with_cause(e))
|
||||||
|
.map_err(|mut e| e.with_custom_data(CustomData::default().aborting(false)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_committer_sig(&self) -> Option<Result<Signature>> {
|
pub fn new_committer_sig(&self) -> Option<Result<Signature>> {
|
||||||
|
|
Loading…
Reference in a new issue