Class: Release
- Inherits:
-
Object
- Object
- Release
- Defined in:
- lib/cookbook-release/release.rb
Defined Under Namespace
Classes: ExistingRelease
Instance Attribute Summary collapse
-
#git ⇒ Object
readonly
Returns the value of attribute git.
Class Method Summary collapse
Instance Method Summary collapse
- #display_changelog(new_version) ⇒ Object
- #display_suggested_version(new_version, reasons) ⇒ Object
- #git_changelog ⇒ Object
-
#initialize(git, opts = {}) ⇒ Release
constructor
A new instance of Release.
- #last_release ⇒ Object
-
#new_version ⇒ Object
return the new version and the reasons.
- #prepare_release ⇒ Object
- #release! ⇒ Object
- #user_defined_version ⇒ Object
Constructor Details
#initialize(git, opts = {}) ⇒ Release
Returns a new instance of Release.
17 18 19 20 21 |
# File 'lib/cookbook-release/release.rb', line 17 def initialize(git, opts={}) @git = git @no_prompt = opts[:no_prompt] @git.no_prompt = @no_prompt end |
Instance Attribute Details
#git ⇒ Object (readonly)
Returns the value of attribute git.
15 16 17 |
# File 'lib/cookbook-release/release.rb', line 15 def git @git end |
Class Method Details
.current_version ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'lib/cookbook-release/release.rb', line 3 def self.current_version r = Release.new(GitUtilities.new) begin r.new_version.first rescue ExistingRelease r.last_release end end |
Instance Method Details
#display_changelog(new_version) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/cookbook-release/release.rb', line 54 def display_changelog(new_version) puts "Changelog for #{new_version}:" git_changelog.each do |commit| puts "* #{commit[:hash]} #{HighLine.color(commit[:subject], commit.color)} (#{commit[:author]})" end end |
#display_suggested_version(new_version, reasons) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/cookbook-release/release.rb', line 46 def display_suggested_version(new_version, reasons) puts "Suggested version: " + new_version.to_s puts "Commits that suggest this change:" reasons.each do |commit| puts "* #{commit[:hash]} #{commit[:subject]} (#{commit[:author]})" end end |
#git_changelog ⇒ Object
27 28 29 |
# File 'lib/cookbook-release/release.rb', line 27 def git_changelog @git_changelog ||= git.compute_changelog(last_release) end |
#last_release ⇒ Object
23 24 25 |
# File 'lib/cookbook-release/release.rb', line 23 def last_release @last_release ||= git.compute_last_release end |
#new_version ⇒ Object
return the new version and the reasons
32 33 34 35 36 37 38 |
# File 'lib/cookbook-release/release.rb', line 32 def new_version %w(major minor patch).each do |level| changes = git_changelog.select(&"#{level}?".to_sym) return [ last_release.send("#{level}!"), changes ] if changes.size > 0 end raise ExistingRelease, "No commit since last release (#{last_release})" end |
#prepare_release ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/cookbook-release/release.rb', line 61 def prepare_release git.clean_index! new_version , reasons = self.new_version puts "Last release was: " + last_release.to_s display_suggested_version(new_version, reasons) puts "" agreed = @no_prompt || agree("Do you agree with that version?") { |q| q.default = "yes" } new_version = user_defined_version unless agreed puts "New release will be #{new_version}" puts "" new_version end |
#release! ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/cookbook-release/release.rb', line 76 def release! new_version = prepare_release begin git.tag(new_version) display_changelog(new_version) puts "" agreed = @no_prompt || agree("Do you agree with this changelog?") { |q| q.default = "yes" } exit 1 unless agreed git.push_tag(new_version) supermarket = Supermarket.new supermarket.publish_ck('Others') ensure puts HighLine.color("Release aborted, you have to reset to previous state manually", :red) puts ":use with care: #{git.reset_command(new_version)}" end end |
#user_defined_version ⇒ Object
40 41 42 43 44 |
# File 'lib/cookbook-release/release.rb', line 40 def user_defined_version puts "Which kind of upgrade ?" new_release_level = choose(*%w(major minor patch)) last_release.send("#{new_release_level}!") end |