sem_ver_components 0.1.0 → 0.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a3dfbf1225479b15f20c2d05e722e3b2c55639bd487c2116ea876e9242b761cf
4
- data.tar.gz: db32b6f0e269ace834c2deebbe15a17e7cc6c99912769e48810ef7e6caba8dde
3
+ metadata.gz: 615e48cee99768167dff45e0889a1718250c4a7188a8c7d2ad0ed2dcb193dd1c
4
+ data.tar.gz: 4e4233b956a6e99179c7c5f10dc2f4bba5ade9c90b27b7a3b85326f259ade41c
5
5
  SHA512:
6
- metadata.gz: 56f653d99f3917916f2c9f5d7f13aa3287af6d609736fc530d6b0862edff47205b308cad5e92f32207eee9509cea97116d1241cc5f945c8ff1a78d3c5752ac6a
7
- data.tar.gz: 2cf423be84f46c9657f610c54d47587b8d6c3a1821742d715f91defd65d7aa60ff617881ccdb0b0297739e2da8128eb8e7133992db41bd351dc7d66c217ecab0
6
+ metadata.gz: fe8e33a730795782a2576b065aaa074295afc3f10eabb8f9f7070cbdb93d30e62545f0daab470072b76c8b92ea71cb7729f7a7b75b61c11eaa3109b7b66ebbb9
7
+ data.tar.gz: 1a7572ba83c6b9b643e25bdb13ce41ee7e4bdc0f08bc95392ec68e2941a75bafa22e16f157eba7b7a7a52a2c5110a65870ddf84bef72894f081ccf2691147345
@@ -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_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
@@ -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.1.0'
3
+ VERSION = '0.2.2'
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.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-15 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