diff --git a/lib/release/commander.rb b/lib/release/commander.rb index 6cea02b..2c4f888 100644 --- a/lib/release/commander.rb +++ b/lib/release/commander.rb @@ -7,6 +7,8 @@ module Release COMMANDS = [ :help, :init, + :major, + :minor, :patch ].sort diff --git a/lib/release/major.rb b/lib/release/major.rb new file mode 100644 index 0000000..62ba5e8 --- /dev/null +++ b/lib/release/major.rb @@ -0,0 +1,39 @@ +require_relative './base' + +module Release + + class Major < Release::Base + def valid? + argv.size > 1 + end + + def help + "release major 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 + + major_branch = major(version) + + git_pull current_branch + + git_local_branch_create major_branch, "v#{version}" + + git_push major_branch + end + + private + + def major (version) + numbers = version.split('.').map { |x| x.to_i } + "#{numbers[0]+1}.0.0" + end + + end + +end diff --git a/lib/release/minor.rb b/lib/release/minor.rb new file mode 100644 index 0000000..608a65f --- /dev/null +++ b/lib/release/minor.rb @@ -0,0 +1,39 @@ +require_relative './base' + +module Release + + class Minor < Release::Base + def valid? + argv.size > 1 + end + + def help + "release minor 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 + + minor_branch = minor(version) + + git_pull current_branch + + git_local_branch_create minor_branch, "v#{version}" + + git_push minor_branch + end + + private + + def minor (version) + numbers = version.split('.').map { |x| x.to_i } + "#{numbers[0]}.#{numbers[1]+1}.0" + end + + end + +end