pr_changelog 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/pr_changelog.rb +3 -0
- data/lib/pr_changelog/base_commit_strategy.rb +14 -0
- data/lib/pr_changelog/change_line.rb +1 -1
- data/lib/pr_changelog/cli.rb +16 -3
- data/lib/pr_changelog/config.rb +5 -0
- data/lib/pr_changelog/git_proxy.rb +4 -0
- data/lib/pr_changelog/merge_commit_strategy.rb +51 -0
- data/lib/pr_changelog/not_released_changes.rb +5 -38
- data/lib/pr_changelog/releases.rb +13 -2
- data/lib/pr_changelog/squash_commit_strategy.rb +56 -0
- data/lib/pr_changelog/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c723eb18c8ee6a3d5dcb25e055fe439105b7849d
|
4
|
+
data.tar.gz: 74fcb7ed7d34c5b2a5b3aa37536db82449508689
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a12c7d8e34491ac360cb9ef7e945c802658b73bf3e53e23e01385955f4c1340bba39c408dc0ff8b9e7f097fb933e09bd6039a01744895008ca8ec78f34925ab8
|
7
|
+
data.tar.gz: 1668613081f37fa6e4b3bd3daa9921fdb0498acc6796b87c1af20bb32f92186d203326a4af936bdd743e7d39d7a3bd991f510442fc6650ddcbde51931182f278
|
data/Gemfile.lock
CHANGED
data/lib/pr_changelog.rb
CHANGED
@@ -10,6 +10,9 @@ require 'pr_changelog/git_proxy'
|
|
10
10
|
require 'pr_changelog/tag'
|
11
11
|
require 'pr_changelog/change_line'
|
12
12
|
require 'pr_changelog/grouped_changes'
|
13
|
+
require 'pr_changelog/base_commit_strategy'
|
14
|
+
require 'pr_changelog/merge_commit_strategy'
|
15
|
+
require 'pr_changelog/squash_commit_strategy'
|
13
16
|
require 'pr_changelog/not_released_changes'
|
14
17
|
|
15
18
|
# Main module
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PrChangelog
|
4
|
+
# A "protocol"-like base class for the extracting the change commit strategies
|
5
|
+
class BaseCommitStrategy
|
6
|
+
def parsed_commits
|
7
|
+
raise 'Not implemented'
|
8
|
+
end
|
9
|
+
|
10
|
+
def format_commit(_commit_line)
|
11
|
+
raise 'Not implemented'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/pr_changelog/cli.rb
CHANGED
@@ -11,6 +11,7 @@ module PrChangelog
|
|
11
11
|
-h, --help\tShow this help
|
12
12
|
-l, --last-release\tSets from_reference and to_reference to the last release and the previous one
|
13
13
|
--format FORMAT_NAME\t(default "plain"), options ("pretty", "plain")
|
14
|
+
--strategy STRATEGY_NAME\tIs the strategy used to merge pull requests (default "merge"), options ("merge", "squash").
|
14
15
|
|
15
16
|
[Examples]
|
16
17
|
|
@@ -33,7 +34,7 @@ module PrChangelog
|
|
33
34
|
class HelpWanted < StandardError
|
34
35
|
end
|
35
36
|
|
36
|
-
attr_reader :format, :from_reference, :to_reference
|
37
|
+
attr_reader :format, :strategy, :from_reference, :to_reference
|
37
38
|
|
38
39
|
class CannotDetermineRelease < StandardError
|
39
40
|
end
|
@@ -44,6 +45,8 @@ module PrChangelog
|
|
44
45
|
|
45
46
|
@format = args.value_for('--format') || PrChangelog.config.default_format
|
46
47
|
|
48
|
+
@strategy = args.value_for('--strategy') || PrChangelog.config.default_strategy
|
49
|
+
|
47
50
|
@releases = releases || Releases.new
|
48
51
|
|
49
52
|
@from_reference, @to_reference = args.last(2)
|
@@ -62,9 +65,19 @@ module PrChangelog
|
|
62
65
|
raise InvalidInputs
|
63
66
|
end
|
64
67
|
|
68
|
+
def build_strategy
|
69
|
+
if strategy == 'merge'
|
70
|
+
MergeCommitStrategy.new(from_reference, to_reference)
|
71
|
+
elsif strategy == 'squash'
|
72
|
+
SquashCommitStrategy.new(from_reference, to_reference)
|
73
|
+
else
|
74
|
+
raise "Strategy '#{strategy}' not recognized."
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
65
78
|
def run
|
66
|
-
changes = NotReleasedChanges.new(
|
67
|
-
puts "## Changes since #{from_reference} to #{to_reference}\n\n"
|
79
|
+
changes = NotReleasedChanges.new(build_strategy)
|
80
|
+
puts "## Changes since #{from_reference} to #{to_reference} (#{strategy})\n\n"
|
68
81
|
|
69
82
|
if format == 'pretty'
|
70
83
|
puts changes.grouped_formatted_changelog
|
data/lib/pr_changelog/config.rb
CHANGED
@@ -7,6 +7,7 @@ module PrChangelog
|
|
7
7
|
class Config
|
8
8
|
DEFAULTS = {
|
9
9
|
format: 'plain',
|
10
|
+
strategy: 'merge',
|
10
11
|
tags: [
|
11
12
|
{
|
12
13
|
prefix: 'feature',
|
@@ -49,6 +50,10 @@ module PrChangelog
|
|
49
50
|
loaded_data[:format] || DEFAULTS[:format]
|
50
51
|
end
|
51
52
|
|
53
|
+
def default_strategy
|
54
|
+
loaded_data[:strategy] || DEFAULTS[:strategy]
|
55
|
+
end
|
56
|
+
|
52
57
|
def tags
|
53
58
|
loaded_data[:tags] || DEFAULTS[:tags]
|
54
59
|
end
|
@@ -5,6 +5,10 @@ module PrChangelog
|
|
5
5
|
class GitProxy
|
6
6
|
LOG_FORMAT = '- %cn: %s%n%w(80, 2, 2)%b'
|
7
7
|
|
8
|
+
def commits_between(base_ref, current_ref)
|
9
|
+
`git log #{base_ref}..#{current_ref} --format='#{LOG_FORMAT}'`
|
10
|
+
end
|
11
|
+
|
8
12
|
def merge_commits_between(base_ref, current_ref)
|
9
13
|
`git log --merges #{base_ref}..#{current_ref} --format='#{LOG_FORMAT}'`
|
10
14
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PrChangelog
|
4
|
+
# A strategy that given two references will return the filtered commit changes
|
5
|
+
# based on the merge commits
|
6
|
+
class MergeCommitStrategy < BaseCommitStrategy
|
7
|
+
MERGE_COMMIT_FORMAT = /Merge pull request (?<pr_number>#\d+) .*/.freeze
|
8
|
+
TAGGED_TITLE = /^(?<tag>.+):\s*(?<title>.+)$/.freeze
|
9
|
+
|
10
|
+
attr_reader :base_ref, :current_ref, :git_proxy
|
11
|
+
|
12
|
+
def initialize(base_ref, current_ref, git_proxy = GitProxy.new)
|
13
|
+
@base_ref = base_ref
|
14
|
+
@current_ref = current_ref
|
15
|
+
@git_proxy = git_proxy
|
16
|
+
end
|
17
|
+
|
18
|
+
def parsed_commits
|
19
|
+
merge_commits_not_merged_into_base_ref
|
20
|
+
.split('- ')
|
21
|
+
.reject(&:empty?)
|
22
|
+
.map { |e| e.split("\n") }
|
23
|
+
.select { |pair| pair.count == 2 }
|
24
|
+
end
|
25
|
+
|
26
|
+
def format_commit(commit_info)
|
27
|
+
github_commit_title = commit_info.first
|
28
|
+
commit_title = commit_info.last
|
29
|
+
|
30
|
+
pr_number = pull_request_number_for(github_commit_title)
|
31
|
+
commit_title.strip!
|
32
|
+
match = commit_title.match(TAGGED_TITLE)
|
33
|
+
if match
|
34
|
+
ChangeLine.new(pr_number, match[:tag], match[:title])
|
35
|
+
else
|
36
|
+
ChangeLine.new(pr_number, nil, commit_title)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def merge_commits_not_merged_into_base_ref
|
43
|
+
git_proxy.merge_commits_between(base_ref, current_ref)
|
44
|
+
end
|
45
|
+
|
46
|
+
def pull_request_number_for(github_commit_title)
|
47
|
+
md = github_commit_title.match(MERGE_COMMIT_FORMAT)
|
48
|
+
md[:pr_number] if md
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -4,15 +4,10 @@ module PrChangelog
|
|
4
4
|
# Calculates a list of not released changes from `base_ref` to `current_ref`
|
5
5
|
# those changes consist of the merged pull-request title
|
6
6
|
class NotReleasedChanges
|
7
|
-
|
8
|
-
TAGGED_TITLE = /^(?<tag>.+):\s*(?<title>.+)$/.freeze
|
7
|
+
attr_reader :commits_strategy
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
def initialize(base_ref, current_ref, git_proxy = GitProxy.new)
|
13
|
-
@base_ref = base_ref
|
14
|
-
@current_ref = current_ref
|
15
|
-
@git_proxy = git_proxy
|
9
|
+
def initialize(commits_strategy)
|
10
|
+
@commits_strategy = commits_strategy
|
16
11
|
end
|
17
12
|
|
18
13
|
def emoji_tags
|
@@ -48,37 +43,9 @@ module PrChangelog
|
|
48
43
|
end
|
49
44
|
|
50
45
|
def parsed_change_list
|
51
|
-
@parsed_change_list ||=
|
52
|
-
|
46
|
+
@parsed_change_list ||= commits_strategy.parsed_commits.map do |commit_info|
|
47
|
+
commits_strategy.format_commit(commit_info)
|
53
48
|
end
|
54
49
|
end
|
55
|
-
|
56
|
-
def parsed_merge_commits
|
57
|
-
merge_commits_not_merged_into_base_ref
|
58
|
-
.split('- ')
|
59
|
-
.reject(&:empty?)
|
60
|
-
.map { |e| e.split("\n") }
|
61
|
-
.select { |pair| pair.count == 2 }
|
62
|
-
end
|
63
|
-
|
64
|
-
def format_merge_commit(github_commit_title, commit_title)
|
65
|
-
pr_number = pull_request_number_for(github_commit_title)
|
66
|
-
commit_title.strip!
|
67
|
-
match = commit_title.match(TAGGED_TITLE)
|
68
|
-
if match
|
69
|
-
ChangeLine.new(pr_number, match[:tag], match[:title])
|
70
|
-
else
|
71
|
-
ChangeLine.new(pr_number, nil, commit_title)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def merge_commits_not_merged_into_base_ref
|
76
|
-
git_proxy.merge_commits_between(base_ref, current_ref)
|
77
|
-
end
|
78
|
-
|
79
|
-
def pull_request_number_for(github_commit_title)
|
80
|
-
md = github_commit_title.match(MERGE_COMMIT_FORMAT)
|
81
|
-
md[:pr_number] if md
|
82
|
-
end
|
83
50
|
end
|
84
51
|
end
|
@@ -9,11 +9,22 @@ module PrChangelog
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def last_release
|
12
|
-
|
12
|
+
sorted_tags.last
|
13
13
|
end
|
14
14
|
|
15
15
|
def last_release_pair
|
16
|
-
|
16
|
+
sorted_tags.last(2)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def sorted_tags
|
22
|
+
git_proxy.git_tags_list.sort_by { |tag| tag_value(tag) }
|
23
|
+
end
|
24
|
+
|
25
|
+
def tag_value(tag)
|
26
|
+
components = tag.split('.')
|
27
|
+
components[0].to_i * 100_000 + components[1].to_i * 1_000 + components[2].to_i
|
17
28
|
end
|
18
29
|
end
|
19
30
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module PrChangelog
|
5
|
+
# A strategy to get the changes between the two references based on the
|
6
|
+
# squash commits
|
7
|
+
class SquashCommitStrategy < BaseCommitStrategy
|
8
|
+
SQUASH_COMMIT_FORMAT = /^GitHub( Enterprise)?: (?<title>.+) \((?<pr_number>#\d+)\)$/.freeze
|
9
|
+
TAGGED_TITLE = /^(?<tag>[^:]+):\s*(?<title>.+)$/.freeze
|
10
|
+
|
11
|
+
attr_reader :base_ref, :current_ref, :git_proxy
|
12
|
+
|
13
|
+
def initialize(base_ref, current_ref, git_proxy = GitProxy.new)
|
14
|
+
@base_ref = base_ref
|
15
|
+
@current_ref = current_ref
|
16
|
+
@git_proxy = git_proxy
|
17
|
+
end
|
18
|
+
|
19
|
+
def parsed_commits
|
20
|
+
commits_not_merged_into_base_ref
|
21
|
+
.split('- ')
|
22
|
+
.reject(&:empty?)
|
23
|
+
.map { |e| e.split("\n") }
|
24
|
+
.map(&:first)
|
25
|
+
.select { |line| line.match(SQUASH_COMMIT_FORMAT) }
|
26
|
+
end
|
27
|
+
|
28
|
+
def format_commit(commit_line)
|
29
|
+
pr_number = pull_request_number_for(commit_line)
|
30
|
+
commit_title = pull_request_title_for(commit_line)
|
31
|
+
commit_title.strip!
|
32
|
+
match = commit_title.match(TAGGED_TITLE)
|
33
|
+
if match
|
34
|
+
ChangeLine.new(pr_number, match[:tag], match[:title])
|
35
|
+
else
|
36
|
+
ChangeLine.new(pr_number, nil, commit_title)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def commits_not_merged_into_base_ref
|
43
|
+
git_proxy.commits_between(base_ref, current_ref)
|
44
|
+
end
|
45
|
+
|
46
|
+
def pull_request_number_for(github_commit_title)
|
47
|
+
md = github_commit_title.match(SQUASH_COMMIT_FORMAT)
|
48
|
+
md[:pr_number] if md
|
49
|
+
end
|
50
|
+
|
51
|
+
def pull_request_title_for(github_commit_title)
|
52
|
+
md = github_commit_title.match(SQUASH_COMMIT_FORMAT)
|
53
|
+
md[:title] if md
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/pr_changelog/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pr_changelog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Felipe Espinoza
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -87,6 +87,7 @@ files:
|
|
87
87
|
- bin/setup
|
88
88
|
- exe/pr_changelog
|
89
89
|
- lib/pr_changelog.rb
|
90
|
+
- lib/pr_changelog/base_commit_strategy.rb
|
90
91
|
- lib/pr_changelog/change_line.rb
|
91
92
|
- lib/pr_changelog/cli.rb
|
92
93
|
- lib/pr_changelog/cli/args.rb
|
@@ -94,8 +95,10 @@ files:
|
|
94
95
|
- lib/pr_changelog/extensions/string.rb
|
95
96
|
- lib/pr_changelog/git_proxy.rb
|
96
97
|
- lib/pr_changelog/grouped_changes.rb
|
98
|
+
- lib/pr_changelog/merge_commit_strategy.rb
|
97
99
|
- lib/pr_changelog/not_released_changes.rb
|
98
100
|
- lib/pr_changelog/releases.rb
|
101
|
+
- lib/pr_changelog/squash_commit_strategy.rb
|
99
102
|
- lib/pr_changelog/tag.rb
|
100
103
|
- lib/pr_changelog/version.rb
|
101
104
|
- pr_changelog.gemspec
|