From 8c61bf35408c0b47eb79d2d9d135b5b479abfecb Mon Sep 17 00:00:00 2001 From: Elvin Efendi Date: Fri, 23 Oct 2015 15:18:58 -0400 Subject: a callback to push config changes to a remote repository --- lib/oxidized/hook/githubrepo.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 lib/oxidized/hook/githubrepo.rb (limited to 'lib') diff --git a/lib/oxidized/hook/githubrepo.rb b/lib/oxidized/hook/githubrepo.rb new file mode 100644 index 0000000..f2ffa2a --- /dev/null +++ b/lib/oxidized/hook/githubrepo.rb @@ -0,0 +1,16 @@ +class GithubRepo < Oxidized::Hook + def validate_cfg! + cfg.has_key?('remote_repo') or raise 'remote_repo is required' + end + + def run_hook(ctx) + credentials = Rugged::Credentials::SshKeyFromAgent.new(username: 'git') + repo = Rugged::Repository.new(Oxidized::CFG.output.git.repo) + log "Pushing local repository(#{repo.path})..." + remote = repo.remotes['origin'] || repo.remotes.create('origin', cfg.remote_repo) + log "to remote: #{remote.url}" + remote.push(['refs/heads/master'], credentials: credentials) + rescue Exception => e + log e.backtrace.join('\n') + end +end -- cgit v1.2.1 From c96c52ab7153ffd85906550544df627c6c80aac8 Mon Sep 17 00:00:00 2001 From: Elvin Efendi Date: Mon, 26 Oct 2015 12:48:48 -0400 Subject: raise more specific exception when required key is not present --- lib/oxidized/hook/githubrepo.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/oxidized/hook/githubrepo.rb b/lib/oxidized/hook/githubrepo.rb index f2ffa2a..efa536b 100644 --- a/lib/oxidized/hook/githubrepo.rb +++ b/lib/oxidized/hook/githubrepo.rb @@ -1,6 +1,6 @@ class GithubRepo < Oxidized::Hook def validate_cfg! - cfg.has_key?('remote_repo') or raise 'remote_repo is required' + cfg.has_key?('remote_repo') or raise KeyError, 'remote_repo is required' end def run_hook(ctx) -- cgit v1.2.1 From bd7d0b1660be8bd4a32828ea5ca83c16c1797045 Mon Sep 17 00:00:00 2001 From: Elvin Efendi Date: Mon, 26 Oct 2015 13:33:53 -0400 Subject: do not rescue general exception --- lib/oxidized/hook/githubrepo.rb | 2 -- 1 file changed, 2 deletions(-) (limited to 'lib') diff --git a/lib/oxidized/hook/githubrepo.rb b/lib/oxidized/hook/githubrepo.rb index efa536b..a17d6b9 100644 --- a/lib/oxidized/hook/githubrepo.rb +++ b/lib/oxidized/hook/githubrepo.rb @@ -10,7 +10,5 @@ class GithubRepo < Oxidized::Hook remote = repo.remotes['origin'] || repo.remotes.create('origin', cfg.remote_repo) log "to remote: #{remote.url}" remote.push(['refs/heads/master'], credentials: credentials) - rescue Exception => e - log e.backtrace.join('\n') end end -- cgit v1.2.1 From 817f33a2a1e8f78720f5e73a10ee45384e886ae9 Mon Sep 17 00:00:00 2001 From: Elvin Efendi Date: Fri, 13 Nov 2015 16:31:02 -0500 Subject: githubrepo hook spec --- lib/oxidized/hook/githubrepo.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/oxidized/hook/githubrepo.rb b/lib/oxidized/hook/githubrepo.rb index a17d6b9..85adaab 100644 --- a/lib/oxidized/hook/githubrepo.rb +++ b/lib/oxidized/hook/githubrepo.rb @@ -5,7 +5,7 @@ class GithubRepo < Oxidized::Hook def run_hook(ctx) credentials = Rugged::Credentials::SshKeyFromAgent.new(username: 'git') - repo = Rugged::Repository.new(Oxidized::CFG.output.git.repo) + repo = Rugged::Repository.new(Oxidized.config.output.git.repo) log "Pushing local repository(#{repo.path})..." remote = repo.remotes['origin'] || repo.remotes.create('origin', cfg.remote_repo) log "to remote: #{remote.url}" -- cgit v1.2.1