sem_ver_components 0.0.2 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7e8432c849fec7ef379f954d777cfbc2920528a7d1c9e82abf7eba5f7c5b290
4
- data.tar.gz: dbc96e731a6ed258dfc732d6f187387ec76581f2971a5d539fc60c4eb3f4b10b
3
+ metadata.gz: 3d2992cb6bc3198b8bb2d72c34ebde42daf01a1c7aa3804fba463f65570557dc
4
+ data.tar.gz: 8fb753b456aaded0b3f8b806605223c5350bf4c1ac89e802bb35718e69aef8c8
5
5
  SHA512:
6
- metadata.gz: 14d250facc23df60b965ed65c9eaf182a7410473ff4080f6c8b39e7ba0c0ec32a42ff809706bff76bc08c5b46b3fdfa2c215f76844b6a19b9a2eefa478fe568a
7
- data.tar.gz: 116218e895cb0335db40fd5f8458118ec54645a906b963de517894a92f14e3381aa93723753e25feb8a9208d7b2ba793a48f6d666c1dec30d550cadfeca1b60d
6
+ metadata.gz: fe56b8eef4241043ac2980adcbde83961beb215f6a052b0430efb203cc813a8f91113bd5685bfd747092d91c021426e6b0dc603879c3340f394757cfee06f1da
7
+ data.tar.gz: e1ad8f9b10b33cf149f535c85f889ff499c94d9f038900f35545471c050213b5fe8d5b169a46feaf05b10d8a40cbdc0c91d5790ec2a790712ad9d4f68737cec2
@@ -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,8 @@
1
+ module SemVerComponents
2
+
3
+ # Base class for all git hosting plugins
4
+ class GitHosting
5
+
6
+ end
7
+
8
+ end
@@ -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_2}&sourceBranch=refs%2Ftags%2F#{tag_1}"
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
@@ -45,10 +45,10 @@ module SemVerComponents
45
45
  components_bump_levels[component] = [] unless components_bump_levels.key?(component)
46
46
  components_bump_levels[component] <<
47
47
  case commit_type.downcase
48
- when 'feat', 'feature'
49
- 1
50
- when 'break', 'breaking'
48
+ when 'break', 'breaking', 'major'
51
49
  2
50
+ when 'feat', 'feature', 'minor'
51
+ 1
52
52
  else
53
53
  0
54
54
  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
- def initialize(local_git)
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
@@ -14,6 +14,9 @@ module SemVerComponents
14
14
  bump_level = commits_info.map { |commit_info| commit_info[:components_bump_levels].values }.flatten(1).max
15
15
  puts(
16
16
  case bump_level
17
+ when nil
18
+ # No commit. Return nothing to bump.
19
+ ''
17
20
  when 0
18
21
  'patch'
19
22
  when 1
@@ -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
- commit_info[:components_bump_levels].each do |component, bump_level|
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}/compare/#{@local_git.git_from}...v#{new_version}) (#{Time.now.utc.strftime('%F %T')})"
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}/commit/#{commit_sha})"
115
+ puts "* [#{commit_line}](#{@git_hosting.commit_url(git_url, commit_sha)})"
94
116
  end
95
117
  puts
96
118
  end
@@ -1,5 +1,5 @@
1
1
  module SemVerComponents
2
2
 
3
- VERSION = '0.0.2'
3
+ VERSION = '0.2.1'
4
4
 
5
5
  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.0.2
4
+ version: 0.2.1
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-14 00:00:00.000000000 Z
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