sem_ver_components 0.1.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/sem_ver_git +7 -1
- data/lib/sem_ver_components/git_hosting.rb +8 -0
- data/lib/sem_ver_components/git_hostings/bitbucket.rb +49 -0
- data/lib/sem_ver_components/git_hostings/github.rb +30 -0
- data/lib/sem_ver_components/output.rb +4 -1
- data/lib/sem_ver_components/outputs/semantic_release_analyze.rb +3 -0
- data/lib/sem_ver_components/outputs/semantic_release_generate_notes.rb +31 -9
- data/lib/sem_ver_components/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 615e48cee99768167dff45e0889a1718250c4a7188a8c7d2ad0ed2dcb193dd1c
|
4
|
+
data.tar.gz: 4e4233b956a6e99179c7c5f10dc2f4bba5ade9c90b27b7a3b85326f259ade41c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe8e33a730795782a2576b065aaa074295afc3f10eabb8f9f7070cbdb93d30e62545f0daab470072b76c8b92ea71cb7729f7a7b75b61c11eaa3109b7b66ebbb9
|
7
|
+
data.tar.gz: 1a7572ba83c6b9b643e25bdb13ce41ee7e4bdc0f08bc95392ec68e2941a75bafa22e16f157eba7b7a7a52a2c5110a65870ddf84bef72894f081ccf2691147345
|
data/bin/sem_ver_git
CHANGED
@@ -4,18 +4,24 @@ require 'sem_ver_components/plugins'
|
|
4
4
|
require 'sem_ver_components/local_git'
|
5
5
|
require 'sem_ver_components/version'
|
6
6
|
require 'sem_ver_components/output'
|
7
|
+
require 'sem_ver_components/git_hosting'
|
7
8
|
|
8
9
|
# Default values
|
9
10
|
git_repo = '.'
|
10
11
|
git_from = nil
|
11
12
|
git_to = 'HEAD'
|
13
|
+
git_hosting = :github
|
12
14
|
output = :info
|
13
15
|
output_plugins = SemVerComponents::Plugins.new(:outputs)
|
16
|
+
git_hosting_plugins = SemVerComponents::Plugins.new(:git_hostings)
|
14
17
|
OptionParser.new do |opts|
|
15
18
|
opts.banner = "Usage: #{File.basename($0)} [options]"
|
16
19
|
opts.on('-f', '--from GIT_REF', 'Git reference from which commits are to be analyzed (defaults to first commit)') do |git_ref|
|
17
20
|
git_from = git_ref
|
18
21
|
end
|
22
|
+
opts.on('-g', '--git_hosting GIT_HOSTING', "Specify which kind of git hosting is used. Used to format URLs to commits and comparisons. Possible values are #{git_hosting_plugins.list.sort.join(', ')}. (defaults to #{git_hosting})") do |git_hosting_str|
|
23
|
+
git_hosting = git_hosting_str.to_sym
|
24
|
+
end
|
19
25
|
opts.on('-h', '--help', 'Display this help') do
|
20
26
|
puts opts
|
21
27
|
exit 0
|
@@ -40,4 +46,4 @@ raise "Unknown parameters: #{ARGV.join(' ')}" unless ARGV.empty?
|
|
40
46
|
local_git = SemVerComponents::LocalGit.new(git_repo, git_from, git_to)
|
41
47
|
commits_info = local_git.analyze_commits
|
42
48
|
|
43
|
-
output_plugins[output].new(local_git).process(commits_info)
|
49
|
+
output_plugins[output].new(local_git, git_hosting_plugins[git_hosting].new).process(commits_info)
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module SemVerComponents
|
2
|
+
|
3
|
+
module GitHostings
|
4
|
+
|
5
|
+
class Bitbucket < GitHosting
|
6
|
+
|
7
|
+
# Get the URL to a given commit sha
|
8
|
+
#
|
9
|
+
# Parameters::
|
10
|
+
# * *git_url* (String): The git URL
|
11
|
+
# * *commit_sha* (String): The commit sha
|
12
|
+
def commit_url(git_url, commit_sha)
|
13
|
+
"#{public_url(git_url)}/commits/#{commit_sha}"
|
14
|
+
end
|
15
|
+
|
16
|
+
# Get the URL to compare 2 tags
|
17
|
+
#
|
18
|
+
# Parameters::
|
19
|
+
# * *git_url* (String): The git URL
|
20
|
+
# * *tag_1* (String): The first tag
|
21
|
+
# * *tag_2* (String): The second tag
|
22
|
+
def compare_url(git_url, tag_1, tag_2)
|
23
|
+
"#{public_url(git_url)}/compare/commits?targetBranch=refs%2Ftags%2F#{tag_1}&sourceBranch=refs%2Ftags%2F#{tag_2}"
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
# Convert the git remote URL to the public URL
|
29
|
+
#
|
30
|
+
# Parameters::
|
31
|
+
# * *git_url* (String): Git remote URL
|
32
|
+
# Result::
|
33
|
+
# * String: The corresponding public URL
|
34
|
+
def public_url(git_url)
|
35
|
+
if git_url =~ /^(.+)\/scm\/([^\/]+)\/(.+)$/
|
36
|
+
base_url = $1
|
37
|
+
project = $2
|
38
|
+
repo = $3
|
39
|
+
"#{base_url}/projects/#{project}/repos/#{repo}"
|
40
|
+
else
|
41
|
+
git_url
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module SemVerComponents
|
2
|
+
|
3
|
+
module GitHostings
|
4
|
+
|
5
|
+
class Github < GitHosting
|
6
|
+
|
7
|
+
# Get the URL to a given commit sha
|
8
|
+
#
|
9
|
+
# Parameters::
|
10
|
+
# * *git_url* (String): The git URL
|
11
|
+
# * *commit_sha* (String): The commit sha
|
12
|
+
def commit_url(git_url, commit_sha)
|
13
|
+
"#{git_url}/commit/#{commit_sha}"
|
14
|
+
end
|
15
|
+
|
16
|
+
# Get the URL to compare 2 tags
|
17
|
+
#
|
18
|
+
# Parameters::
|
19
|
+
# * *git_url* (String): The git URL
|
20
|
+
# * *tag_1* (String): The first tag
|
21
|
+
# * *tag_2* (String): The second tag
|
22
|
+
def compare_url(git_url, tag_1, tag_2)
|
23
|
+
"#{git_url}/compare/#{tag_1}...#{tag_2}"
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -1,13 +1,16 @@
|
|
1
1
|
module SemVerComponents
|
2
2
|
|
3
|
+
# Base class for all output plugins
|
3
4
|
class Output
|
4
5
|
|
5
6
|
# Constructor
|
6
7
|
#
|
7
8
|
# Parameters::
|
8
9
|
# * *local_git* (LocalGit): The git repository
|
9
|
-
|
10
|
+
# * *git_hosting* (GitHosting): The git hosting to be used for URLs
|
11
|
+
def initialize(local_git, git_hosting)
|
10
12
|
@local_git = local_git
|
13
|
+
@git_hosting = git_hosting
|
11
14
|
end
|
12
15
|
|
13
16
|
end
|
@@ -41,22 +41,46 @@ module SemVerComponents
|
|
41
41
|
end
|
42
42
|
git_url = @local_git.git.remote('origin').url
|
43
43
|
git_url = git_url[0..-5] if git_url.end_with?('.git')
|
44
|
+
# Reference merge commits: merged commits will not be part of the changelog, but their bump level will be taken into account when reporting the merge commit.
|
45
|
+
# List of merged commits' shas, per merge commit sha.
|
46
|
+
# Hash< String, Array< String > >
|
47
|
+
merge_commits = {}
|
48
|
+
commits_info.each do |commit_info|
|
49
|
+
git_commit = commit_info[:commit]
|
50
|
+
git_commit_parents = git_commit.parents
|
51
|
+
# In the case of a merge commit, reference all commits that are part of this merge commit, directly from the graph
|
52
|
+
if git_commit_parents.size > 1
|
53
|
+
git_commit_sha = git_commit.sha
|
54
|
+
merge_commits[git_commit_sha] = @local_git.git_log.between(@local_git.git.merge_base(*git_commit_parents.map(&:sha)).first.sha, git_commit_sha)[1..-1].map(&:sha)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
commits_to_ignore = merge_commits.values.flatten(1).sort.uniq
|
44
58
|
# Group commits per bump level, per component
|
45
59
|
# Hash< String or nil, Hash< Integer, Array<Git::Object::Commit> >
|
46
60
|
commits_per_component = {}
|
47
|
-
# Also reference commits to be ignored: commits that are part of a merge commit
|
48
|
-
merged_commits = []
|
49
61
|
commits_info.each do |commit_info|
|
50
62
|
git_commit = commit_info[:commit]
|
51
|
-
|
63
|
+
git_commit_sha = git_commit.sha
|
64
|
+
# Don't put merged commits as we consider the changelog should contain the merge commit comment.
|
65
|
+
next if commits_to_ignore.include?(git_commit_sha)
|
66
|
+
components_bump_levels = commit_info[:components_bump_levels]
|
67
|
+
# If we are dealing with a merge commit, consider the components' bump levels of the merged commits
|
68
|
+
if merge_commits.key?(git_commit_sha)
|
69
|
+
merge_commits[git_commit_sha].each do |merged_commit_sha|
|
70
|
+
components_bump_levels = components_bump_levels.merge(
|
71
|
+
commits_info.find { |search_commit_info| search_commit_info[:commit].sha == merged_commit_sha }[:components_bump_levels]
|
72
|
+
) do |component, bump_level_1, bump_level_2|
|
73
|
+
[bump_level_1, bump_level_2].max
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
components_bump_levels.each do |component, bump_level|
|
52
78
|
commits_per_component[component] = {} unless commits_per_component.key?(component)
|
53
79
|
commits_per_component[component][bump_level] = [] unless commits_per_component[component].key?(bump_level)
|
54
80
|
commits_per_component[component][bump_level] << git_commit
|
55
81
|
end
|
56
|
-
# In the case of a merge commit, reference all commits that are part of this merge commit, directly from the graph
|
57
|
-
merged_commits.concat(@local_git.git_log.between(@local_git.git.merge_base(*git_commit.parents.map(&:sha)).first.sha, git_commit.sha)[1..-1].map(&:sha)) if git_commit.parents.size > 1
|
58
82
|
end
|
59
|
-
puts "# [v#{new_version}](#{git_url
|
83
|
+
puts "# [v#{new_version}](#{@git_hosting.compare_url(git_url, @local_git.git_from, "v#{new_version}")}) (#{Time.now.utc.strftime('%F %T')})"
|
60
84
|
puts
|
61
85
|
commits_per_component.sort_by { |component, _component_info| component || '' }.each do |(component, component_info)|
|
62
86
|
puts "## #{component.nil? ? 'Global changes' : "Changes for #{component}"}\n" if commits_per_component.size > 1 || !component.nil?
|
@@ -78,8 +102,6 @@ module SemVerComponents
|
|
78
102
|
# Hash< String, String >
|
79
103
|
commit_lines = {}
|
80
104
|
commits.each do |commit|
|
81
|
-
# Don't put merged commits as we consider the changelog should contain the merge commit comment.
|
82
|
-
next if merged_commits.include?(commit.sha)
|
83
105
|
message_lines = commit.message.split("\n")
|
84
106
|
commit_line = message_lines.first
|
85
107
|
if commit_line =~ /^Merge pull request .+$/
|
@@ -90,7 +112,7 @@ module SemVerComponents
|
|
90
112
|
commit_lines[commit_line] = commit.sha
|
91
113
|
end
|
92
114
|
commit_lines.each do |commit_line, commit_sha|
|
93
|
-
puts "* [#{commit_line}](#{git_url
|
115
|
+
puts "* [#{commit_line}](#{@git_hosting.commit_url(git_url, commit_sha)})"
|
94
116
|
end
|
95
117
|
puts
|
96
118
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sem_ver_components
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Muriel Salvan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-01-
|
11
|
+
date: 2021-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: git
|
@@ -62,6 +62,9 @@ extensions: []
|
|
62
62
|
extra_rdoc_files: []
|
63
63
|
files:
|
64
64
|
- bin/sem_ver_git
|
65
|
+
- lib/sem_ver_components/git_hosting.rb
|
66
|
+
- lib/sem_ver_components/git_hostings/bitbucket.rb
|
67
|
+
- lib/sem_ver_components/git_hostings/github.rb
|
65
68
|
- lib/sem_ver_components/local_git.rb
|
66
69
|
- lib/sem_ver_components/output.rb
|
67
70
|
- lib/sem_ver_components/outputs/info.rb
|