Class: PrChangelog::SquashCommitStrategy

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

Overview

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

Constant Summary collapse

SQUASH_COMMIT_FORMAT =
/^GitHub( Enterprise)?: (?<title>.+) \((?<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) ⇒ SquashCommitStrategy

Returns a new instance of SquashCommitStrategy.



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

Instance Attribute Details

#base_refObject (readonly)

Returns the value of attribute base_ref.



11
12
13
# File 'lib/pr_changelog/squash_commit_strategy.rb', line 11

def base_ref
  @base_ref
end

#current_refObject (readonly)

Returns the value of attribute current_ref.



11
12
13
# File 'lib/pr_changelog/squash_commit_strategy.rb', line 11

def current_ref
  @current_ref
end

#git_proxyObject (readonly)

Returns the value of attribute git_proxy.



11
12
13
# File 'lib/pr_changelog/squash_commit_strategy.rb', line 11

def git_proxy
  @git_proxy
end

Instance Method Details

#format_commit(commit_line) ⇒ Object



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



19
20
21
22
23
24
25
26
# 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