diff --git a/lib/release/base.rb b/lib/release/base.rb index db1738e..47c3156 100644 --- a/lib/release/base.rb +++ b/lib/release/base.rb @@ -26,17 +26,25 @@ module Release end private - + def validate_version_format (version) - error "invalid version number format: #{version}" unless version =~ /\d+\.\d+\.\d+/ + error "Invalid version number format. Try using MAJOR.MINOR.PATCH." unless version =~ /\d+\.\d+\.\d+/ end def validate_version_is_new (version) - error "version already exists: #{git_local_list_tags.join(' ')}" if git_local_list_tags.include? "v#{version}" + error "Version already exists: #{git_local_list_tags.join(' ')}" if git_local_list_tags.include? "v#{version}" + end + + def validate_version_exists (version) + error "Version does not exist: #{git_local_list_tags.join(' ')}" unless git_local_list_tags.include? "v#{version}" end def validate_current_branch_master - error "invalid starting branch: #{current_branch}" unless standard_branches.include? current_branch + error "Invalid starting branch: #{current_branch}. Try switching to #{standard_branches.join(' ')}." unless standard_branches.include? current_branch + end + + def validate_release_branch_does_not_exist (branch) + error "Version branch already exists: #{branch}" if remote_branch(branch) != "" end end diff --git a/lib/release/init.rb b/lib/release/init.rb index b50d82d..673ded7 100644 --- a/lib/release/init.rb +++ b/lib/release/init.rb @@ -15,11 +15,12 @@ module Release subcommand, version, *extras = *argv validate_version_format version - validate_version_is_new version + validate_current_branch_master - git_pull current_branch + validate_version_is_new version + git_local_tag version git_push_tags diff --git a/lib/release/major.rb b/lib/release/major.rb index 62ba5e8..c887a9f 100644 --- a/lib/release/major.rb +++ b/lib/release/major.rb @@ -1,35 +1,16 @@ -require_relative './base' +require_relative './new_version' 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 + class Major < Release::NewVersion private - def major (version) + def subcommand_name + "major" + end + + def increment_version (version) numbers = version.split('.').map { |x| x.to_i } "#{numbers[0]+1}.0.0" end diff --git a/lib/release/minor.rb b/lib/release/minor.rb index 608a65f..a0f6743 100644 --- a/lib/release/minor.rb +++ b/lib/release/minor.rb @@ -1,35 +1,16 @@ -require_relative './base' +require_relative './new_version' 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 + class Minor < Release::NewVersion private - def minor (version) + def subcommand_name + "minor" + end + + def increment_version (version) numbers = version.split('.').map { |x| x.to_i } "#{numbers[0]}.#{numbers[1]+1}.0" end diff --git a/lib/release/new_version.rb b/lib/release/new_version.rb new file mode 100644 index 0000000..fc46995 --- /dev/null +++ b/lib/release/new_version.rb @@ -0,0 +1,44 @@ +require_relative './base' + +module Release + + class NewVersion < Release::Base + def valid? + argv.size > 1 + end + + def help + "release #{subcommand_name} version" + end + + def execute + subcommand, version, *extras = *argv + + validate_version_format version + + validate_current_branch_master + git_pull current_branch + + validate_version_exists version + + new_branch = increment_version(version) + validate_release_branch_does_not_exist(new_branch) + + git_local_branch_create new_branch, "v#{version}" + + git_push new_branch + end + + private + + def subcommand_name + error "override" + end + + def increment_version (version) + error "override" + end + + end + +end diff --git a/lib/release/patch.rb b/lib/release/patch.rb index 8f2c022..7e6454f 100644 --- a/lib/release/patch.rb +++ b/lib/release/patch.rb @@ -1,35 +1,16 @@ -require_relative './base' +require_relative './new_version' 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 + class Patch < Release::NewVersion private - def patch (version) + def subcommand_name + "patch" + end + + def increment_version (version) numbers = version.split('.').map { |x| x.to_i } "#{numbers[0]}.#{numbers[1]}.#{numbers[2]+1}" end