summaryrefslogtreecommitdiff
path: root/lib/oxidized
diff options
context:
space:
mode:
authorElvin Efendi <elvin.efendiev@shopify.com>2015-10-23 15:18:58 -0400
committerElvin Efendi <elvin.efendiev@shopify.com>2015-11-13 15:48:14 -0500
commit8c61bf35408c0b47eb79d2d9d135b5b479abfecb (patch)
tree166945c67340c4be35cf55aa46a0ff2e36a8f256 /lib/oxidized
parent5a2364e50620b825d5325bfbbc5d0f3d8578e25f (diff)
a callback to push config changes to a remote repository
Diffstat (limited to 'lib/oxidized')
-rw-r--r--lib/oxidized/hook/githubrepo.rb16
1 files changed, 16 insertions, 0 deletions
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