class PrChangelog::MergeCommitStrategy

A strategy that given two references will return the filtered commit changes based on the merge commits

Constants

MERGE_COMMIT_FORMAT
TAGGED_TITLE

Attributes

base_ref[R]
current_ref[R]
git_proxy[R]

Public Class Methods

new(base_ref, current_ref, git_proxy = GitProxy.new) click to toggle source
# File lib/pr_changelog/merge_commit_strategy.rb, line 12
def initialize(base_ref, current_ref, git_proxy = GitProxy.new)
  @base_ref    = base_ref
  @current_ref = current_ref
  @git_proxy   = git_proxy
end

Public Instance Methods

format_commit(commit_info) click to toggle source
# File lib/pr_changelog/merge_commit_strategy.rb, line 26
def format_commit(commit_info)
  github_commit_title = commit_info.first
  commit_title = commit_info.last

  pr_number = pull_request_number_for(github_commit_title)
  commit_title.strip!
  match = commit_title.match(TAGGED_TITLE)
  if match
    ChangeLine.new(pr_number, match[:tag], match[:title])
  else
    ChangeLine.new(pr_number, nil, commit_title)
  end
end
parsed_commits() click to toggle source
# File lib/pr_changelog/merge_commit_strategy.rb, line 18
def parsed_commits
  merge_commits_not_merged_into_base_ref
    .split('- ')
    .reject(&:empty?)
    .map { |e| e.split("\n") }
    .select { |pair| pair.count == 2 }
end

Private Instance Methods

merge_commits_not_merged_into_base_ref() click to toggle source
# File lib/pr_changelog/merge_commit_strategy.rb, line 42
def merge_commits_not_merged_into_base_ref
  git_proxy.merge_commits_between(base_ref, current_ref)
end
pull_request_number_for(github_commit_title) click to toggle source
# File lib/pr_changelog/merge_commit_strategy.rb, line 46
def pull_request_number_for(github_commit_title)
  md = github_commit_title.match(MERGE_COMMIT_FORMAT)
  md[:pr_number] if md
end