diff options
author | Wild Kat <wk@users.noreply.github.com> | 2018-05-26 23:49:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-26 23:49:29 +0200 |
commit | 39dbb74c527c054007e26ad34c8921d4be6cb638 (patch) | |
tree | d55745153153450fb40e1f591eb861495a6068d9 /lib/oxidized/hook/githubrepo.rb | |
parent | defdc69f92b3bcf62b1fd3b5ceac63a7a4e637ae (diff) | |
parent | 42bf10b7bce34ff577c469f6c2f659f3913cbf4a (diff) |
Merge branch 'master' into FortiOS-Push
Diffstat (limited to 'lib/oxidized/hook/githubrepo.rb')
-rw-r--r-- | lib/oxidized/hook/githubrepo.rb | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/lib/oxidized/hook/githubrepo.rb b/lib/oxidized/hook/githubrepo.rb index f74b22a..e077d5d 100644 --- a/lib/oxidized/hook/githubrepo.rb +++ b/lib/oxidized/hook/githubrepo.rb @@ -35,26 +35,32 @@ class GithubRepo < Oxidized::Hook end Rugged::Commit.create(repo, { - parents: [repo.head.target, their_branch.target], - tree: merge_index.write_tree(repo), - message: "Merge remote-tracking branch '#{their_branch.name}'", - update_ref: "HEAD" - }) + parents: [repo.head.target, their_branch.target], + tree: merge_index.write_tree(repo), + message: "Merge remote-tracking branch '#{their_branch.name}'", + 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 - if cfg.has_key?('publickey') && cfg.has_key?('privatekey') - log "Using ssh auth with key", :debug - Rugged::Credentials::SshKey.new(username: 'git', publickey: File.expand_path(cfg.publickey), privatekey: File.expand_path(cfg.privatekey), passphrase: ENV["OXIDIZED_SSH_PASSPHRASE"]) + Proc.new do |url, username_from_url, allowed_types| + if cfg.has_key?('username') + git_user = cfg.username + else + git_user = username_from_url ? username_from_url : 'git' + end + + if cfg.has_key?('password') + log "Authenticating using username and password as '#{git_user}'", :debug + Rugged::Credentials::UserPassword.new(username: git_user, password: cfg.password) + elsif cfg.has_key?('publickey') && cfg.has_key?('privatekey') + log "Authenticating using ssh keys as '#{git_user}'", :debug + Rugged::Credentials::SshKey.new(username: git_user, publickey: File.expand_path(cfg.publickey), privatekey: File.expand_path(cfg.privatekey), passphrase: ENV["OXIDIZED_SSH_PASSPHRASE"]) else - log "Using ssh auth with agentforwarding", :debug - Rugged::Credentials::SshKeyFromAgent.new(username: 'git') + log "Authenticating using ssh agent as '#{git_user}'", :debug + Rugged::Credentials::SshKeyFromAgent.new(username: git_user) end end end |