fastlane-plugin-semantic_versioning 1.0.0 → 2.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 85cd9cae201bc1df61f042591928d143e3be6b16f2118af031d8277872bb2602
4
- data.tar.gz: a1bc72d14b4866bf874ff0f1ad0b47e965baa895bcfed5ded778120e17a66ec8
3
+ metadata.gz: d8564caab2d111a1099b9c876d794673d124b89fea24c4d6ef3b7886f096e9c5
4
+ data.tar.gz: cf726334226530356e0180b112080ffb30bce81aa6709c9b072ac9d152070234
5
5
  SHA512:
6
- metadata.gz: 51ea808a889665240814d26ce939f1c006c9bd03b6544a3a289e38afb460668dc51e4f723a4507b6a8f3a3112b71bb1bd407bfd2da5df513a22b085b3053337e
7
- data.tar.gz: 0227ac5c1726f2e9954f9d272bb36e99fbf83af5280e7831ffb823ccd44ed32f1b5528c57188a4bd927956e9cdcbd7940183604369fcbcf6c95e830c1e9cd85c
6
+ metadata.gz: 7119102889ba20b58d153f92cbd9ae6d7b118c3e01c963773bfd0a1320976f5a55e336e9356822f2f64e2bc5be6e08fb6b61151ac005fc6c73fbdc1867ee5b90
7
+ data.tar.gz: bf0e95b1a39df59564cf3b47e6418fb8cc754d7a6f53b0ccce793f1e93557336e5ce988a17d711f7b26a9acaf8672ee0183226013867af3e39cdd0f48abe038c
@@ -18,6 +18,7 @@ module Fastlane
18
18
  params[:allowed_types].map!(&:to_sym)
19
19
  params[:bump_map].transform_keys!(&:to_sym)
20
20
  params[:bump_map].transform_values!(&:to_sym)
21
+ params[:force_type] = params[:force_type]&.to_sym
21
22
 
22
23
  UI.message("The semantic_versioning plugin is working!")
23
24
 
@@ -26,10 +27,11 @@ module Fastlane
26
27
 
27
28
  commits = Helper::SemanticVersioningHelper.git_commits(
28
29
  from: Helper::SemanticVersioningHelper.git_tag_exists?(formatted_tag) ? formatted_tag : nil,
29
- allowed_types: params[:allowed_types]
30
+ allowed_types: params[:allowed_types],
31
+ bump_map: params[:bump_map]
30
32
  )
31
33
 
32
- bump_type = Helper::SemanticVersioningHelper.bump_type(commits: commits, bump_map: params[:bump_map])
34
+ bump_type = Helper::SemanticVersioningHelper.bump_type(commits: commits, force_type: params[:force_type])
33
35
  new_version = Helper::SemanticVersioningHelper.increase_version(current_version: current_version, bump_type: bump_type)
34
36
  new_changelog = Helper::SemanticVersioningHelper.build_changelog(version: new_version, commits: commits, type_map: params[:type_map])
35
37
  bumpable = current_version != new_version
@@ -88,6 +90,12 @@ module Fastlane
88
90
  default_value: { breaking: :major, feat: :minor, fix: :patch },
89
91
  is_string: false,
90
92
  verify_block: ->(value) { verify_bump_map(value) }),
