Class: PrChangelog::MergeCommitStrategy

Inherits:
BaseCommitStrategy show all
Defined in:
lib/pr_changelog/merge_commit_strategy.rb

Overview

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

Constant Summary collapse

MERGE_COMMIT_FORMAT =
/Merge pull request (?<pr_number>#\d+) .*/.freeze
TAGGED_TITLE =
/^(?<tag>.+):\s*(?<title>.+)$/.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_ref, current_ref, git_proxy = GitProxy.new) ⇒ MergeCommitStrategy

Returns a new instance of MergeCommitStrategy.



12
13
14
15
16
# 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

Instance Attribute Details

#base_refObject (readonly)

Returns the value of attribute base_ref.



10
11
12
# File 'lib/pr_changelog/merge_commit_strategy.rb', line 10

def base_ref
  @base_ref
end

#current_refObject (readonly)

Returns the value of attribute current_ref.



10
11
12
# File 'lib/pr_changelog/merge_commit_strategy.rb', line 10

def current_ref
  @current_ref
end

#git_proxyObject (readonly)

Returns the value of attribute git_proxy.



10
11
12
# File 'lib/pr_changelog/merge_commit_strategy.rb', line 10

def git_proxy
  @git_proxy
end

Instance Method Details

#format_commit(commit_info) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# 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_commitsObject



18
19
20
21
22
23
24
# File 'lib/pr_changelog/merge_commit_strategy.rb', line 18

def parsed_commits
  merge_commits_not_merged_into_base_ref
    .split("\n- ")
    .reject(&:empty?)
    .map { |e| e.split("\n") }
    .select { |pair| pair.count == 2 }
end