class Dpl::Providers::Pages::Git

Public Instance Methods

deploy() click to toggle source
# File lib/dpl/providers/pages/git.rb, line 99
def deploy
  git_clone? ? git_clone : git_init
  copy_files
  return info :stop if git_clone? && !git_dirty?

  git_config
  git_commit
  git_push
  git_status if verbose?
end
login() click to toggle source
# File lib/dpl/providers/pages/git.rb, line 82
def login
  token? ? login_token : setup_deploy_key
end
prepare() click to toggle source
# File lib/dpl/providers/pages/git.rb, line 92
def prepare
  info :deploy
  info :keep_history if keep_history?
  debug :work_dir
  Dir.chdir(work_dir)
end
setup() click to toggle source
# File lib/dpl/providers/pages/git.rb, line 86
def setup
  info :setup_dir, src_dir
  info :committer_from_gh if committer_from_gh?
  info :git_config
end

Private Instance Methods

api() click to toggle source
# File lib/dpl/providers/pages/git.rb, line 245
def api
  @api ||= Octokit::Client.new(access_token: token, api_endpoint:)
end
api_endpoint() click to toggle source
# File lib/dpl/providers/pages/git.rb, line 249
def api_endpoint
  opts[:url] == 'github.com' ? 'https://api.github.com/' : "https://#{opts[:url]}/api/v3/"
end
copy_files() click to toggle source
# File lib/dpl/providers/pages/git.rb, line 142
def copy_files
  shell :copy_files
end
debug(*args) click to toggle source
# File lib/dpl/providers/pages/git.rb, line 257
def debug(*args)
  info(*args) if verbose?
end
email() click to toggle source
Calls superclass method
# File lib/dpl/providers/pages/git.rb, line 195
def email
  str = super if email?
  str ||= user.email if committer_from_gh?
  str || git_author_email
end
git_branch_exists?() click to toggle source
# File lib/dpl/providers/pages/git.rb, line 169
def git_branch_exists?
  git_ls_remote?(remote_url, target_branch)
end
git_clone() click to toggle source
# File lib/dpl/providers/pages/git.rb, line 133
def git_clone
  shell :git_clone, echo: false
end
git_clone?() click to toggle source
# File lib/dpl/providers/pages/git.rb, line 129
def git_clone?
  keep_history? && git_branch_exists?
end
git_commit() click to toggle source
# File lib/dpl/providers/pages/git.rb, line 151
def git_commit
  info :prepare
  shell :git_commit_hook, path: asset(:git, :detect_private_key).path, echo: false if deploy_key?
  shell :deployment_file if deployment_file?
  shell :cname if fqdn?
  shell :git_add
  shell :git_commit
  shell :git_show
end
git_commit_msg_opts() click to toggle source
# File lib/dpl/providers/pages/git.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/pages/git.rb, line 173
def git_commit_opts
  ' --allow-empty' if allow_empty_commit?
end
git_config() click to toggle source
# File lib/dpl/providers/pages/git.rb, line 146
def git_config
  shell :git_config_name, echo: false
  shell :git_config_email, echo: false
end
git_init() click to toggle source
# File lib/dpl/providers/pages/git.rb, line 137
def git_init
  shell :git_init
  shell :git_checkout
end
git_push() click to toggle source
# File lib/dpl/providers/pages/git.rb, line 161
def git_push
  shell :git_push, echo: false
end
git_push_opts() click to toggle source
# File lib/dpl/providers/pages/git.rb, line 182
def git_push_opts
  ' --force' unless keep_history?
end
git_status() click to toggle source
# File lib/dpl/providers/pages/git.rb, line 165
def git_status
  shell 'git status'
end
git_url() click to toggle source
# File lib/dpl/providers/pages/git.rb, line 218
def git_url
  "git@#{opts[:url]}:#{slug}.git"
end
https_url_with_token() click to toggle source
# File lib/dpl/providers/pages/git.rb, line 214
def https_url_with_token
  "https://#{token}@#{url}"
end
login_token() click to toggle source
# File lib/dpl/providers/pages/git.rb, line 112
def login_token
  user.login
  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/pages/git.rb, line 186
def name
  str = super if name?
  str ||= user.name if committer_from_gh?
  str ||= git_author_name
  str = "#{str} (via Travis CI)" if ENV['TRAVIS'] && !name?
  str
end
now() click to toggle source
# File lib/dpl/providers/pages/git.rb, line 253
def now
  Time.now
end
project_name() click to toggle source
Calls superclass method
# File lib/dpl/providers/pages/git.rb, line 202
def project_name
  super || fqdn || repo_slug
end
remote_url() click to toggle source
# File lib/dpl/providers/pages/git.rb, line 210
def remote_url
  token? ? https_url_with_token : git_url
end
setup_deploy_key() click to toggle source
# File lib/dpl/providers/pages/git.rb, line 120
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, url: opts[:url]
end
slug() click to toggle source
# File lib/dpl/providers/pages/git.rb, line 226
def slug
  repo || repo_slug
end
src_dir() click to toggle source
# File lib/dpl/providers/pages/git.rb, line 237
def src_dir
  @src_dir ||= expand(local_dir)
end
sufficient_scopes?() click to toggle source
# File lib/dpl/providers/pages/git.rb, line 206
def sufficient_scopes?
  api.scopes.include?('public_repo') || api.scopes.include?('repo')
end
url() click to toggle source
# File lib/dpl/providers/pages/git.rb, line 222
def url
  "#{opts[:url]}/#{slug}.git"
end
user() click to toggle source
# File lib/dpl/providers/pages/git.rb, line 230
def user
  @user ||= api.user
rescue StandardError => e
  puts "ERR: #{e.inspect}"
  puts e.backtrace
end
work_dir() click to toggle source
# File lib/dpl/providers/pages/git.rb, line 241
def work_dir
  @work_dir ||= tmp_dir
end