class Dpl::Providers::GitPush

Public Instance Methods

deploy() click to toggle source
# File lib/dpl/providers/git_push.rb, line 93
def deploy
  git_clone
  copy_files
  return info :stop unless git_dirty?

  push
  pull_request if pull_request?
end
login() click to toggle source
# File lib/dpl/providers/git_push.rb, line 85
def login
  token? ? login_token : setup_deploy_key
end
prepare() click to toggle source
# File lib/dpl/providers/git_push.rb, line 89
def prepare
  Dir.chdir(work_dir)
end
pull_request() click to toggle source
# File lib/dpl/providers/git_push.rb, line 108
def pull_request
  pr_exists? ? info(:pr_exists) : create_pr
end
push() click to toggle source
# File lib/dpl/providers/git_push.rb, line 102
def push
  git_config
  git_commit
  git_push
end
setup() click to toggle source
# File lib/dpl/providers/git_push.rb, line 80
def setup
  info :setup
  info :git_config
end
validate() click to toggle source
# File lib/dpl/providers/git_push.rb, line 76
def validate
  error :same_branch if same_branch? && !allow_same_branch?
end

Private Instance Methods

api_url() click to toggle source
# File lib/dpl/providers/git_push.rb, line 265
def api_url
  enterprise? ? "https://#{host}/api/v3/" : 'https://api.github.com/'
end
branch_exists?() click to toggle source
# File lib/dpl/providers/git_push.rb, line 154
def branch_exists?
  git_ls_remote?(remote_url, branch)
end
clone_branch() click to toggle source
# File lib/dpl/providers/git_push.rb, line 141
def clone_branch
  branch_exists? ? branch : base_branch
end
copy_files() click to toggle source
# File lib/dpl/providers/git_push.rb, line 145
def copy_files
  shell :copy_files
end
create_pr() click to toggle source
# File lib/dpl/providers/git_push.rb, line 252
def create_pr
  pr = github.create_pull_request(repo, base_branch, branch, "Update #{base_branch}")
  info :pr_created, number: pr.number
end
email() click to toggle source
Calls superclass method
# File lib/dpl/providers/git_push.rb, line 190
def email
  str = super if email?
  str || user_email
end
git_clone() click to toggle source
# File lib/dpl/providers/git_push.rb, line 136
def git_clone
  shell :git_clone, echo: false
  shell :git_branch unless branch_exists?
end
git_commit() click to toggle source
# File lib/dpl/providers/git_push.rb, line 158
def git_commit
  shell :git_commit_hook, path: asset(:git, :detect_private_key).path, echo: false if deploy_key?
  shell :git_add
  shell :git_commit
  shell :git_show
end
git_commit_msg_opts() click to toggle source
# File lib/dpl/providers/git_push.rb, line 177
def git_commit_msg_opts
  msg = interpolate(commit_message, vars:)
  msg.split("\n").reject(&:empty?).map { |message| %(-m #{quote(message)}) }
end
git_commit_opts() click to toggle source
# File lib/dpl/providers/git_push.rb, line 173
def git_commit_opts
  ' --allow-empty' if allow_empty_commit?
end
git_config() click to toggle source
# File lib/dpl/providers/git_push.rb, line 149
def git_config
  shell :git_config_name, echo: false
  shell :git_config_email, echo: false
end
git_push() click to toggle source
# File lib/dpl/providers/git_push.rb, line 165
def git_push
  shell :git_push, echo: false
end
git_push_opts() click to toggle source
# File lib/dpl/providers/git_push.rb, line 169
def git_push_opts
  '--force' if force?
end
git_url() click to toggle source
# File lib/dpl/providers/git_push.rb, line 208
def git_url
  "git@#{host}:#{slug}.git"
end
github() click to toggle source
# File lib/dpl/providers/git_push.rb, line 261
def github
  @github ||= Octokit::Client.new(access_token: token, api_endpoint: api_url, auto_paginate: true)
end
github?() click to toggle source
# File lib/dpl/providers/git_push.rb, line 257
def github?
  host.include?('github') || enterprise?
end
https_url_with_token() click to toggle source
# File lib/dpl/providers/git_push.rb, line 204
def https_url_with_token
  "https://#{token}@#{url}"
end
login_token() click to toggle source
# File lib/dpl/providers/git_push.rb, line 118
def login_token
  return unless github?

  info :login, user.login
  error :insufficient_scopes unless sufficient_scopes?
rescue Octokit::Unauthorized => e
  error :invalid_token, e.message
end
name() click to toggle source
Calls superclass method
# File lib/dpl/providers/git_push.rb, line 182
def name
  str = super if name?
  str ||= user_name
  str = "#{str} (via Travis CI)" if ENV['TRAVIS'] && !name?
  str
end
now() click to toggle source
# File lib/dpl/providers/git_push.rb, line 269
def now
  Time.now
end
pr_exists?() click to toggle source
# File lib/dpl/providers/git_push.rb, line 248
def pr_exists?
  !!github.pulls(repo).detect { |pull| pull.head.ref == branch }
end
project_name() click to toggle source
Calls superclass method
# File lib/dpl/providers/git_push.rb, line 196
def project_name
  super || repo_slug
end
remote_url() click to toggle source
# File lib/dpl/providers/git_push.rb, line 200
def remote_url
  token? ? https_url_with_token : git_url
end
same_branch?() click to toggle source
# File lib/dpl/providers/git_push.rb, line 114
def same_branch?
  git_branch == branch
end
scopes() click to toggle source
# File lib/dpl/providers/git_push.rb, line 244
def scopes
  @scopes ||= github.scopes
end
setup_deploy_key() click to toggle source
# File lib/dpl/providers/git_push.rb, line 127
def setup_deploy_key
  path = '~/.dpl/deploy_key'
  info(:setup_deploy_key, path:)
  mv deploy_key, path
  chmod 0o600, path
  setup_git_ssh path
  shell :check_deploy_key, key: path
end
slug() click to toggle source
# File lib/dpl/providers/git_push.rb, line 216
def slug
  repo || repo_slug
end
src_dir() click to toggle source
# File lib/dpl/providers/git_push.rb, line 220
def src_dir
  @src_dir ||= expand(local_dir)
end
sufficient_scopes?() click to toggle source
# File lib/dpl/providers/git_push.rb, line 228
def sufficient_scopes?
  scopes.include?('public_repo') || scopes.include?('repo')
end
url() click to toggle source
# File lib/dpl/providers/git_push.rb, line 212
def url
  "#{host}/#{slug}.git"
end
user() click to toggle source
# File lib/dpl/providers/git_push.rb, line 232
def user
  @user ||= github.user
end
user_email() click to toggle source
# File lib/dpl/providers/git_push.rb, line 240
def user_email
  user.email
end
user_name() click to toggle source
# File lib/dpl/providers/git_push.rb, line 236
def user_name
  user.name || user.login
end
work_dir() click to toggle source
# File lib/dpl/providers/git_push.rb, line 224
def work_dir
  @work_dir ||= tmp_dir
end