class CookbookRelease::Commit

Public Class Methods

new(hash) click to toggle source
# File lib/cookbook-release/commit.rb, line 9
def initialize(hash)
  @hash = hash
end

Public Instance Methods

backtick_string(input) click to toggle source
# File lib/cookbook-release/commit.rb, line 91
def backtick_string(input)
  s = input.gsub(/( )?(#{Unicode::Emoji::REGEX})( )?/, '` \2 `')
           .gsub(/( )?``( )?/, '')
  s += '`' unless s =~ /`$/
  s = '`' + s unless s =~ /^`/
  s
end
color() click to toggle source
# File lib/cookbook-release/commit.rb, line 44
def color
  case true
  when major?
    :red
  when risky?
    :red
  else
    :grey
  end
end
major?() click to toggle source
# File lib/cookbook-release/commit.rb, line 13
def major?
  [
    /breaking/i,
    /\[major\]/i
  ].any? do |r|
    self[:subject] =~ r
  end
end
minor?() click to toggle source
# File lib/cookbook-release/commit.rb, line 32
def minor?
  !(major? || patch?)
end
nodes_only?() click to toggle source
# File lib/cookbook-release/commit.rb, line 40
def nodes_only?
  self[:nodes_only]
end
patch?() click to toggle source
# File lib/cookbook-release/commit.rb, line 22
def patch?
  [
    /\bfix\b/i,
    /\bbugfix\b/i,
    /\[patch\]/i
  ].any? do |r|
    self[:subject] =~ r
  end
end
risky?() click to toggle source
# File lib/cookbook-release/commit.rb, line 36
def risky?
  !!(self[:subject] =~ /\[risky\]/i)
end
to_s_html(full) click to toggle source
# File lib/cookbook-release/commit.rb, line 59
    def to_s_html(full)
      result = []
      result << <<-EOH
<font color=#{color.to_s}>
  #{self[:hash]} #{self[:author]} <#{self[:email]}> #{self[:subject]}
</font>
      EOH
      if full && self[:body]
        result << <<-EOH
<pre>
#{strip_change_id(self[:body])}
</pre>
        EOH
      end

      result.join("\n")
    end
to_s_markdown(full) click to toggle source
# File lib/cookbook-release/commit.rb, line 77
def to_s_markdown(full)
  result = "*#{self[:hash]}* "
  if self[:subject] =~ /risky|breaking/i
    slack_user = self[:email].split('@')[0]
    result << "@#{slack_user}"
  else
    result << "_#{self[:author]} <#{self[:email]}>_"
  end
  result << ' '
  result << backtick_string(self[:subject])
  result << "\n```\n#{strip_change_id(self[:body])}```" if full && self[:body]
  result
end
to_s_oneline() click to toggle source
# File lib/cookbook-release/commit.rb, line 55
def to_s_oneline
  "#{self[:hash]} #{self[:author]} <#{self[:email]}> #{self[:subject]}"
end

Private Instance Methods

strip_change_id(body) click to toggle source
# File lib/cookbook-release/commit.rb, line 101
def strip_change_id(body)
  body.each_line.reject {|l| l.start_with?('Change-Id') }.join
end