Class: Octopolo::Scripts::TagRelease

Inherits:
Object
  • Object
show all
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

Attributes included from GitWrapper

#git

Attributes included from ConfigWrapper

#config

Attributes included from CLIWrapper

#cli

Class Method Summary collapse

Instance Method Summary collapse

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(options={})
  @prefix = options[:prefix]
  @suffix = options[:suffix]
  @force = options[:force]
  @major = options[:major]
  @minor = options[:minor]
  @patch = options[:patch]
end

Instance Attribute Details

#forceObject 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

#majorObject 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

#minorObject 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

#patchObject 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

#prefixObject

Returns the value of attribute prefix.



16
17
18
# File 'lib/octopolo/scripts/tag_release.rb', line 16

def prefix
  @prefix
end

#suffixObject

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(options=nil)
  new(options).execute
end

Instance Method Details

#ask_user_versionObject



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

#changelogObject

Private: the changelog file



114
115
116
# File 'lib/octopolo/scripts/tag_release.rb', line 114

def changelog
  @changelog ||= Changelog.new
end

#executeObject



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_versionObject



89
90
91
92
# File 'lib/octopolo/scripts/tag_release.rb', line 89

def get_current_version
  tags = git.semver_tags
  tags.map{|tag| Octopolo::SemverTagScrubber.scrub_prefix(tag); tag.to_version }.sort.last || "0.0.0".to_version
end

#set_prefixObject

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.semver_tags.last)
end

#should_create_branch?Boolean

Public: Whether to create a new branch

Returns a Boolean

Returns:

  • (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_nameObject

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_releaseObject

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_semverObject



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_changelogObject



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