summaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2012-08-25 18:19:28 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2012-08-25 18:19:28 +0100
commit885adb8211c0501813af5af62ab9b22f70df6a42 (patch)
tree1d062ba0ada1e3cb9ecd44c697e51d3d2af3da41 /example
parent2384d5d41ae38a8adce74e18b34f2d6b07819a56 (diff)
downloadgitano-885adb8211c0501813af5af62ab9b22f70df6a42.tar.gz
EXAMPLE: Global hook post-receive example for generic CIA.vc
Diffstat (limited to 'example')
-rw-r--r--example/global-hooks/cia-notify.post-receive.lua45
1 files changed, 45 insertions, 0 deletions
diff --git a/example/global-hooks/cia-notify.post-receive.lua b/example/global-hooks/cia-notify.post-receive.lua
new file mode 100644
index 0000000..18408ce
--- /dev/null
+++ b/example/global-hooks/cia-notify.post-receive.lua
@@ -0,0 +1,45 @@
+-- cia-notify.post-receive.lua
+--
+-- Example post-receive global hook which notifies cia.vc on ref updates
+-- which match any of the patterns provided by the project.
+--
+-- It notifies CIA.vc *before* passing the updates on to the project hook.
+--
+-- Copyright 2012 Daniel Silverstone <dsilvers@digital-scurf.org>
+--
+-- This is an example which is part of Gitano.
+--
+
+local project_hook, repo, updates = ...
+
+local empty = "0000000000000000000000000000000000000000"
+
+local cia_project = repo:get_config("cia.project")
+if cia_project then
+ local refpatterns = repo:get_config_list("cia.branches")
+ if not refpatterns or #refpatterns == 0 then
+ refpatterns = { ".*" }
+ end
+ for i = 1, #refpatterns do
+ refpatterns[i] = "^refs/heads/" .. refpatterns[i]
+ end
+ for ref, details in pairs(updates) do
+ if details.newsha ~= empty and details.oldsha ~= empty then
+ local refmatched = false
+ for i = 1, #refpatterns do
+ if ref:match(refpatterns[i]) then
+ refmatched = true
+ break
+ end
+ end
+ if refmatched then
+ log.chat("Informing CIA of commits on", ref:sub(12))
+ cia.inform_commits(cia_project, ref:sub(12), repo,
+ details.oldsha, details.newsha)
+ end
+ end
+ end
+end
+
+-- Finally, chain to the project hook
+return project_hook(repo, updates)