Skip to content

Commit

Permalink
Merge 2561b09 into baf2ab2
Browse files Browse the repository at this point in the history
  • Loading branch information
svenfuchs committed Aug 21, 2019
2 parents baf2ab2 + 2561b09 commit 21c411a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
5 changes: 5 additions & 0 deletions lib/dpl/ctx/bash.rb
Expand Up @@ -388,6 +388,11 @@ def encoding(path)
end
end

# Returns the current branch name
def git_branch
ENV['TRAVIS_BRANCH'] || git_rev_parse('HEAD')
end

# Returns the message of the commit `git_sha`.
def git_commit_msg
`git log #{git_sha} -n 1 --pretty=%B`.chomp
Expand Down
7 changes: 5 additions & 2 deletions lib/dpl/helper/interpolate.rb
Expand Up @@ -68,11 +68,12 @@ class Interpolator < Struct.new(:str, :obj, :args, :opts)
include Interpolate

MODIFIER = %i(obfuscate escape quote)
PATTERN = /%\{(\w+)\}/
PATTERN = /%\{(\$?[\w]+)\}/
ENV_VAR = /^\$[A-Z_]+$/
UPCASE = /^[A-Z_]+$/

def apply
str = interpolate(self.str)
str = interpolate(self.str.to_s)
str = obfuscate(str) unless opts[:secure]
str = str.gsub(' ', ' ') if str.lines.size == 1
str
Expand Down Expand Up @@ -104,6 +105,8 @@ def lookup(key)
if mod = modifier(key)
key = key.to_s.sub("#{mod}d_", '')
obj.send(mod, lookup(key))
elsif key.to_s =~ ENV_VAR
ENV[key.to_s.sub('$', '')]
elsif key.to_s =~ UPCASE
obj.class.const_get(key)
elsif args.is_a?(Hash) && args.key?(key)
Expand Down
12 changes: 6 additions & 6 deletions lib/dpl/provider.rb
Expand Up @@ -168,12 +168,12 @@ def validate_runtimes(ctx)
:validate_runtimes, :user_agent

def_delegators :ctx, :apt_get, :gem_require, :npm_install, :pip_install,
:build_dir, :build_number, :repo_slug, :encoding, :git_commit_msg,
:git_dirty?, :git_log, :git_ls_files, :git_ls_remote?, :git_remote_urls,
:git_rev_parse, :git_sha, :git_tag, :machine_name, :node_version,
:npm_version, :sleep, :ssh_keygen, :success?, :mv, :tmp_dir, :which,
:logger, :rendezvous, :file_size, :write_file, :write_netrc, :last_out,
:last_err, :test?, :tty?
:build_dir, :build_number, :repo_slug, :encoding, :git_branch,
:git_commit_msg, :git_dirty?, :git_log, :git_ls_files, :git_ls_remote?,
:git_remote_urls, :git_rev_parse, :git_sha, :git_tag, :machine_name,
:node_version, :npm_version, :sleep, :ssh_keygen, :success?, :mv,
:tmp_dir, :which, :logger, :rendezvous, :file_size, :write_file,
:write_netrc, :last_out, :last_err, :test?, :tty?

attr_reader :repo_name, :key_name

Expand Down
7 changes: 6 additions & 1 deletion lib/dpl/providers/pages.rb
Expand Up @@ -19,6 +19,7 @@ class Pages < Provider
opt '--repo SLUG', 'Repo slug', default: :repo_slug
opt '--target_branch BRANCH', 'Branch to push force to', default: 'gh-pages'
opt '--keep_history', 'Create incremental commit instead of doing push force', default: true
opt '--commit_message MSG', default: 'Deploy %{project_name} to %{url}:%{target_branch}'
opt '--allow_empty_commit', 'Allow an empty commit to be created', requires: :keep_history
opt '--committer_from_gh', 'Use the token\'s owner name and email for commit. Overrides the email and name options'
opt '--verbose', 'Be verbose about the deploy process'
Expand Down Expand Up @@ -59,7 +60,7 @@ class Pages < Provider
deployment_file: 'touch "deployed at %{now} by %{committer_name}"',
cname: 'echo "%{fqdn}" > CNAME',
git_add: 'git add -A .',
git_commit: 'git commit%{git_commit_opts} -qm "Deploy %{project_name} to %{url}:%{target_branch}"',
git_commit: 'git commit%{git_commit_opts} -qm "%{commit_message}"',
git_show: 'git show --stat-count=10 HEAD',
git_push: 'git push%{git_push_opts} --quiet "%{remote_url}" "%{target_branch}":"%{target_branch}" > /dev/null 2>&1'

Expand Down Expand Up @@ -180,6 +181,10 @@ def committer_email
committer_from_gh? ? user.email || email : email
end

def commit_message
interpolate(super)
end

def project_name
super || fqdn || repo_slug
end
Expand Down
7 changes: 6 additions & 1 deletion spec/dpl/providers/pages_spec.rb
Expand Up @@ -5,8 +5,9 @@
let!(:cwd) { File.expand_path('.') }
let(:tmp) { File.expand_path('tmp') }

before { stub_request(:get, 'https://api.github.com/user').and_return(status: 200, body: user, headers: headers) }
env FOO: 'foo'

before { stub_request(:get, 'https://api.github.com/user').and_return(status: 200, body: user, headers: headers) }
before { subject.run }

describe 'by default', record: true do
Expand Down Expand Up @@ -89,6 +90,10 @@
it { should have_run 'git config user.email "other"' }
end

describe 'given --commit_message "msg %{repo} %{$FOO}"' do
it { should have_run 'git commit -qm "msg travis-ci/dpl foo"' }
end

describe 'given --deploy_key a2V5Cg==', record: true do
let(:args) { |e| args_from_description(e) }
it { should have_run '[info] Setting up deploy key in ~/.dpl/deploy_key' }
Expand Down

0 comments on commit 21c411a

Please sign in to comment.