From d334d3af298f2bde9dd828d015ac8fd6a096a8e4 Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Sun, 14 Jun 2020 01:19:55 +0900 Subject: [PATCH] feat: Allow to customise the target branch (#7) * define master * tweak * update readme --- README.md | 20 ++++++++++++-------- lib/appium_thor/commands/commands.rb | 1 + lib/appium_thor/config.rb | 5 ++++- lib/appium_thor/helpers.rb | 6 +++--- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index e72bdbf..a67a460 100644 --- a/README.md +++ b/README.md @@ -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') @@ -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` -- diff --git a/lib/appium_thor/commands/commands.rb b/lib/appium_thor/commands/commands.rb index da04597..7e979f3 100644 --- a/lib/appium_thor/commands/commands.rb +++ b/lib/appium_thor/commands/commands.rb @@ -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 diff --git a/lib/appium_thor/config.rb b/lib/appium_thor/config.rb index 335231c..0f8037a 100644 --- a/lib/appium_thor/config.rb +++ b/lib/appium_thor/config.rb @@ -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 @@ -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| @@ -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) diff --git a/lib/appium_thor/helpers.rb b/lib/appium_thor/helpers.rb index 55298c4..134e9bb 100644 --- a/lib/appium_thor/helpers.rb +++ b/lib/appium_thor/helpers.rb @@ -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. @@ -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 @@ -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'"