class PrChangelog::SquashCommitStrategy

A strategy to get the changes between the two references based on the squash commits

Constants

SQUASH_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/squash_commit_strategy.rb, line 13
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_line) click to toggle source
# File lib/pr_changelog/squash_commit_strategy.rb, line 28
def format_commit(commit_line)
  pr_number = pull_request_number_for(commit_line)
  commit_title = pull_request_title_for(commit_line)
  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/squash_commit_strategy.rb, line 19
def parsed_commits
  commits_not_merged_into_base_ref
    .split('- ')
    .reject(&:empty?)
    .map { |e| e.split("\n") }
    .map(&:first)
    .select { |line| line.match(SQUASH_COMMIT_FORMAT) }
end

Private Instance Methods

commits_not_merged_into_base_ref() click to toggle source
# File lib/pr_changelog/squash_commit_strategy.rb, line 42
def commits_not_merged_into_base_ref
  git_proxy.commits_between(base_ref, current_ref)
end
pull_request_number_for(github_commit_title) click to toggle source
# File lib/pr_changelog/squash_commit_strategy.rb, line 46
def pull_request_number_for(github_commit_title)
  md = github_commit_title.match(SQUASH_COMMIT_FORMAT)
  md[:pr_number] if md
end
pull_request_title_for(github_commit_title) click to toggle source
# File lib/pr_changelog/squash_commit_strategy.rb, line 51
def pull_request_title_for(github_commit_title)
  md = github_commit_title.match(SQUASH_COMMIT_FORMAT)
  md[:title] if md
end