create_github_release 1.1.0 → 1.3.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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -0
  3. data/CHANGELOG.md +18 -0
  4. data/README.md +156 -38
  5. data/Rakefile +6 -6
  6. data/create_github_release.gemspec +3 -3
  7. data/exe/create-github-release +1 -1
  8. data/exe/revert-github-release +165 -0
  9. data/lib/create_github_release/assertions/bundle_is_up_to_date.rb +1 -1
  10. data/lib/create_github_release/assertions/gh_authenticated.rb +1 -1
  11. data/lib/create_github_release/assertions/gh_command_exists.rb +1 -1
  12. data/lib/create_github_release/assertions/git_command_exists.rb +1 -1
  13. data/lib/create_github_release/assertions/in_git_repo.rb +1 -1
  14. data/lib/create_github_release/assertions/in_repo_root_directory.rb +1 -1
  15. data/lib/create_github_release/assertions/local_and_remote_on_same_commit.rb +1 -1
  16. data/lib/create_github_release/assertions/local_release_branch_does_not_exist.rb +1 -1
  17. data/lib/create_github_release/assertions/no_staged_changes.rb +1 -1
  18. data/lib/create_github_release/assertions/no_uncommitted_changes.rb +1 -1
  19. data/lib/create_github_release/assertions/on_default_branch.rb +1 -1
  20. data/lib/create_github_release/assertions/remote_release_branch_does_not_exist.rb +1 -1
  21. data/lib/create_github_release/assertions/remote_release_tag_does_not_exist.rb +1 -1
  22. data/lib/create_github_release/command_line/options.rb +151 -0
  23. data/lib/create_github_release/command_line/parser.rb +262 -0
  24. data/lib/create_github_release/command_line/validations.rb +293 -0
  25. data/lib/create_github_release/command_line/validator.rb +93 -0
  26. data/lib/create_github_release/command_line.rb +43 -0
  27. data/lib/create_github_release/project.rb +115 -55
  28. data/lib/create_github_release/release_assertions.rb +1 -1
  29. data/lib/create_github_release/release_tasks.rb +1 -1
  30. data/lib/create_github_release/tasks/commit_release.rb +1 -1
  31. data/lib/create_github_release/tasks/create_github_release.rb +1 -1
  32. data/lib/create_github_release/tasks/create_release_branch.rb +1 -1
  33. data/lib/create_github_release/tasks/create_release_pull_request.rb +1 -1
  34. data/lib/create_github_release/tasks/create_release_tag.rb +1 -1
  35. data/lib/create_github_release/tasks/push_release.rb +1 -1
  36. data/lib/create_github_release/tasks/update_changelog.rb +1 -1
  37. data/lib/create_github_release/tasks/update_version.rb +5 -2
  38. data/lib/create_github_release/version.rb +1 -1
  39. data/lib/create_github_release.rb +1 -2
  40. metadata +12 -34
  41. data/lib/create_github_release/command_line_options.rb +0 -378
  42. data/lib/create_github_release/command_line_parser.rb +0 -229
@@ -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