diff options
author | Elvin Efendi <elvin.efendiyev@gmail.com> | 2015-12-13 18:54:44 -0500 |
---|---|---|
committer | Elvin Efendi <elvin.efendiyev@gmail.com> | 2015-12-13 18:54:44 -0500 |
commit | 82db9fdd9c135a445a4839e39b245a9965091219 (patch) | |
tree | 20d82b890b6d78a92ab2c321c54db2ca79a0da7a /lib/oxidized/hook | |
parent | a561109ce1495747df1e019575105e0caf2dcdb5 (diff) | |
parent | fa3b93c5046f23ebbb2e82ac4944357683f8c5d8 (diff) |
Merge pull request #12 from Shopify/github-auth-opts
let user configure which auth method to use
Diffstat (limited to 'lib/oxidized/hook')
-rw-r--r-- | lib/oxidized/hook/githubrepo.rb | 18 |
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 |