diff options
author | Danilo Sousa <dsgoncalves@uoldiveo.com> | 2016-02-19 18:58:47 -0200 |
---|---|---|
committer | Danilo Sousa <dsgoncalves@uoldiveo.com> | 2016-02-19 18:58:47 -0200 |
commit | a486e086fc3b52f26ade94e58a16fa2150fc9cae (patch) | |
tree | 3d6bc37aa024a2a6f1afc9879bc595fe78b4e497 | |
parent | 70bbbb2ca879af28afb8d7b739e4379907fd426a (diff) |
move the groups remote to the hook config
thanks to @ElvinEfendi for the idea! :+1:
-rw-r--r-- | README.md | 15 | ||||
-rw-r--r-- | lib/oxidized/hook/githubrepo.rb | 2 | ||||
-rw-r--r-- | spec/githubrepo_spec.rb | 14 |
3 files changed, 19 insertions, 12 deletions
@@ -535,14 +535,15 @@ This hook configures the repository `remote` and _push_ the code when the specif * `username`: username for repository auth. * `password`: password for repository auth. -When using groups repositories, the remotes should be passed in the `groups` config for each group. +When using groups repositories, each group must have its own `remote` in the `remote_repo` config. ``` yaml -vars: {} -groups: - routers: git@git.intranet:oxidized/routers.git - switches: git@git.intranet:oxidized/switches.git - firewalls: git@git.intranet:oxidized/firewalls.git +hooks: + push_to_remote: + remote_repo: + routers: git@git.intranet:oxidized/routers.git + switches: git@git.intranet:oxidized/switches.git + firewalls: git@git.intranet:oxidized/firewalls.git ``` @@ -550,7 +551,7 @@ groups: ``` yaml hooks: - push_to_gitlab: + push_to_remote: type: githubrepo events: [node_success, post_store] remote_repo: git@git.intranet:oxidized/test.git diff --git a/lib/oxidized/hook/githubrepo.rb b/lib/oxidized/hook/githubrepo.rb index dd9520b..0c75c68 100644 --- a/lib/oxidized/hook/githubrepo.rb +++ b/lib/oxidized/hook/githubrepo.rb @@ -58,7 +58,7 @@ class GithubRepo < Oxidized::Hook if node.group.nil? || single_repo? cfg.remote_repo else - Oxidized.config.groups[node.group].remote_repo + cfg.remote_repo[node.group] end end diff --git a/spec/githubrepo_spec.rb b/spec/githubrepo_spec.rb index a5bbeca..8d85761 100644 --- a/spec/githubrepo_spec.rb +++ b/spec/githubrepo_spec.rb @@ -126,8 +126,6 @@ describe GithubRepo do before do Rugged::Credentials::SshKeyFromAgent.expects(:new).with(username: 'git').returns(credentials) Rugged::Repository.expects(:new).with(repository).returns(repo) - Oxidized.config.groups.ggrroouupp.remote_repo = 'ggrroouupp#remote_repo' - Oxidized.config.hooks.github_repo_hook.remote_repo = 'github_repo_hook#remote_repo' Oxidized.config.output.git.single_repo = single_repo repo.expects(:remotes).twice.returns(remotes) @@ -137,22 +135,30 @@ describe GithubRepo do remote.expects(:push).with(['refs/heads/master'], credentials: credentials).returns(true) end - describe 'when there are several repositories' do + describe 'and there are several repositories' do let(:create_remote) { 'ggrroouupp#remote_repo' } let(:repository) { './ggrroouupp.git' } let(:single_repo) { nil } + before do + Oxidized.config.hooks.github_repo_hook.remote_repo.ggrroouupp = 'ggrroouupp#remote_repo' + end + it 'will push to the node group repository' do gr.cfg = Oxidized.config.hooks.github_repo_hook gr.run_hook(ctx).must_equal true end end - describe 'when is a single repository' do + describe 'and has a single repository' do let(:create_remote) { 'github_repo_hook#remote_repo' } let(:repository) { 'foo.git' } let(:single_repo) { true } + before do + Oxidized.config.hooks.github_repo_hook.remote_repo = 'github_repo_hook#remote_repo' + end + it 'will push to the correct repository' do gr.cfg = Oxidized.config.hooks.github_repo_hook gr.run_hook(ctx).must_equal true |