class Schmersion::Message

Constants

REGEX

Attributes

body[R]
breaking_changes[R]
description[R]
footers[R]
header[R]
pull_request_id[R]
scope[R]
type[R]

Public Class Methods

new(raw_message) click to toggle source
# File lib/schmersion/message.rb, line 19
def initialize(raw_message)
  @raw_message = clean(raw_message)

  parts = @raw_message.split("\n\n").map(&:strip)

  @header = parts.shift
  @paragraphs = parts
  @breaking_changes = []
  @footers = []

  parse_header
  parse_footers

  @body = @paragraphs.join("\n\n")
end

Public Instance Methods

breaking_change?() click to toggle source
# File lib/schmersion/message.rb, line 39
def breaking_change?
  @breaking_change == true ||
    @breaking_changes.size.positive?
end
merge?() click to toggle source
# File lib/schmersion/message.rb, line 44
def merge?
  @raw_message.match?(/\AMerge\s+/)
end
valid?() click to toggle source
# File lib/schmersion/message.rb, line 35
def valid?
  !@type.nil?
end

Private Instance Methods

clean(message) click to toggle source
# File lib/schmersion/message.rb, line 94
def clean(message)
  message.sub(/.*-----END PGP SIGNATURE-----\n\n/m, '')
end
parse_footers() click to toggle source
# File lib/schmersion/message.rb, line 64
def parse_footers
  footer = []
  @paragraphs.last&.each_line do |line|
    case line.strip
    when FOOTER_COLON_REGEX, FOOTER_TICKET_REGEX
      if footer.any?
        handle_footer(footer)
        footer = []
      end
      footer << "#{Regexp.last_match(1)} #{Regexp.last_match(2)}"
    else
      footer << line.strip
    end
  end

  handle_footer(footer) if footer.any?

  @paragraphs.pop if @footers.any? || @breaking_changes.any?
end
parse_header() click to toggle source
# File lib/schmersion/message.rb, line 50
def parse_header
  match = @header.match(REGEX)
  return unless match

  @type = match[1]
  @scope = match[2]
  @description = match[4].strip
  @pull_request_id = match[5]

  @breaking_change = true if match[3] == '!'

  match
end