create_github_release 1.1.0 → 1.2.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 +4 -4
- data/.yardopts +1 -0
- data/CHANGELOG.md +8 -0
- data/README.md +156 -38
- data/Rakefile +6 -6
- data/create_github_release.gemspec +3 -3
- data/exe/create-github-release +1 -1
- data/lib/create_github_release/assertions/bundle_is_up_to_date.rb +1 -1
- data/lib/create_github_release/assertions/gh_authenticated.rb +1 -1
- data/lib/create_github_release/assertions/gh_command_exists.rb +1 -1
- data/lib/create_github_release/assertions/git_command_exists.rb +1 -1
- data/lib/create_github_release/assertions/in_git_repo.rb +1 -1
- data/lib/create_github_release/assertions/in_repo_root_directory.rb +1 -1
- data/lib/create_github_release/assertions/local_and_remote_on_same_commit.rb +1 -1
- data/lib/create_github_release/assertions/local_release_branch_does_not_exist.rb +1 -1
- data/lib/create_github_release/assertions/no_staged_changes.rb +1 -1
- data/lib/create_github_release/assertions/no_uncommitted_changes.rb +1 -1
- data/lib/create_github_release/assertions/on_default_branch.rb +1 -1
- data/lib/create_github_release/assertions/remote_release_branch_does_not_exist.rb +1 -1
- data/lib/create_github_release/assertions/remote_release_tag_does_not_exist.rb +1 -1
- data/lib/create_github_release/command_line/options.rb +151 -0
- data/lib/create_github_release/command_line/parser.rb +253 -0
- data/lib/create_github_release/command_line/validations.rb +293 -0
- data/lib/create_github_release/command_line/validator.rb +93 -0
- data/lib/create_github_release/command_line.rb +43 -0
- data/lib/create_github_release/project.rb +115 -55
- data/lib/create_github_release/release_assertions.rb +1 -1
- data/lib/create_github_release/release_tasks.rb +1 -1
- data/lib/create_github_release/tasks/commit_release.rb +1 -1
- data/lib/create_github_release/tasks/create_github_release.rb +1 -1
- data/lib/create_github_release/tasks/create_release_branch.rb +1 -1
- data/lib/create_github_release/tasks/create_release_pull_request.rb +1 -1
- data/lib/create_github_release/tasks/create_release_tag.rb +1 -1
- data/lib/create_github_release/tasks/push_release.rb +1 -1
- data/lib/create_github_release/tasks/update_changelog.rb +1 -1
- data/lib/create_github_release/tasks/update_version.rb +1 -1
- data/lib/create_github_release/version.rb +1 -1
- data/lib/create_github_release.rb +1 -2
- metadata +10 -34
- data/lib/create_github_release/command_line_options.rb +0 -378
- data/lib/create_github_release/command_line_parser.rb +0 -229
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: create_github_release
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: semverify
|
@@ -108,20 +108,6 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '1.36'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: ruby-debug-ide
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - "~>"
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0.7'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - "~>"
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '0.7'
|
125
111
|
- !ruby/object:Gem::Dependency
|
126
112
|
name: simplecov
|
127
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -150,20 +136,6 @@ dependencies:
|
|
150
136
|
- - "~>"
|
151
137
|
- !ruby/object:Gem::Version
|
152
138
|
version: '0.8'
|
153
|
-
- !ruby/object:Gem::Dependency
|
154
|
-
name: solargraph
|
155
|
-
requirement: !ruby/object:Gem::Requirement
|
156
|
-
requirements:
|
157
|
-
- - "~>"
|
158
|
-
- !ruby/object:Gem::Version
|
159
|
-
version: '0.49'
|
160
|
-
type: :development
|
161
|
-
prerelease: false
|
162
|
-
version_requirements: !ruby/object:Gem::Requirement
|
163
|
-
requirements:
|
164
|
-
- - "~>"
|
165
|
-
- !ruby/object:Gem::Version
|
166
|
-
version: '0.49'
|
167
139
|
- !ruby/object:Gem::Dependency
|
168
140
|
name: timecop
|
169
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -250,8 +222,11 @@ files:
|
|
250
222
|
- lib/create_github_release/backtick_debug.rb
|
251
223
|
- lib/create_github_release/change.rb
|
252
224
|
- lib/create_github_release/changelog.rb
|
253
|
-
- lib/create_github_release/
|
254
|
-
- lib/create_github_release/
|
225
|
+
- lib/create_github_release/command_line.rb
|
226
|
+
- lib/create_github_release/command_line/options.rb
|
227
|
+
- lib/create_github_release/command_line/parser.rb
|
228
|
+
- lib/create_github_release/command_line/validations.rb
|
229
|
+
- lib/create_github_release/command_line/validator.rb
|
255
230
|
- lib/create_github_release/project.rb
|
256
231
|
- lib/create_github_release/release_assertions.rb
|
257
232
|
- lib/create_github_release/release_tasks.rb
|
@@ -273,7 +248,8 @@ metadata:
|
|
273
248
|
allowed_push_host: https://rubygems.org
|
274
249
|
homepage_uri: https://github.com/main-branch/create_github_release
|
275
250
|
source_code_uri: https://github.com/main-branch/create_github_release
|
276
|
-
changelog_uri: https://
|
251
|
+
changelog_uri: https://rubydoc.info/gems/create_github_release/1.2.0/file/CHANGELOG.md
|
252
|
+
documentation_uri: https://rubydoc.info/gems/create_github_release/1.2.0
|
277
253
|
rubygems_mfa_required: 'true'
|
278
254
|
post_install_message:
|
279
255
|
rdoc_options: []
|
@@ -290,7 +266,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
290
266
|
- !ruby/object:Gem::Version
|
291
267
|
version: '0'
|
292
268
|
requirements: []
|
293
|
-
rubygems_version: 3.
|
269
|
+
rubygems_version: 3.5.3
|
294
270
|
signing_key:
|
295
271
|
specification_version: 4
|
296
272
|
summary: A script to create a GitHub release for a Ruby Gem
|
@@ -1,378 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'uri'
|
4
|
-
|
5
|
-
module CreateGithubRelease
|
6
|
-
# An array of the valid release types
|
7
|
-
# @return [Array<String>]
|
8
|
-
# @api private
|
9
|
-
VALID_RELEASE_TYPES = %w[major minor patch first].freeze
|
10
|
-
|
11
|
-
# Regex pattern for a [valid git reference](https://git-scm.com/docs/git-check-ref-format)
|
12
|
-
# @return [Regexp]
|
13
|
-
# @api private
|
14
|
-
VALID_REF_PATTERN = /^(?:(?:[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*)|(?:[a-zA-Z0-9-]+))$/
|
15
|
-
|
16
|
-
# An array of the allowed options that can be passed to `.new`
|
17
|
-
# @return [Array<Symbol>]
|
18
|
-
ALLOWED_OPTIONS = %i[
|
19
|
-
release_type default_branch release_branch remote last_release_version
|
20
|
-
next_release_version changelog_path quiet verbose
|
21
|
-
].freeze
|
22
|
-
|
23
|
-
# rubocop:disable Metrics/ClassLength
|
24
|
-
|
25
|
-
# Stores and validates the command line options
|
26
|
-
#
|
27
|
-
# @example
|
28
|
-
# options = CreateGithubRelease::CommandLineOptions.new
|
29
|
-
# options.release_type = 'major'
|
30
|
-
# options.valid? #=> true
|
31
|
-
# options.errors #=> []
|
32
|
-
#
|
33
|
-
# @api public
|
34
|
-
#
|
35
|
-
class CommandLineOptions
|
36
|
-
ALLOWED_OPTIONS.each { |option| attr_accessor option }
|
37
|
-
|
38
|
-
# @attribute release_type [rw] the type of release to create
|
39
|
-
#
|
40
|
-
# Must be one of the VALID_RELEASE_TYPES
|
41
|
-
#
|
42
|
-
# @example
|
43
|
-
# options = CreateGithubRelease::CommandLineOptions.new(release_type: 'major')
|
44
|
-
# options.release_type #=> 'major'
|
45
|
-
# @return [String]
|
46
|
-
# @api public
|
47
|
-
|
48
|
-
# @attribute default_branch [rw] the default branch of the repository
|
49
|
-
# @example
|
50
|
-
# options = CreateGithubRelease::CommandLineOptions.new(default_branch: 'main')
|
51
|
-
# options.default_branch #=> 'main'
|
52
|
-
# @return [String]
|
53
|
-
# @api public
|
54
|
-
|
55
|
-
# @attribute release_branch [rw] the branch use to create the release
|
56
|
-
# @example
|
57
|
-
# options = CreateGithubRelease::CommandLineOptions.new(release_branch: 'release-v1.0.0')
|
58
|
-
# options.release_branch #=> 'release-v1.0.0'
|
59
|
-
# @return [String]
|
60
|
-
# @api public
|
61
|
-
|
62
|
-
# @attribute remote [rw] the name of the remote to use to access Github
|
63
|
-
# @example
|
64
|
-
# options = CreateGithubRelease::CommandLineOptions.new(remote: 'origin')
|
65
|
-
# options.remote #=> 'origin'
|
66
|
-
# @return [String]
|
67
|
-
# @api public
|
68
|
-
|
69
|
-
# @attribute last_release_version [rw] the version of the last release
|
70
|
-
# @example
|
71
|
-
# options = CreateGithubRelease::CommandLineOptions.new(last_release_version: '0.1.1')
|
72
|
-
# options.last_release_version #=> '0.1.1'
|
73
|
-
# @return [String]
|
74
|
-
# @api public
|
75
|
-
|
76
|
-
# @attribute next_release_version [rw] the version of the next release
|
77
|
-
# @example
|
78
|
-
# options = CreateGithubRelease::CommandLineOptions.new(next_release_version: '1.0.0')
|
79
|
-
# options.next_release_version #=> '1.0.0'
|
80
|
-
# @return [String]
|
81
|
-
# @api public
|
82
|
-
|
83
|
-
# @attribute changelog_path [rw] the path to the changelog file
|
84
|
-
# @example
|
85
|
-
# options = CreateGithubRelease::CommandLineOptions.new(changelog_path: 'CHANGELOG.md')
|
86
|
-
# options.changelog_path #=> 'CHANGELOG.md'
|
87
|
-
# @return [String]
|
88
|
-
# @api public
|
89
|
-
|
90
|
-
# @attribute quiet [rw] if `true`, suppresses all output
|
91
|
-
# @example
|
92
|
-
# options = CreateGithubRelease::CommandLineOptions.new(quiet: true)
|
93
|
-
# options.quiet #=> true
|
94
|
-
# @return [Boolean]
|
95
|
-
# @api public
|
96
|
-
|
97
|
-
# @attribute verbose [rw] if `true`, enables verbose output
|
98
|
-
# @example
|
99
|
-
# options = CreateGithubRelease::CommandLineOptions.new(verbose: true)
|
100
|
-
# options.verbose #=> true
|
101
|
-
# @return [Boolean]
|
102
|
-
# @api public
|
103
|
-
|
104
|
-
# Create a new instance of this class
|
105
|
-
#
|
106
|
-
# @example No arguments or block given
|
107
|
-
# options = CreateGithubRelease::CommandLineOptions.new
|
108
|
-
# options.release_type #=> nil
|
109
|
-
# options.valid? #=> false
|
110
|
-
# options.errors #=> ["--release-type must be given and be one of 'major', 'minor', 'patch'"]
|
111
|
-
#
|
112
|
-
# @example With keyword arguments
|
113
|
-
# config = { release_type: 'major', default_branch: 'main', quiet: true }
|
114
|
-
# options = CreateGithubRelease::CommandLineOptions.new(**config)
|
115
|
-
# options.release_type #=> 'major'
|
116
|
-
# options.default_branch #=> 'main'
|
117
|
-
# options.quiet #=> true
|
118
|
-
# options.valid? #=> true
|
119
|
-
#
|
120
|
-
# @example with a configuration block
|
121
|
-
# options = CreateGithubRelease::CommandLineOptions.new do |o|
|
122
|
-
# o.release_type = 'major'
|
123
|
-
# o.default_branch = 'main'
|
124
|
-
# o.quiet = true
|
125
|
-
# end
|
126
|
-
# options.release_type #=> 'major'
|
127
|
-
# options.default_branch #=> 'main'
|
128
|
-
# options.quiet #=> true
|
129
|
-
# options.valid? #=> true
|
130
|
-
#
|
131
|
-
# @yield [self] an initialization block
|
132
|
-
# @yieldparam self [CreateGithubRelease::CommandLineOptions] the instance being initialized
|
133
|
-
# @yieldreturn [void] the return value is ignored
|
134
|
-
#
|
135
|
-
def initialize(**options)
|
136
|
-
assert_no_unknown_options(options)
|
137
|
-
options.each { |k, v| instance_variable_set("@#{k}", v) }
|
138
|
-
|
139
|
-
self.quiet ||= false
|
140
|
-
self.verbose ||= false
|
141
|
-
@errors = []
|
142
|
-
|
143
|
-
yield(self) if block_given?
|
144
|
-
end
|
145
|
-
|
146
|
-
# Returns `true` if all options are valid and `false` otherwise
|
147
|
-
#
|
148
|
-
# * If the options are valid, returns `true` clears the `#errors` array
|
149
|
-
# * If the options are not valid, returns `false` and populates the `#errors` array
|
150
|
-
#
|
151
|
-
# @example when all options are valid
|
152
|
-
# options = CreateGithubRelease::CommandLineOptions.new
|
153
|
-
# options.release_type = 'major'
|
154
|
-
# options.valid? #=> true
|
155
|
-
# options.errors #=> []
|
156
|
-
#
|
157
|
-
# @example when one or more options are not valid
|
158
|
-
# options = CreateGithubRelease::CommandLineOptions.new
|
159
|
-
# options.release_type #=> nil
|
160
|
-
# options.valid? #=> false
|
161
|
-
# options.errors #=> ["--release-type must be given and be one of 'major', 'minor', 'patch'"]
|
162
|
-
#
|
163
|
-
# @return [Boolean]
|
164
|
-
#
|
165
|
-
def valid?
|
166
|
-
@errors = []
|
167
|
-
private_methods(false).select { |m| m.to_s.start_with?('validate_') }.each { |m| send(m) }
|
168
|
-
@errors.empty?
|
169
|
-
end
|
170
|
-
|
171
|
-
# Returns an array of error messages
|
172
|
-
#
|
173
|
-
# * If the options are valid, returns an empty array
|
174
|
-
# * If the options are not valid, returns an array of error messages
|
175
|
-
#
|
176
|
-
# @example when all options are valid
|
177
|
-
# options = CreateGithubRelease::CommandLineOptions.new
|
178
|
-
# options.release_type = 'major'
|
179
|
-
# options.valid? #=> true
|
180
|
-
# options.errors #=> []
|
181
|
-
#
|
182
|
-
# @example when one or more options are not valid
|
183
|
-
# options = CreateGithubRelease::CommandLineOptions.new
|
184
|
-
# options.release_type #=> nil
|
185
|
-
# options.quiet = options.verbose = true
|
186
|
-
# options.valid? #=> false
|
187
|
-
# options.errors #=> [
|
188
|
-
# "Both --quiet and --verbose cannot be given",
|
189
|
-
# "--release-type must be given and be one of 'major', 'minor', 'patch'"
|
190
|
-
# ]
|
191
|
-
#
|
192
|
-
# @return [Array<String>] an array of error messages
|
193
|
-
#
|
194
|
-
def errors
|
195
|
-
valid?
|
196
|
-
@errors
|
197
|
-
end
|
198
|
-
|
199
|
-
private
|
200
|
-
|
201
|
-
# Raise ArgumentError if options has a key not in ALLOWED_OPTIONS
|
202
|
-
# @return [void]
|
203
|
-
# @api private
|
204
|
-
def assert_no_unknown_options(options)
|
205
|
-
unknown_options = options.keys - ALLOWED_OPTIONS
|
206
|
-
return if unknown_options.empty?
|
207
|
-
|
208
|
-
message = "Unknown keywords: #{unknown_options.join(', ')}"
|
209
|
-
raise ArgumentError, message
|
210
|
-
end
|
211
|
-
|
212
|
-
# Returns `true` if the given name is a valid git reference
|
213
|
-
# @return [Boolean]
|
214
|
-
# @api private
|
215
|
-
def valid_reference?(name)
|
216
|
-
VALID_REF_PATTERN.match?(name)
|
217
|
-
end
|
218
|
-
|
219
|
-
# Returns `true` if the `#quiet` is `true` or `false` and `false` otherwise
|
220
|
-
# @return [Boolean]
|
221
|
-
# @api private
|
222
|
-
def validate_quiet
|
223
|
-
return true if quiet == true || quiet == false
|
224
|
-
|
225
|
-
@errors << 'quiet must be either true or false'
|
226
|
-
false
|
227
|
-
end
|
228
|
-
|
229
|
-
# Returns `true` if the `#verbose` is `true` or `false` and `false` otherwise
|
230
|
-
# @return [Boolean]
|
231
|
-
# @api private
|
232
|
-
def validate_verbose
|
233
|
-
return true if verbose == true || verbose == false
|
234
|
-
|
235
|
-
@errors << 'verbose must be either true or false'
|
236
|
-
false
|
237
|
-
end
|
238
|
-
|
239
|
-
# Returns `true` if only one of `#quiet` or `#verbose` is `true`
|
240
|
-
# @return [Boolean]
|
241
|
-
# @api private
|
242
|
-
def validate_only_quiet_or_verbose_given
|
243
|
-
return true unless quiet && verbose
|
244
|
-
|
245
|
-
@errors << 'Both --quiet and --verbose cannot both be used'
|
246
|
-
false
|
247
|
-
end
|
248
|
-
|
249
|
-
# Returns `true` if the `#release_type` is not nil
|
250
|
-
# @return [Boolean]
|
251
|
-
# @api private
|
252
|
-
def validate_release_type_given
|
253
|
-
return true unless release_type.nil?
|
254
|
-
|
255
|
-
valid_release_types = "'#{VALID_RELEASE_TYPES.join("', '")}'"
|
256
|
-
@errors << "RELEASE_TYPE must be given and be one of #{valid_release_types}"
|
257
|
-
false
|
258
|
-
end
|
259
|
-
|
260
|
-
# Returns `true` if the `#release_type` is nil or a valid release type
|
261
|
-
# @return [Boolean]
|
262
|
-
# @api private
|
263
|
-
def validate_release_type
|
264
|
-
return true if release_type.nil? || VALID_RELEASE_TYPES.include?(release_type)
|
265
|
-
|
266
|
-
valid_release_types = "'#{VALID_RELEASE_TYPES.join("', '")}'"
|
267
|
-
@errors << "RELEASE_TYPE '#{release_type}' is not valid. Must be one of #{valid_release_types}"
|
268
|
-
false
|
269
|
-
end
|
270
|
-
|
271
|
-
# Returns `true` if the `#default_branch` is nil or is a valid git reference
|
272
|
-
# @return [Boolean]
|
273
|
-
# @api private
|
274
|
-
def validate_default_branch
|
275
|
-
return true if default_branch.nil? || valid_reference?(default_branch)
|
276
|
-
|
277
|
-
@errors << "--default-branch='#{default_branch}' is not valid"
|
278
|
-
false
|
279
|
-
end
|
280
|
-
|
281
|
-
# Returns `true` if the `#release_branch` is nil or is a valid git reference
|
282
|
-
# @return [Boolean]
|
283
|
-
# @api private
|
284
|
-
def validate_release_branch
|
285
|
-
return true if release_branch.nil? || valid_reference?(release_branch)
|
286
|
-
|
287
|
-
@errors << "--release-branch='#{release_branch}' is not valid"
|
288
|
-
false
|
289
|
-
end
|
290
|
-
|
291
|
-
# Returns `true` if the `#remote` is nil or is a valid git reference
|
292
|
-
# @return [Boolean]
|
293
|
-
# @api private
|
294
|
-
def validate_remote
|
295
|
-
return true if remote.nil? || valid_reference?(remote)
|
296
|
-
|
297
|
-
@errors << "--remote='#{remote}' is not valid"
|
298
|
-
false
|
299
|
-
end
|
300
|
-
|
301
|
-
# Returns `true` if the given version is a valid gem version
|
302
|
-
# @return [Boolean]
|
303
|
-
# @api private
|
304
|
-
def valid_gem_version?(version)
|
305
|
-
Gem::Version.new(version)
|
306
|
-
true
|
307
|
-
rescue ArgumentError
|
308
|
-
false
|
309
|
-
end
|
310
|
-
|
311
|
-
# Returns `true` if the `#last_release_version` is nil or is a valid gem version
|
312
|
-
# @return [Boolean]
|
313
|
-
# @api private
|
314
|
-
def validate_last_release_version
|
315
|
-
return true if last_release_version.nil?
|
316
|
-
|
317
|
-
if valid_gem_version?(last_release_version)
|
318
|
-
true
|
319
|
-
else
|
320
|
-
@errors << "--last-release-version='#{last_release_version}' is not valid"
|
321
|
-
false
|
322
|
-
end
|
323
|
-
end
|
324
|
-
|
325
|
-
# Returns `true` if the `#next_release_version` is nil or is a valid gem version
|
326
|
-
# @return [Boolean]
|
327
|
-
# @api private
|
328
|
-
def validate_next_release_version
|
329
|
-
return true if next_release_version.nil?
|
330
|
-
|
331
|
-
if valid_gem_version?(next_release_version)
|
332
|
-
true
|
333
|
-
else
|
334
|
-
@errors << "--next-release-version='#{next_release_version}' is not valid"
|
335
|
-
false
|
336
|
-
end
|
337
|
-
end
|
338
|
-
|
339
|
-
# Returns `true` if the given path is valid
|
340
|
-
# @param path [String] the path to validate
|
341
|
-
# @return [Boolean]
|
342
|
-
# @api private
|
343
|
-
def valid_path?(path)
|
344
|
-
File.expand_path(path)
|
345
|
-
true
|
346
|
-
rescue ArgumentError
|
347
|
-
false
|
348
|
-
end
|
349
|
-
|
350
|
-
# Returns `true` if `#changelog_path` is nil or is a valid regular file path
|
351
|
-
# @return [Boolean]
|
352
|
-
# @api private
|
353
|
-
def validate_changelog_path
|
354
|
-
changelog_path.nil? || (changelog_path_valid? && changelog_regular_file?)
|
355
|
-
end
|
356
|
-
|
357
|
-
# `true` if `#changelog_path` is a valid path
|
358
|
-
# @return [Boolean]
|
359
|
-
# @api private
|
360
|
-
def changelog_path_valid?
|
361
|
-
return true if valid_path?(changelog_path)
|
362
|
-
|
363
|
-
@errors << "--changelog-path='#{changelog_path}' is not valid"
|
364
|
-
false
|
365
|
-
end
|
366
|
-
|
367
|
-
# `true` if `#changelog_path` does not exist OR if it exists and is a regular file
|
368
|
-
# @return [Boolean]
|
369
|
-
# @api private
|
370
|
-
def changelog_regular_file?
|
371
|
-
return true unless File.exist?(changelog_path) && !File.file?(changelog_path)
|
372
|
-
|
373
|
-
@errors << "--changelog-path='#{changelog_path}' must be a regular file"
|
374
|
-
false
|
375
|
-
end
|
376
|
-
end
|
377
|
-
# rubocop:enable Metrics/ClassLength
|
378
|
-
end
|
@@ -1,229 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'English'
|
4
|
-
require 'optparse'
|
5
|
-
require 'create_github_release/command_line_options'
|
6
|
-
|
7
|
-
module CreateGithubRelease
|
8
|
-
# Parses the options for this script
|
9
|
-
#
|
10
|
-
# @example Specify the release type
|
11
|
-
# options = CommandLineParser.new.parse('major')
|
12
|
-
# options.valid? # => true
|
13
|
-
# options.release_type # => "major"
|
14
|
-
# options.quiet # => false
|
15
|
-
#
|
16
|
-
# @example Specify the release type and the quiet option
|
17
|
-
# parser = CommandLineParser.new
|
18
|
-
# args = %w[minor --quiet]
|
19
|
-
# options = parser.parse(*args)
|
20
|
-
# options.release_type # => "minor"
|
21
|
-
# options.quiet # => true
|
22
|
-
#
|
23
|
-
# @example Show the command line help
|
24
|
-
# CommandLineParser.new.parse('--help')
|
25
|
-
# parser.parse('--help')
|
26
|
-
#
|
27
|
-
# @api public
|
28
|
-
#
|
29
|
-
class CommandLineParser
|
30
|
-
# Create a new command line parser
|
31
|
-
#
|
32
|
-
# @example
|
33
|
-
# parser = CommandLineParser.new
|
34
|
-
#
|
35
|
-
def initialize
|
36
|
-
@option_parser = OptionParser.new
|
37
|
-
define_options
|
38
|
-
@options = CreateGithubRelease::CommandLineOptions.new
|
39
|
-
end
|
40
|
-
|
41
|
-
# Parse the command line arguements returning the options
|
42
|
-
#
|
43
|
-
# @example
|
44
|
-
# parser = CommandLineParser.new
|
45
|
-
# options = parser.parse(['major'])
|
46
|
-
#
|
47
|
-
# @param args [Array<String>] the command line arguments
|
48
|
-
#
|
49
|
-
# @return [CreateGithubRelease::CommandLineOptions] the options
|
50
|
-
#
|
51
|
-
def parse(*args)
|
52
|
-
begin
|
53
|
-
option_parser.parse!(remaining_args = args.dup)
|
54
|
-
rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e
|
55
|
-
report_errors(e.message)
|
56
|
-
end
|
57
|
-
parse_remaining_args(remaining_args)
|
58
|
-
# puts options unless options.quiet
|
59
|
-
report_errors(*options.errors) unless options.valid?
|
60
|
-
options
|
61
|
-
end
|
62
|
-
|
63
|
-
private
|
64
|
-
|
65
|
-
# @!attribute [rw] options
|
66
|
-
#
|
67
|
-
# The options to used for the create-github-release script
|
68
|
-
#
|
69
|
-
# @example
|
70
|
-
# parser = CommandLineParser.new
|
71
|
-
# parser.parse(['major'])
|
72
|
-
# options = parser.options
|
73
|
-
# options.release_type # => 'major'
|
74
|
-
#
|
75
|
-
# @return [CreateGithubRelease::CommandLineOptions] the options
|
76
|
-
#
|
77
|
-
# @api private
|
78
|
-
#
|
79
|
-
attr_reader :options
|
80
|
-
|
81
|
-
# @!attribute [rw] option_parser
|
82
|
-
#
|
83
|
-
# The option parser
|
84
|
-
#
|
85
|
-
# @return [OptionParser] the option parser
|
86
|
-
#
|
87
|
-
# @api private
|
88
|
-
#
|
89
|
-
attr_reader :option_parser
|
90
|
-
|
91
|
-
# Parse non-option arguments (the release type)
|
92
|
-
# @return [void]
|
93
|
-
# @api private
|
94
|
-
def parse_remaining_args(remaining_args)
|
95
|
-
options.release_type = remaining_args.shift || nil
|
96
|
-
report_errors('Too many args') unless remaining_args.empty?
|
97
|
-
end
|
98
|
-
|
99
|
-
# An error message constructed from the given errors array
|
100
|
-
# @return [String]
|
101
|
-
# @api private
|
102
|
-
def error_message(errors)
|
103
|
-
<<~MESSAGE
|
104
|
-
#{errors.map { |e| "ERROR: #{e}" }.join("\n")}
|
105
|
-
|
106
|
-
Use --help for usage
|
107
|
-
MESSAGE
|
108
|
-
end
|
109
|
-
|
110
|
-
# Output an error message and useage to stderr and exit
|
111
|
-
# @return [void]
|
112
|
-
# @api private
|
113
|
-
def report_errors(*errors)
|
114
|
-
warn error_message(errors)
|
115
|
-
exit 1
|
116
|
-
end
|
117
|
-
|
118
|
-
# The command line template as a string
|
119
|
-
# @return [String]
|
120
|
-
# @api private
|
121
|
-
def command_template
|
122
|
-
<<~COMMAND
|
123
|
-
#{File.basename($PROGRAM_NAME)} --help | RELEASE_TYPE [options]
|
124
|
-
COMMAND
|
125
|
-
end
|
126
|
-
|
127
|
-
# Define the options for OptionParser
|
128
|
-
# @return [void]
|
129
|
-
# @api private
|
130
|
-
def define_options
|
131
|
-
# @sg-ignore
|
132
|
-
option_parser.banner = "Usage:\n#{command_template}"
|
133
|
-
option_parser.separator ''
|
134
|
-
option_parser.separator "RELEASE_TYPE must be 'major', 'minor', or 'patch'"
|
135
|
-
option_parser.separator ''
|
136
|
-
option_parser.separator 'Options:'
|
137
|
-
%i[
|
138
|
-
define_help_option define_default_branch_option define_release_branch_option
|
139
|
-
define_remote_option define_last_release_version_option define_next_release_version_option
|
140
|
-
define_changelog_path_option define_quiet_option define_verbose_option
|
141
|
-
].each { |m| send(m) }
|
142
|
-
end
|
143
|
-
|
144
|
-
# Define the quiet option
|
145
|
-
# @return [void]
|
146
|
-
# @api private
|
147
|
-
def define_quiet_option
|
148
|
-
option_parser.on('-q', '--[no-]quiet', 'Do not show output') do |quiet|
|
149
|
-
options.quiet = quiet
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
# Define the verbose option
|
154
|
-
# @return [void]
|
155
|
-
# @api private
|
156
|
-
def define_verbose_option
|
157
|
-
option_parser.on('-v', '--[no-]verbose', 'Show extra output') do |verbose|
|
158
|
-
options.verbose = verbose
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
# Define the help option
|
163
|
-
# @return [void]
|
164
|
-
# @api private
|
165
|
-
def define_help_option
|
166
|
-
option_parser.on_tail('-h', '--help', 'Show this message') do
|
167
|
-
puts option_parser
|
168
|
-
exit 0
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
# Define the default_branch option which requires a value
|
173
|
-
# @return [void]
|
174
|
-
# @api private
|
175
|
-
def define_default_branch_option
|
176
|
-
option_parser.on('--default-branch=BRANCH_NAME', 'Override the default branch') do |name|
|
177
|
-
options.default_branch = name
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
# Define the release_branch option which requires a value
|
182
|
-
# @return [void]
|
183
|
-
# @api private
|
184
|
-
def define_release_branch_option
|
185
|
-
option_parser.on('--release-branch=BRANCH_NAME', 'Override the release branch to create') do |name|
|
186
|
-
options.release_branch = name
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
# Define the remote option which requires a value
|
191
|
-
# @return [void]
|
192
|
-
# @api private
|
193
|
-
def define_remote_option
|
194
|
-
option_parser.on('--remote=REMOTE_NAME', "Use this remote name instead of 'origin'") do |name|
|
195
|
-
options.remote = name
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
# Define the last_release_version option which requires a value
|
200
|
-
# @return [void]
|
201
|
-
# @api private
|
202
|
-
def define_last_release_version_option
|
203
|
-
option_parser.on('--last-release-version=VERSION', 'Use this version instead `semverify current`') do |version|
|
204
|
-
options.last_release_version = version
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
|
-
# Define the next_release_version option which requires a value
|
209
|
-
# @return [void]
|
210
|
-
# @api private
|
211
|
-
def define_next_release_version_option
|
212
|
-
option_parser.on(
|
213
|
-
'--next-release-version=VERSION',
|
214
|
-
'Use this version instead `semverify next-RELEASE_TYPE`'
|
215
|
-
) do |version|
|
216
|
-
options.next_release_version = version
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
# Define the changelog_path option which requires a value
|
221
|
-
# @return [void]
|
222
|
-
# @api private
|
223
|
-
def define_changelog_path_option
|
224
|
-
option_parser.on('--changelog-path=PATH', 'Use this file instead of CHANGELOG.md') do |name|
|
225
|
-
options.changelog_path = name
|
226
|
-
end
|
227
|
-
end
|
228
|
-
end
|
229
|
-
end
|