diff options
Diffstat (limited to 'bin/gitano-post-receive-hook.in')
-rw-r--r-- | bin/gitano-post-receive-hook.in | 130 |
1 files changed, 71 insertions, 59 deletions
diff --git a/bin/gitano-post-receive-hook.in b/bin/gitano-post-receive-hook.in index ad77da2..cb77e06 100644 --- a/bin/gitano-post-receive-hook.in +++ b/bin/gitano-post-receive-hook.in @@ -141,71 +141,83 @@ local function report_repo(reponame, repo, msg) end end -if repo.name == "gitano-admin" and updates[admin_repo.HEAD] then - -- Updating the 'master' of gitano-admin, let's iterate all the repositories - - gitano.log.syslog.info("Updating gitano-admin") - - local msg = gitano.i18n.expand("SCANNING_FOR_UPDATES") - gitano.log.chat(msg) - gitano.log.syslog.info(msg) - - local ok, msg = gitano.repository.foreach(config, report_repo) - if not ok then - gitano.log.crit(msg) +function post_receive_core_handler(repo, updates) + if repo.name == "gitano-admin" and updates[admin_repo.HEAD] then + -- Updating the 'master' of gitano-admin, let's iterate all the repositories + + gitano.log.syslog.info("Updating gitano-admin") + + local msg = gitano.i18n.expand("SCANNING_FOR_UPDATES") + gitano.log.chat(msg) + gitano.log.syslog.info(msg) + + local ok, msg = gitano.repository.foreach(config, report_repo) + if not ok then + gitano.log.crit(msg) + end + + msg = gitano.i18n.expand("ALL_UPDATES_DONE") + gitano.log.chat(msg) + gitano.log.syslog.info(msg) + + local proc = sp.spawn({ + gitano.config.lib_bin_path() .. "/gitano-update-ssh", + gitano.config.repo_path() + }) + local how, why = proc:wait() + if how ~= "exit" or why ~= 0 then + gitano.log.crit(gitano.i18n.expand("ERROR_UPDATE_SSH_NOT_WORK")) + end + elseif repo.name ~= "gitano-admin" then + -- Not gitano-admin at all, so run the update-server-info stuff + gitano.log.info(gitano.i18n.expand("UPDATE_HTTP_INFO")) + local ok, err = repo.git:update_server_info() + if not ok then + gitano.log.warn(err) + end + gitano.log.info(gitano.i18n.expand("UPDATE_LASTMOD_DATE")) + local shas = {} + for _, t in pairs(updates) do + shas[#shas+1] = t.newsha + end + local ok, err = repo:update_modified_date(shas) + if not ok then + gitano.log.warn(err) + end end + return "continue" +end - msg = gitano.i18n.expand("ALL_UPDATES_DONE") - gitano.log.chat(msg) - gitano.log.syslog.info(msg) - - local proc = sp.spawn({ - gitano.config.lib_bin_path() .. "/gitano-update-ssh", - gitano.config.repo_path() - }) - local how, why = proc:wait() - if how ~= "exit" or why ~= 0 then - gitano.log.crit(gitano.i18n.expand("ERROR_UPDATE_SSH_NOT_WORK")) - end -elseif repo.name ~= "gitano-admin" then - -- Not gitano-admin at all, so run the update-server-info stuff - gitano.log.info(gitano.i18n.expand("UPDATE_HTTP_INFO")) - local ok, err = repo.git:update_server_info() - if not ok then - gitano.log.warn(err) - end - gitano.log.info(gitano.i18n.expand("UPDATE_LASTMOD_DATE")) - local shas = {} - for _, t in pairs(updates) do - shas[#shas+1] = t.newsha - end - local ok, err = repo:update_modified_date(shas) - if not ok then - gitano.log.warn(err) +function post_receive_run_supple(repo, updates) + if repo:uses_hook("post-receive") then + gitano.log.debug("Configuring for post-receive hook") + gitano.actions.set_supple_globals("post-receive") + + local msg = gitano.i18n.expand("RUNNING_POST_RECEIVE_HOOK") + gitano.log.info(msg) + gitano.log.syslog.info(msg) + + local info = { + username = username, + keytag = keytag, + source = source, + realname = (config.users[username] or {}).real_name or "", + email = (config.users[username] or {}).email_address or "", + } + local ok, msg = gitano.supple.run_hook("post-receive", repo, info, updates) + if not ok then + gitano.log.crit(msg or gitano.i18n.expand("ERROR_NO_ERROR_FOUND")) + end + gitano.log.info(gitano.i18n.expand("FINISHED")) end + return "continue" end -if repo:uses_hook("post-receive") then - gitano.log.debug("Configuring for post-receive hook") - gitano.actions.set_supple_globals("post-receive") +gitano.hooks.add(gitano.hooks.names.POST_RECEIVE, -1000, + post_receive_core_handler) +gitano.hooks.add(gitano.hooks.names.POST_RECEIVE, 0, post_receive_run_supple) - local msg = gitano.i18n.expand("RUNNING_POST_RECEIVE_HOOK") - gitano.log.info(msg) - gitano.log.syslog.info(msg) - - local info = { - username = username, - keytag = keytag, - source = source, - realname = (config.users[username] or {}).real_name or "", - email = (config.users[username] or {}).email_address or "", - } - local ok, msg = gitano.supple.run_hook("post-receive", repo, info, updates) - if not ok then - gitano.log.crit(msg or gitano.i18n.expand("ERROR_NO_ERROR_FOUND")) - end - gitano.log.info(gitano.i18n.expand("FINISHED")) -end +gitano.hooks.run(gitano.hooks.names.POST_RECEIVE, repo, updates) gitano.log.syslog.close() |