Class: CookbookRelease::Commit
- Inherits:
-
Object
- Object
- CookbookRelease::Commit
- Extended by:
- Forwardable
- Defined in:
- lib/cookbook-release/commit.rb
Instance Method Summary collapse
- #color ⇒ Object
-
#initialize(hash) ⇒ Commit
constructor
A new instance of Commit.
- #major? ⇒ Boolean
- #minor? ⇒ Boolean
- #patch? ⇒ Boolean
- #risky? ⇒ Boolean
- #to_s_html(full) ⇒ Object
- #to_s_markdown(full) ⇒ Object
- #to_s_oneline ⇒ Object
Constructor Details
#initialize(hash) ⇒ Commit
Returns a new instance of Commit.
6 7 8 |
# File 'lib/cookbook-release/commit.rb', line 6 def initialize(hash) @hash = hash end |
Instance Method Details
#color ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/cookbook-release/commit.rb', line 37 def color case true when major? :red when risky? :red else :grey end end |
#major? ⇒ Boolean
10 11 12 13 14 15 16 17 |
# File 'lib/cookbook-release/commit.rb', line 10 def major? [ /breaking/i, /\[major\]/i ].any? do |r| self[:subject] =~ r end end |
#minor? ⇒ Boolean
29 30 31 |
# File 'lib/cookbook-release/commit.rb', line 29 def minor? !(major? || patch?) end |
#patch? ⇒ Boolean
19 20 21 22 23 24 25 26 27 |
# File 'lib/cookbook-release/commit.rb', line 19 def patch? [ /\bfix\b/i, /\bbugfix\b/i, /\[patch\]/i ].any? do |r| self[:subject] =~ r end end |
#risky? ⇒ Boolean
33 34 35 |
# File 'lib/cookbook-release/commit.rb', line 33 def risky? !!(self[:subject] =~ /\[risky\]/i) end |
#to_s_html(full) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/cookbook-release/commit.rb', line 52 def to_s_html(full) result = [] result << "<font color=\#{color.to_s}>\n \#{self[:hash]} \#{self[:author]} <\#{self[:email]}> \#{self[:subject]}\n</font>\n EOH\n if full && self[:body]\n result << <<-EOH\n<pre>\n\#{self[:body]}\n</pre>\n EOH\n end\n\n result.join(\"\\n\")\nend\n" |
#to_s_markdown(full) ⇒ Object
70 71 72 73 74 |
# File 'lib/cookbook-release/commit.rb', line 70 def to_s_markdown(full) result = "*#{self[:hash]}* _#{self[:author]} <#{self[:email]}>_ `#{self[:subject]}`" result << "\n```\n#{self[:body]}\n```" if full && self[:body] result end |
#to_s_oneline ⇒ Object
48 49 50 |
# File 'lib/cookbook-release/commit.rb', line 48 def to_s_oneline "#{self[:hash]} #{self[:author]} <#{self[:email]}> #{self[:subject]}" end |