class MrBump::Change

This class acts parses merge information from a commit message string

Constants

BRANCH_FMT
BRANCH_TYPES
FORMATS
MERGE_MANUAL_FMT
MERGE_PR_FMT
MERGE_REGEX

Attributes

branch_name[R]
branch_type[R]
comment_lines[R]
config[R]
dev_id[R]
pr_number[R]

Public Class Methods

from_gitlog(config, commit_msg, comment_lines) click to toggle source
# File lib/mr_bump/change.rb, line 58
def self.from_gitlog(config, commit_msg, comment_lines)
  matches = MERGE_REGEX.match(commit_msg)
  raise ArgumentError, "Couldn't extract merge information from commit message " \
                       "'#{commit_msg}'" unless matches
  Change.new(
    config,
    (matches['branch_type'] || 'task').capitalize,
    matches['branch_name'],
    matches['dev_id'],
    matches['pr_number'],
    comment_lines
  )
end
from_md(config, md) click to toggle source
# File lib/mr_bump/change.rb, line 72
def self.from_md(config, md)
  regex = RegexTemplate.render(config['markdown_template'], FORMATS, 'i')
  matches = regex.match md
  raise ArgumentError, "Couldn't extract merge information from markdown " \
                       "'#{md}'" unless matches
  # Convert whole string matches into smaller individual matches
  match_hash = FORMATS.map do |key, reg|
    key = key.to_s
    find = matches.names.include?(key) ? matches[key] : ''
    [key.to_s, find.scan(Regexp.new(reg)).reject(&:empty?)]
  end
  match_hash = Hash[match_hash]

  comment_lines = match_hash['first_comment_line'] + match_hash['comment_body']

  Change.new(
    config,
    (match_hash['branch_type'].first || 'task').capitalize,
    nil,
    match_hash['dev_id'].first,
    match_hash['pr_number'].first,
    comment_lines
  )
end
new(config, branch_type = nil, branch_name = nil, dev_id = nil, pr_number = nil, comment_lines = nil) click to toggle source
# File lib/mr_bump/change.rb, line 28
def initialize(config, branch_type = nil, branch_name = nil, dev_id = nil, pr_number = nil, comment_lines = nil)
  @config = config
  @branch_type = (branch_type || 'Task')
  @branch_name = branch_name
  @dev_id = dev_id
  @pr_number = pr_number || ''
  @comment_lines = Array(comment_lines)
  unless @comment_lines.empty? || @dev_id.nil?
    id = Regexp.escape(@dev_id)
    prefix_regex = /^(\[#{id}\]|\(#{id}\)|#{id})\s*([:\-]\s*)?/
    @comment_lines[0] = @comment_lines[0].sub(prefix_regex, '')
  end
end

Public Instance Methods

comment_body() click to toggle source
# File lib/mr_bump/change.rb, line 50
def comment_body
  comment_lines[1..-1] if comment_lines.size > 1
end
first_comment_line() click to toggle source
# File lib/mr_bump/change.rb, line 46
def first_comment_line
  comment_lines.first
end
has_no_detail?() click to toggle source
# File lib/mr_bump/change.rb, line 42
def has_no_detail?
  comment_lines.empty? && dev_id.nil?
end
to_md() click to toggle source
# File lib/mr_bump/change.rb, line 54
def to_md
  Mustache.render(config['markdown_template'], self)
end