Skip to content

Commit

Permalink
feat: Allow to customise the target branch (#7)
Browse files Browse the repository at this point in the history
* define master

* tweak

* update readme
  • Loading branch information
KazuCocoa authored Jun 13, 2020
1 parent b75ffd3 commit d334d3a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Appium::Thor::Config.set do
gem_name 'appium_thor'
github_owner 'appium'
github_name 'appium_thor'
branch 'master'
version_file 'lib/appium_thor/version.rb'
docs_block do
run 'docs/helpers_docs.md', globs('/lib/appium_thor/helpers.rb')
Expand All @@ -35,14 +36,17 @@ end

# Defaults

Option | Default
--:|:--
gem_name | must be provided
github_owner | `appium`
github_name | `#{gem_name}`
version_file | `lib/#{gem_name}/version.rb`
docs_block | no docs are generated

|Option | Default|
|---:|:---|
|gem_name | must be provided|
|github_owner | `appium`|
|github_name | `#{gem_name}`|
|branch | `master`|
|version_file | `lib/#{gem_name}/version.rb`|
|docs_block | no docs are generated|

`branch` customises the target branch to push changes.
Defaults to `master`

--

Expand Down
1 change: 1 addition & 0 deletions lib/appium_thor/commands/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def info
gem_name: #{gem_name}
github_name: #{github_name}
github_owner: #{github_owner}
branch: #{branch}
version_file: #{version_file}
MSG
end
Expand Down
5 changes: 4 additions & 1 deletion lib/appium_thor/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ def init_and_validate
@version_file ||= "lib/#{@gem_name}/version.rb"
end

@branch ||= 'master'

@github_owner ||= 'appium'

# ensure all options are set
Expand All @@ -33,7 +35,7 @@ def self.options

# the subset of options that operate on strings
def self.string_options
%w[gem_name github_name github_owner version_file].map(&:to_sym)
%w[gem_name github_name github_owner branch version_file].map(&:to_sym)
end

string_options.each do |option|
Expand All @@ -51,6 +53,7 @@ def #{option} string=nil
# gem_name 'appium_thor'
# github_owner 'appium'
# github_name 'appium_thor'
# branch 'master'
# version_file 'path/to/version.rb'
# end
def self.set(&block)
Expand Down
6 changes: 3 additions & 3 deletions lib/appium_thor/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def _build_gem
# Returns true if the tag exists on the master branch.
def tag_exists(tag_name)
cmd = %Q(git branch -a --contains "#{tag_name}")
POSIX::Spawn::Child.new(cmd).out.include? '* master'
POSIX::Spawn::Child.new(cmd).out.include? "* #{branch}"
end

# Runs command. Raises an exception if the command doesn't execute successfully.
Expand Down Expand Up @@ -166,7 +166,7 @@ def _uninstall
# Builds the gem
# Publishes the gem to rubygems
def _publish
unless `git branch`.include? '* master'
unless `git branch`.include? "* #{branch}"
puts 'Master branch required to release.'
exit!
end
Expand All @@ -189,7 +189,7 @@ def _publish
notes rescue notes_failed = true
docs
sh "git commit --allow-empty -am 'Update release notes'" unless notes_failed
sh 'git push origin master'
sh "git push origin #{branch}"
sh "git push origin #{tag_name}"
_build_gem
puts "Please run 'gem push #{gem_name}-#{version}.gem'"
Expand Down

0 comments on commit d334d3a

Please sign in to comment.