sem_ver_components 0.1.1 → 0.2.3

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: 6ad5f6f5e4ed0306f70bc8967049da98b057cbef64efcbb45708bcc97c05921d
4
- data.tar.gz: a5c86d63ed59ecb62ab18e9a6043bb53f3cafd04058b5c935ae9851765475904
3
+ metadata.gz: 185deb09195baa6edae7e07fbd2bcc12950e68bdca1e7a2d8dac5701bc7ffeac
4
+ data.tar.gz: 201606f2490c02ba2819582bf787c7f8264d577f6c7feeebc1ef9ddfbf41ce0e
5
5
  SHA512:
6
- metadata.gz: b7d91845e1d2c9488c91fc55fc7f33b83097c6a2f2487c5001ba4379e8123df2e412058b2dbdf69e18c1288efd7645e3b0588987017c0bd00086f16e5fdd65de
7
- data.tar.gz: df0a4368d25cceeef753bf31dc66a27442327e39bcd6686e49213144aafadb6f723864761c6700d5b1d9e1d45564efef59357f47b7b66f91cd7e895be70e2a77
6
+ metadata.gz: 9af95c9e8a9fb2377eafaa277cd730f4a11d698484b6794441b49d88e0022faf7aa77a89fe883a4f5489faafc822e1c522c539b3a4f2061c4d428c43a63ea5cb
7
+ data.tar.gz: 373c35bad5e6a655c80fa0a7a2430203309380cf98a645ba99bcefb9bae9cad6fdb777e679dfcfcc0789755e6998c8ad2398d9ab3aca02ba660ff9aa7a9470dc
@@ -4,17 +4,23 @@ 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
- git_from = git_ref
20
+ git_from = git_ref.empty? ? nil : git_ref
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
18
24
  end
19
25
  opts.on('-h', '--help', 'Display this help') do
20
26
  puts opts
@@ -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_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
- 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
@@ -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.1.1'
3
+ VERSION = '0.2.3'
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.1.1
4
+ version: 0.2.3
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-15 00:00:00.000000000 Z
11
+ date: 2021-01-19 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