Class: Octopolo::Scripts::TagRelease
- Inherits:
-
Object
- Object
- Octopolo::Scripts::TagRelease
- Includes:
- CLIWrapper, ConfigWrapper, GitWrapper
- Defined in:
- lib/octopolo/scripts/tag_release.rb
Constant Summary collapse
- TIMESTAMP_FORMAT =
"%Y.%m.%d.%H.%M"
- SEMVER_CHOICES =
%w[Major Minor Patch]
Instance Attribute Summary collapse
-
#force ⇒ Object
(also: #force?)
Returns the value of attribute force.
-
#major ⇒ Object
(also: #major?)
Returns the value of attribute major.
-
#minor ⇒ Object
(also: #minor?)
Returns the value of attribute minor.
-
#patch ⇒ Object
(also: #patch?)
Returns the value of attribute patch.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#suffix ⇒ Object
Returns the value of attribute suffix.
Attributes included from GitWrapper
Attributes included from ConfigWrapper
Attributes included from CLIWrapper
Class Method Summary collapse
Instance Method Summary collapse
- #ask_user_version ⇒ Object
-
#changelog ⇒ Object
Private: the changelog file.
- #execute ⇒ Object
- #get_current_version ⇒ Object
-
#initialize(options = {}) ⇒ TagRelease
constructor
A new instance of TagRelease.
-
#set_prefix ⇒ Object
Private: sets/removes the prefix from the tag.
-
#should_create_branch? ⇒ Boolean
Public: Whether to create a new branch.
-
#tag_name ⇒ Object
Public: The name to apply to the new tag.
-
#tag_release ⇒ Object
Public: Generate a tag for the current release.
- #tag_semver ⇒ Object
- #update_changelog ⇒ Object
- #upgrade_version(current_version) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ TagRelease
Returns a new instance of TagRelease.
34 35 36 37 38 39 40 41 |
# File 'lib/octopolo/scripts/tag_release.rb', line 34 def initialize(={}) @prefix = [:prefix] @suffix = [:suffix] @force = [:force] @major = [:major] @minor = [:minor] @patch = [:patch] end |
Instance Attribute Details
#force ⇒ Object Also known as: force?
Returns the value of attribute force.
18 19 20 |
# File 'lib/octopolo/scripts/tag_release.rb', line 18 def force @force end |
#major ⇒ Object Also known as: major?
Returns the value of attribute major.
19 20 21 |
# File 'lib/octopolo/scripts/tag_release.rb', line 19 def major @major end |
#minor ⇒ Object Also known as: minor?
Returns the value of attribute minor.
20 21 22 |
# File 'lib/octopolo/scripts/tag_release.rb', line 20 def minor @minor end |
#patch ⇒ Object Also known as: patch?
Returns the value of attribute patch.
21 22 23 |
# File 'lib/octopolo/scripts/tag_release.rb', line 21 def patch @patch end |
#prefix ⇒ Object
Returns the value of attribute prefix.
16 17 18 |
# File 'lib/octopolo/scripts/tag_release.rb', line 16 def prefix @prefix end |
#suffix ⇒ Object
Returns the value of attribute suffix.
17 18 19 |
# File 'lib/octopolo/scripts/tag_release.rb', line 17 def suffix @suffix end |
Class Method Details
.execute(options = nil) ⇒ Object
30 31 32 |
# File 'lib/octopolo/scripts/tag_release.rb', line 30 def self.execute(=nil) new().execute end |
Instance Method Details
#ask_user_version ⇒ Object
94 95 96 97 |
# File 'lib/octopolo/scripts/tag_release.rb', line 94 def ask_user_version response = cli.ask("Which version section do you want to increment?", SEMVER_CHOICES) send("#{response.downcase}=", true) end |
#changelog ⇒ Object
Private: the changelog file
114 115 116 |
# File 'lib/octopolo/scripts/tag_release.rb', line 114 def changelog @changelog ||= Changelog.new end |
#execute ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/octopolo/scripts/tag_release.rb', line 43 def execute if should_create_branch? update_changelog tag_release else raise Octopolo::WrongBranch.new("Must perform this script from the deploy branch (#{config.deploy_branch})") end end |
#get_current_version ⇒ Object
89 90 91 92 |
# File 'lib/octopolo/scripts/tag_release.rb', line 89 def get_current_version = git. .map{|tag| Octopolo::SemverTagScrubber.scrub_prefix(tag); tag.to_version }.sort.last || "0.0.0".to_version end |
#set_prefix ⇒ Object
Private: sets/removes the prefix from the tag
Allows the tag to play nice with the semantic gem
121 122 123 |
# File 'lib/octopolo/scripts/tag_release.rb', line 121 def set_prefix @prefix ||= Octopolo::SemverTagScrubber.scrub_prefix(git..last) end |
#should_create_branch? ⇒ Boolean
Public: Whether to create a new branch
Returns a Boolean
55 56 57 |
# File 'lib/octopolo/scripts/tag_release.rb', line 55 def should_create_branch? force? || (git.current_branch == config.deploy_branch) end |
#tag_name ⇒ Object
Public: The name to apply to the new tag
73 74 75 76 77 78 79 |
# File 'lib/octopolo/scripts/tag_release.rb', line 73 def tag_name if config.semantic_versioning @tag_name ||= tag_semver else @tag_name ||= %Q(#{Time.now.strftime(TIMESTAMP_FORMAT)}#{"_#{suffix}" if suffix}) end end |
#tag_release ⇒ Object
Public: Generate a tag for the current release
68 69 70 |
# File 'lib/octopolo/scripts/tag_release.rb', line 68 def tag_release git.new_tag tag_name end |
#tag_semver ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/octopolo/scripts/tag_release.rb', line 81 def tag_semver current_version = get_current_version set_prefix ask_user_version unless @major || @minor || @patch new_version = upgrade_version current_version "#{prefix}#{new_version.to_s}" end |
#update_changelog ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/octopolo/scripts/tag_release.rb', line 59 def update_changelog changelog.open do |log| log.puts "#### #{tag_name}" end git.perform("add #{changelog.filename}") git.perform("commit -m 'Updating Changelog for #{tag_name}'") end |
#upgrade_version(current_version) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/octopolo/scripts/tag_release.rb', line 99 def upgrade_version current_version if @major current_version.major += 1 current_version.minor = 0 current_version.patch = 0 elsif @minor current_version.minor += 1 current_version.patch = 0 elsif @patch current_version.patch+=1 end current_version end |