summaryrefslogtreecommitdiff
path: root/lib/oxidized/hook
diff options
context:
space:
mode:
Diffstat (limited to 'lib/oxidized/hook')
-rw-r--r--lib/oxidized/hook/githubrepo.rb18
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/oxidized/hook/githubrepo.rb b/lib/oxidized/hook/githubrepo.rb
index 25b2cd0..22ee8ea 100644
--- a/lib/oxidized/hook/githubrepo.rb
+++ b/lib/oxidized/hook/githubrepo.rb
@@ -4,18 +4,17 @@ class GithubRepo < Oxidized::Hook
end
def run_hook(ctx)
- credentials = Rugged::Credentials::UserPassword.new(username: cfg.username, password: cfg.password)
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}"
- fetch_and_merge_remote(repo, credentials)
+ fetch_and_merge_remote(repo)
remote.push([repo.head.name], credentials: credentials)
end
- def fetch_and_merge_remote(repo, credentials)
+ def fetch_and_merge_remote(repo)
repo.fetch('origin', [repo.head.name], credentials: credentials)
their_branch = repo.branches["origin/master"] or return
@@ -31,4 +30,17 @@ class GithubRepo < Oxidized::Hook
update_ref: "HEAD"
})
end
+
+ private
+
+ def credentials
+ @credentials ||= if cfg.has_key?('username') && cfg.has_key?('password')
+ log "Using https auth", :debug
+ Rugged::Credentials::UserPassword.new(username: cfg.username, password: cfg.password)
+ else
+ log "Using ssh auth", :debug
+ Rugged::Credentials::SshKeyFromAgent.new(username: 'git')
+ end
+ end
+
end