summaryrefslogtreecommitdiff
path: root/lib/oxidized
diff options
context:
space:
mode:
authorElvin Efendi <elvin.efendiev@shopify.com>2015-12-09 22:53:16 -0500
committerElvin Efendi <elvin.efendiev@shopify.com>2015-12-13 18:54:10 -0500
commitfa3b93c5046f23ebbb2e82ac4944357683f8c5d8 (patch)
tree20d82b890b6d78a92ab2c321c54db2ca79a0da7a /lib/oxidized
parenta561109ce1495747df1e019575105e0caf2dcdb5 (diff)
let user configure which auth method to use
Diffstat (limited to 'lib/oxidized')
-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