Skip to content

Commit

Permalink
add pages --commit_message (ports #824)
Browse files Browse the repository at this point in the history
  • Loading branch information
svenfuchs committed Aug 11, 2019
1 parent 1eb056a commit f26f065
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
12 changes: 7 additions & 5 deletions lib/dpl/providers/pages.rb
Expand Up @@ -16,6 +16,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 All @@ -24,12 +25,9 @@ class Pages < Provider
opt '--project_name NAME', 'Used in the commit message only (defaults to fqdn or the current repo slug)'
opt '--email EMAIL', 'Committer email', default: 'deploy@travis-ci.org'
opt '--name NAME', 'Committer name', default: 'Deploy Bot'
# what is the purpose of this file in the first place? a file name with
# spaces seems highly irregular, but this has been there from the start
# https://github.com/travis-ci/dpl/commit/58f6c7dd4f0fd49df2e93a8495fd01c7784d4f58#diff-cc5438ae072229825b07abf38951a912R47
opt '--deployment_file', 'Enable creation of a deployment-info file'
# not mentioned in the readme
opt '--github_url URL', default: 'github.com'

# how about the octokit options?

needs :git
Expand Down Expand Up @@ -59,7 +57,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 "%{url_with_token}" "%{target_branch}":"%{target_branch}" > /dev/null 2>&1'

Expand Down Expand Up @@ -162,6 +160,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 @@ -88,4 +89,8 @@
describe 'given --email other' do
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
end

0 comments on commit f26f065

Please sign in to comment.