schmersion 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'semantic'
4
+
5
+ module Schmersion
6
+ class VersionCalculator
7
+
8
+ def initialize(current, commits, **options)
9
+ if current.is_a?(String)
10
+ current = Semantic::Version.new(current)
11
+ end
12
+
13
+ @current = current || Semantic::Version.new('1.0.0')
14
+ @commits = commits
15
+ @options = options
16
+ end
17
+
18
+ def calculate
19
+ if @current.pre && pre?
20
+ new_version = @current.dup
21
+ elsif breaking_changes? && consider_breaking_changes_major? && @current.major.positive?
22
+ new_version = @current.increment!(:major)
23
+ elsif features? || breaking_changes?
24
+ new_version = @current.increment!(:minor)
25
+ else
26
+ new_version = @current.increment!(:patch)
27
+ end
28
+
29
+ add_pre_to_version(new_version) if @options[:pre]
30
+
31
+ new_version
32
+ end
33
+
34
+ private
35
+
36
+ def pre?
37
+ !!@options[:pre]
38
+ end
39
+
40
+ def features?
41
+ @commits.any? { |c| c.message.type == 'feat' }
42
+ end
43
+
44
+ def breaking_changes?
45
+ @commits.any? { |c| c.message.breaking_change? }
46
+ end
47
+
48
+ def consider_breaking_changes_major?
49
+ return false if @options[:breaking_change_not_major]
50
+
51
+ true
52
+ end
53
+
54
+ def add_pre_to_version(version)
55
+ prefix = @options[:pre]
56
+ prefix = 'pre' unless prefix.is_a?(String)
57
+
58
+ current_prefix, current_sequence = @current&.pre&.split('.', 2)
59
+ if current_prefix == prefix
60
+ # If the current version's prefix is the same as the one
61
+ # that's been selected, we'll increment its integer
62
+ pre_sequence = current_sequence.to_i + 1
63
+ else
64
+ pre_sequence = 1
65
+ end
66
+ version.pre = "#{prefix}.#{pre_sequence}"
67
+ version
68
+ end
69
+
70
+ end
71
+ end
metadata ADDED
@@ -0,0 +1,207 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: schmersion
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Adam Cooke
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-08-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: git
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.7.0
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '2.0'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.7.0
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '2.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: semantic
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.5'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.5'
61
+ - !ruby/object:Gem::Dependency
62
+ name: swamp-cli
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.0'
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '1.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rake
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '13.0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '13.0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rspec
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '3.9'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '3.9'
103
+ - !ruby/object:Gem::Dependency
104
+ name: rubocop
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '0.85'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '0.85'
117
+ - !ruby/object:Gem::Dependency
118
+ name: rubocop-performance
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '1.6'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '1.6'
131
+ - !ruby/object:Gem::Dependency
132
+ name: rubocop-rspec
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: '1.39'
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: '1.39'
145
+ description: A tool for generating CHANGELOGs and managing app versioning.
146
+ email:
147
+ - adam@krystal.uk
148
+ executables:
149
+ - schmersion
150
+ extensions: []
151
+ extra_rdoc_files: []
152
+ files:
153
+ - VERSION
154
+ - bin/schmersion
155
+ - cli/help.rb
156
+ - cli/init.rb
157
+ - cli/lint-prepare.rb
158
+ - cli/lint-validate.rb
159
+ - cli/log.rb
160
+ - cli/pending.rb
161
+ - cli/release.rb
162
+ - cli/setup-linting.rb
163
+ - cli/versions.rb
164
+ - lib/schmersion.rb
165
+ - lib/schmersion/commit.rb
166
+ - lib/schmersion/commit_parser.rb
167
+ - lib/schmersion/config.rb
168
+ - lib/schmersion/error.rb
169
+ - lib/schmersion/formatter.rb
170
+ - lib/schmersion/formatters.rb
171
+ - lib/schmersion/formatters/markdown.rb
172
+ - lib/schmersion/formatters/yaml.rb
173
+ - lib/schmersion/helpers.rb
174
+ - lib/schmersion/host.rb
175
+ - lib/schmersion/hosts.rb
176
+ - lib/schmersion/hosts/github.rb
177
+ - lib/schmersion/linter.rb
178
+ - lib/schmersion/message.rb
179
+ - lib/schmersion/message_validator.rb
180
+ - lib/schmersion/releaser.rb
181
+ - lib/schmersion/repo.rb
182
+ - lib/schmersion/schmersion_version.rb
183
+ - lib/schmersion/version.rb
184
+ - lib/schmersion/version_calculator.rb
185
+ homepage: https://github.com/krystal/schmersion
186
+ licenses: []
187
+ metadata: {}
188
+ post_install_message:
189
+ rdoc_options: []
190
+ require_paths:
191
+ - lib
192
+ required_ruby_version: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - ">="
195
+ - !ruby/object:Gem::Version
196
+ version: '2.6'
197
+ required_rubygems_version: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ requirements: []
203
+ rubygems_version: 3.1.2
204
+ signing_key:
205
+ specification_version: 4
206
+ summary: This is a tool for generating CHANGELOGs and managing app versioning.
207
+ test_files: []