93
+ FastlaneCore::ConfigItem.new(key: :force_type,
94
+ env_name: "SEMANTIC_VERSIONING_FORCE_TYPE",
95
+ description: "Force a minimum bump type",
96
+ optional: true,
97
+ default_value: nil,
98
+ type: String),
91
99
  FastlaneCore::ConfigItem.new(key: :tag_format,
92
100
  env_name: "SEMANTIC_VERSIONING_TAG_FORMAT",
93
101
  description: "The format for the git tag",
@@ -27,36 +27,53 @@ module Fastlane
27
27
  end
28
28
 
29
29
  # Retrieves git commits and returns them grouped by type
30
- def self.git_commits(from:, allowed_types:)
30
+ def self.git_commits(from:, allowed_types:, bump_map:)
31
31
  logs = from ? git.log(-1).between(from) : git.log(-1)
32
32
  logs.reverse_each.map do |commit|
33
- parse_conventional_commit(commit: commit, allowed_types: allowed_types)
33
+ parse_conventional_commit(commit: commit, allowed_types: allowed_types, bump_map: bump_map)
34
34
  end.compact
35
35
  end
36
36
 
37
- def self.group_commits(commits:, allowed_types:)
38
- result = allowed_types.to_h { |type| [type, []] }
37
+ def self.parse_conventional_commit(commit:, allowed_types:, bump_map:)
38
+ types = allowed_types.join("|")
39
+ commit.message.match(/^(?<type>#{types})(\((?<scope>\S+)\))?(?<major>!)?:\s+(?<subject>[^\n\r]+)(\z|\n\n(?<body>.*\z))/m) do |match|
40
+ cc = {
41
+ type: match[:type].to_sym,
42
+ major: !!match[:major],
43
+ scope: match[:scope],
44
+ subject: match[:subject],
45
+ body: match[:body],
46
+ breaking: nil,
47
+ original_message: commit.message
48
+ }
39
49
 
40
- commits.each do |commit|
41
- if commit[:breaking] && allowed_types.include?(:breaking)
42
- result[:breaking] << commit
50
+ match[:body]&.match(/^BREAKING CHANGE?: (.+)\z/) do |breaking|
51
+ cc[:breaking] = breaking[1]
43
52
  end
44
- next unless allowed_types.include?(commit[:type])
45
53
 
46
- # If the breaking change is made from the actual feature subject, don't repeat it.
47
- next if commit[:breaking] == commit[:subject]
54
+ cc[:bump] = commit_bump_type(commit: cc, bump_map: bump_map)
48
55
 
49
- result[commit[:type]] << commit
56
+ return cc
50
57
  end
58
+ end
51
59
 
52
- return result
60
+ def self.commit_bump_type(commit:, bump_map:)
61
+ return :major if commit[:major]
62
+
63
+ return bump_map[:breaking] if commit[:breaking]
64
+
65
+ return bump_map[commit[:type]]
53
66
  end
54
67
 
55
- def self.bump_type(commits:, bump_map:)
56
- result = nil
68
+ def self.bump_type(commits:, force_type: nil)
69
+ return force_type if force_type == :major # can't go any higher
70
+
71
+ result = force_type
57
72
 
58
73
  commits.each do |commit|
59
- bump_type = commit[:breaking] ? bump_map[:breaking] : bump_map[commit[:type]]
74
+ return :major if commit[:major]
75
+
76
+ bump_type = commit[:bump]
60
77
  if bump_type == :major
61
78
  return :major
62
79
  elsif bump_type == :minor
@@ -69,29 +86,26 @@ module Fastlane
69
86
  return result
70
87
  end
71
88
 
72
- def self.parse_conventional_commit(commit:, allowed_types:)
73
- types = allowed_types.join("|")
74
- commit.message.match(/^(?<type>#{types})(\((?<scope>\S+)\))?(?<breaking>!)?:\s+(?<subject>[^\n\r]+)(\z|\n\n(?<body>.*\z))/m) do |match|
75
- unless allowed_types.include?(match[:type].to_sym)
76
- UI.important("Commit #{commit.sha} has invalid type: #{match[:type]}. Ignoring")
77
- break
78
- end
89
+ def self.group_commits(commits:, allowed_types:)
90
+ result = allowed_types.to_h { |type| [type, []] }
91
+ result[:none] = []
79
92
 
80
- cc = {
81
- type: match[:type].to_sym,
82
- scope: match[:scope],
83
- subject: match[:subject],
84
- body: match[:body],
85
- breaking: match[:breaking] ? match[:subject] : nil,
86
- original_message: commit.message
87
- }
93
+ commits.each do |commit|
94
+ if commit[:breaking] && allowed_types.include?(:breaking)
95
+ result[:breaking] << commit
96
+ end
88
97
 
89
- match[:body]&.match(/^BREAKING CHANGE?: (.+)\z/) do |breaking|
90
- cc[:breaking] = breaking[1]
98
+ if commit[:major] && !allowed_types.include?(commit[:type])
99
+ result[:none] << commit
100
+ next
91
101
  end
92
102
 
93
- return cc
103
+ next unless allowed_types.include?(commit[:type])
104
+
105
+ result[commit[:type]] << commit
94
106
  end
107
+
108
+ return result
95
109
  end
96
110
 
97
111
  def self.increase_version(current_version:, bump_type:)
@@ -123,7 +137,7 @@ module Fastlane
123
137
  grouped_commits.each do |key, section_commits|
124
138
  next unless section_commits.any?
125
139
 
126
- lines << "### #{type_map[key]}:"
140
+ lines << "### #{type_map[key]}:" if key != :none
127
141
  lines << ""
128
142
 
129
143
  section_commits.each do |commit|
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module SemanticVersioning
3
- VERSION = "1.0.0"
3
+ VERSION = "2.0.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-semantic_versioning
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karsten Silkenbäumer