Implement CreateHook::access()
This commit is contained in:
parent
989c1790be
commit
6714f4e3c7
1 changed files with 62 additions and 6 deletions
|
@ -78,19 +78,75 @@ impl<'a> HookDataAccessorProvider for CreateHook<'a> {
|
|||
impl<'a> StoreIdAccessor for CreateHook<'a> {
|
||||
|
||||
fn access(&self, id: &StoreId) -> HookResult<()> {
|
||||
use vcs::git::action::StoreAction;
|
||||
use vcs::git::config::commit_message;
|
||||
|
||||
debug!("[GIT CREATE HOOK]: {:?}", id);
|
||||
try!(self
|
||||
.runtime
|
||||
.ensure_cfg_branch_is_checked_out()
|
||||
.map_err(Box::new)
|
||||
.map_err(|e| HEK::HookExecutionError.into_error_with_cause(e)));
|
||||
let repository = try!(self.runtime.repository());
|
||||
|
||||
// Now to the create() hook action
|
||||
|
||||
unimplemented!()
|
||||
|
||||
Ok(())
|
||||
self.runtime
|
||||
.config_value_or_err()
|
||||
.and_then(|cfg| {
|
||||
self.runtime
|
||||
.repository()
|
||||
.map(|r| (r, cfg))
|
||||
.map_err_into(GHEK::RepositoryError)
|
||||
.map_err(|e| e.into())
|
||||
})
|
||||
.and_then(|(repo, cfg)| {
|
||||
repo.signature()
|
||||
.map(|s| (repo, cfg, s))
|
||||
.map_err_into(GHEK::RepositorySignatureFetchingError)
|
||||
.map_err_into(GHEK::RepositoryError)
|
||||
.map_err(|e| e.into())
|
||||
})
|
||||
.and_then(|(repo, cfg, sig)| {
|
||||
repo.index()
|
||||
.map(|idx| (repo, cfg, sig, idx))
|
||||
.map_err_into(GHEK::RepositoryIndexFetchingError)
|
||||
.map_err_into(GHEK::RepositoryError)
|
||||
.map_err(|e| e.into())
|
||||
})
|
||||
.and_then(|(repo, cfg, sig, mut idx)| {
|
||||
idx.add_path(id)
|
||||
.map(|_| (repo, cfg, sig, idx))
|
||||
.map_err_into(GHEK::RepositoryPathAddingError)
|
||||
.map_err_into(GHEK::RepositoryError)
|
||||
.map_err(|e| e.into())
|
||||
})
|
||||
.and_then(|(repo, cfg, sig, mut idx)| {
|
||||
idx.write_tree()
|
||||
.map(|oid| (repo, cfg, sig, idx, oid))
|
||||
.map_err_into(GHEK::RepositoryTreeWritingError)
|
||||
.map_err_into(GHEK::RepositoryError)
|
||||
.map_err(|e| e.into())
|
||||
})
|
||||
.and_then(|(repo, cfg, sig, idx, oid)| {
|
||||
repo.find_tree(oid)
|
||||
.map(|tree| (repo, cfg, sig, idx, oid, tree))
|
||||
.map_err_into(GHEK::RepositoryTreeFindingError)
|
||||
.map_err_into(GHEK::RepositoryError)
|
||||
.map_err(|e| e.into())
|
||||
})
|
||||
.and_then(|(repo, cfg, sig, idx, oid, tree)| {
|
||||
let cmtmsg = commit_message(cfg, StoreAction::Create);
|
||||
repo.find_commit(oid)
|
||||
.map(|cmt| (repo, sig, tree, cmt, cmtmsg))
|
||||
.map_err_into(GHEK::RepositoryCommitFindingError)
|
||||
.map_err_into(GHEK::RepositoryError)
|
||||
.map_err(|e| e.into())
|
||||
})
|
||||
.and_then(|(repo, sig, tree, cmt, commitmsg)| {
|
||||
repo.commit(Some("HEAD"), &sig, &sig, &commitmsg[..], &tree, &[&cmt])
|
||||
.map_err_into(GHEK::RepositoryCommittingError)
|
||||
.map_err_into(GHEK::RepositoryError)
|
||||
.map_err(|e| e.into())
|
||||
})
|
||||
.map(|_| ())
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue