From 9ff65e7e1e4941442daf8056b8472a9a720a46bf Mon Sep 17 00:00:00 2001 From: rkiel Date: Tue, 19 Sep 2017 22:18:18 -0400 Subject: [PATCH] release: added patch --- lib/feature/merge.rb | 2 +- lib/feature/start.rb | 2 +- lib/release/commander.rb | 3 ++- lib/release/patch.rb | 39 +++++++++++++++++++++++++++++++++++++ lib/shared/branchability.rb | 2 +- lib/shared/runnable.rb | 6 +++--- 6 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 lib/release/patch.rb diff --git a/lib/feature/merge.rb b/lib/feature/merge.rb index 9f7e06b..3c962ba 100644 --- a/lib/feature/merge.rb +++ b/lib/feature/merge.rb @@ -22,7 +22,7 @@ module Feature feature_branch = current_branch - error "invalid branch: #{merge_to_branch}" unless standard_branches.include? merge_to_branch + error "invalid branch: #{merge_to_branch}" unless standard_branches.include? merge_to_branch or merge_to_branch =~ /\d+\.\d+\.\d+/ git_checkout merge_to_branch git_pull merge_to_branch diff --git a/lib/feature/start.rb b/lib/feature/start.rb index 1a87a33..55a87a6 100644 --- a/lib/feature/start.rb +++ b/lib/feature/start.rb @@ -17,7 +17,7 @@ module Feature feature_name = feature_words.join('-') feature_branch = "#{ENV['FEATURE_USER']||ENV['USER']}-#{current_branch}-#{feature_name}" - error "invalid base branch: #{current_branch}" unless standard_branches.include? current_branch + error "invalid base branch: #{current_branch}" unless standard_branches.include? current_branch or current_branch =~ /\d+\.\d+\.\d+/ error "invalid feature branch: #{feature_name}" if standard_branches.include? feature_name git_pull current_branch diff --git a/lib/release/commander.rb b/lib/release/commander.rb index bbdd8f3..6cea02b 100644 --- a/lib/release/commander.rb +++ b/lib/release/commander.rb @@ -6,7 +6,8 @@ module Release COMMANDS = [ :help, - :init + :init, + :patch ].sort DEFAULT = :help diff --git a/lib/release/patch.rb b/lib/release/patch.rb new file mode 100644 index 0000000..8f2c022 --- /dev/null +++ b/lib/release/patch.rb @@ -0,0 +1,39 @@ +require_relative './base' + +module Release + + class Patch < Release::Base + def valid? + argv.size > 1 + end + + def help + "release patch version" + end + + def execute + subcommand, version, *extras = *argv + + error "invalid version: #{version}" unless version =~ /\d+\.\d+\.\d+/ + error "unknown version: #{git_local_list_tags.join(' ')}" unless git_local_list_tags.include? "v#{version}" + error "invalid base branch: #{current_branch}" unless standard_branches.include? current_branch + + patch_branch = patch(version) + + git_pull current_branch + + git_local_branch_create patch_branch, "v#{version}" + + git_push patch_branch + end + + private + + def patch (version) + numbers = version.split('.').map { |x| x.to_i } + "#{numbers[0]}.#{numbers[1]}.#{numbers[2]+1}" + end + + end + +end diff --git a/lib/shared/branchability.rb b/lib/shared/branchability.rb index 3f247bb..957f568 100644 --- a/lib/shared/branchability.rb +++ b/lib/shared/branchability.rb @@ -20,7 +20,7 @@ module Shared user = parts.shift standard = parts.shift error "invalid user: #{user}" unless [ENV['FEATURE_USER'],ENV['USER']].include? user - error "invalid branch: #{standard}" unless standard_branches.include? standard + error "invalid branch: #{standard}" unless standard_branches.include? standard or standard =~ /\d+\.\d+\.\d+/ feature = parts.join('-') { user: user, standard: standard, feature: feature } end diff --git a/lib/shared/runnable.rb b/lib/shared/runnable.rb index 2733d31..e0749f2 100644 --- a/lib/shared/runnable.rb +++ b/lib/shared/runnable.rb @@ -44,7 +44,7 @@ module Shared end def git_local_list_tags - `git tag -l 'v*'`.strip.split(/\s+/) + `git tag -l 'v*'`.strip.split(/\s+/).sort end def git_prune @@ -71,8 +71,8 @@ module Shared run_cmd "git rebase #{branch}" end - def git_local_branch_create (branch) - run_cmd "git checkout -b #{branch}" + def git_local_branch_create (branch, commit='') + run_cmd "git checkout -b #{branch} #{commit}" end def git_commit (message, force = false)