summaryrefslogtreecommitdiff
path: root/lib/oxidized
diff options
context:
space:
mode:
authorytti <saku@ytti.fi>2016-02-23 00:31:55 +0200
committerytti <saku@ytti.fi>2016-02-23 00:31:55 +0200
commit1d6be9c011a9195626f59d3d62ac2febe9dd3149 (patch)
tree01eb7f3d336aaeb90347510afb32715bd7c042bc /lib/oxidized
parent2543d95d150844eb6e619f6c99dd26fc9b1d1084 (diff)
parent69210c7ddf7d77cc9eb7b78f0bc00ad2f1475955 (diff)
Merge pull request #326 from danilopopeye/group-remotes-and-hooks
multiple remotes for groups in GithubRepo hook
Diffstat (limited to 'lib/oxidized')
-rw-r--r--lib/oxidized/hook/githubrepo.rb13
-rw-r--r--lib/oxidized/node.rb12
2 files changed, 21 insertions, 4 deletions
diff --git a/lib/oxidized/hook/githubrepo.rb b/lib/oxidized/hook/githubrepo.rb
index d10b51e..7fc6677 100644
--- a/lib/oxidized/hook/githubrepo.rb
+++ b/lib/oxidized/hook/githubrepo.rb
@@ -1,12 +1,12 @@
class GithubRepo < Oxidized::Hook
def validate_cfg!
- cfg.has_key?('remote_repo') or raise KeyError, 'remote_repo is required'
+ raise KeyError, 'hook.remote_repo is required' unless cfg.has_key?('remote_repo')
end
def run_hook(ctx)
- repo = Rugged::Repository.new(Oxidized.config.output.git.repo)
+ repo = Rugged::Repository.new(ctx.node.repo)
log "Pushing local repository(#{repo.path})..."
- remote = repo.remotes['origin'] || repo.remotes.create('origin', cfg.remote_repo)
+ remote = repo.remotes['origin'] || repo.remotes.create('origin', remote_repo(ctx.node))
log "to remote: #{remote.url}"
fetch_and_merge_remote(repo)
@@ -54,4 +54,11 @@ class GithubRepo < Oxidized::Hook
end
end
+ def remote_repo(node)
+ if node.group.nil? || cfg.remote_repo.is_a?(String)
+ cfg.remote_repo
+ else
+ cfg.remote_repo[node.group]
+ end
+ end
end
diff --git a/lib/oxidized/node.rb b/lib/oxidized/node.rb
index 7a278a9..35bcad9 100644
--- a/lib/oxidized/node.rb
+++ b/lib/oxidized/node.rb
@@ -24,7 +24,7 @@ module Oxidized
@vars = opt[:vars]
@stats = Stats.new
@retry = 0
- @repo = Oxidized.config.output.git.repo
+ @repo = resolve_repo
# model instance needs to access node instance
@model.node = self
@@ -170,5 +170,15 @@ module Oxidized
Oxidized.mgr.model[model].new
end
+ def resolve_repo
+ remote_repo = Oxidized.config.output.git.repo
+
+ if Oxidized.config.output.git.single_repo? || @group.nil? || remote_repo.is_a?(String)
+ remote_repo
+ else
+ remote_repo[@group]
+ end
+ end
+
end
end