create_github_release 1.0.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -1
  3. data/.solargraph.yml +23 -0
  4. data/.vscode/launch.json +19 -0
  5. data/.yardopts +1 -0
  6. data/CHANGELOG.md +26 -0
  7. data/README.md +165 -47
  8. data/Rakefile +7 -4
  9. data/create_github_release.gemspec +7 -4
  10. data/exe/create-github-release +5 -1
  11. data/lib/create_github_release/assertion_base.rb +0 -2
  12. data/lib/create_github_release/assertions/bundle_is_up_to_date.rb +1 -1
  13. data/lib/create_github_release/assertions/gh_authenticated.rb +1 -1
  14. data/lib/create_github_release/assertions/gh_command_exists.rb +1 -1
  15. data/lib/create_github_release/assertions/git_command_exists.rb +1 -1
  16. data/lib/create_github_release/assertions/in_git_repo.rb +1 -1
  17. data/lib/create_github_release/assertions/in_repo_root_directory.rb +1 -1
  18. data/lib/create_github_release/assertions/local_and_remote_on_same_commit.rb +1 -1
  19. data/lib/create_github_release/assertions/local_release_branch_does_not_exist.rb +1 -1
  20. data/lib/create_github_release/assertions/no_staged_changes.rb +1 -1
  21. data/lib/create_github_release/assertions/no_uncommitted_changes.rb +1 -1
  22. data/lib/create_github_release/assertions/on_default_branch.rb +1 -1
  23. data/lib/create_github_release/assertions/remote_release_branch_does_not_exist.rb +1 -1
  24. data/lib/create_github_release/assertions/remote_release_tag_does_not_exist.rb +1 -1
  25. data/lib/create_github_release/command_line/options.rb +151 -0
  26. data/lib/create_github_release/command_line/parser.rb +253 -0
  27. data/lib/create_github_release/command_line/validations.rb +293 -0
  28. data/lib/create_github_release/command_line/validator.rb +93 -0
  29. data/lib/create_github_release/command_line.rb +43 -0
  30. data/lib/create_github_release/project.rb +136 -76
  31. data/lib/create_github_release/release_assertions.rb +2 -1
  32. data/lib/create_github_release/release_tasks.rb +2 -1
  33. data/lib/create_github_release/tasks/commit_release.rb +1 -1
  34. data/lib/create_github_release/tasks/create_github_release.rb +1 -1
  35. data/lib/create_github_release/tasks/create_release_branch.rb +1 -1
  36. data/lib/create_github_release/tasks/create_release_pull_request.rb +1 -1
  37. data/lib/create_github_release/tasks/create_release_tag.rb +1 -1
  38. data/lib/create_github_release/tasks/push_release.rb +1 -1
  39. data/lib/create_github_release/tasks/update_changelog.rb +1 -1
  40. data/lib/create_github_release/tasks/update_version.rb +13 -14
  41. data/lib/create_github_release/version.rb +1 -1
  42. data/lib/create_github_release.rb +1 -2
  43. metadata +31 -25
  44. data/lib/create_github_release/command_line_options.rb +0 -367
  45. data/lib/create_github_release/command_line_parser.rb +0 -225
@@ -1,225 +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::Options] 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::Options] 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
- option_parser.banner = "Usage:\n#{command_template}"
132
- option_parser.separator ''
133
- option_parser.separator "RELEASE_TYPE must be 'major', 'minor', or 'patch'"
134
- option_parser.separator ''
135
- option_parser.separator 'Options:'
136
- %i[
137
- define_help_option define_default_branch_option define_release_branch_option
138
- define_remote_option define_last_release_version_option define_next_release_version_option
139
- define_changelog_path_option define_quiet_option define_verbose_option
140
- ].each { |m| send(m) }
141
- end
142
-
143
- # Define the quiet option
144
- # @return [void]
145
- # @api private
146
- def define_quiet_option
147
- option_parser.on('-q', '--[no-]quiet', 'Do not show output') do |quiet|
148
- options.quiet = quiet
149
- end
150
- end
151
-
152
- # Define the verbose option
153
- # @return [void]
154
- # @api private
155
- def define_verbose_option
156
- option_parser.on('-v', '--[no-]verbose', 'Show extra output') do |verbose|
157
- options.verbose = verbose
158
- end
159
- end
160
-
161
- # Define the help option
162
- # @return [void]
163
- # @api private
164
- def define_help_option
165
- option_parser.on_tail('-h', '--help', 'Show this message') do
166
- puts option_parser
167
- exit 0
168
- end
169
- end
170
-
171
- # Define the default_branch option which requires a value
172
- # @return [void]
173
- # @api private
174
- def define_default_branch_option
175
- option_parser.on('--default-branch=BRANCH_NAME', 'Override the default branch') do |name|
176
- options.default_branch = name
177
- end
178
- end
179
-
180
- # Define the release_branch option which requires a value
181
- # @return [void]
182
- # @api private
183
- def define_release_branch_option
184
- option_parser.on('--release-branch=BRANCH_NAME', 'Override the release branch to create') do |name|
185
- options.release_branch = name
186
- end
187
- end
188
-
189
- # Define the remote option which requires a value
190
- # @return [void]
191
- # @api private
192
- def define_remote_option
193
- option_parser.on('--remote=REMOTE_NAME', "Use this remote name instead of 'origin'") do |name|
194
- options.remote = name
195
- end
196
- end
197
-
198
- # Define the last_release_version option which requires a value
199
- # @return [void]
200
- # @api private
201
- def define_last_release_version_option
202
- option_parser.on('--last-release-version=VERSION', 'Use this version instead `bump current`') do |version|
203
- options.last_release_version = version
204
- end
205
- end
206
-
207
- # Define the next_release_version option which requires a value
208
- # @return [void]
209
- # @api private
210
- def define_next_release_version_option
211
- option_parser.on('--next-release-version=VERSION', 'Use this version instead `bump RELEASE_TYPE`') do |version|
212
- options.next_release_version = version
213
- end
214
- end
215
-
216
- # Define the changelog_path option which requires a value
217
- # @return [void]
218
- # @api private
219
- def define_changelog_path_option
220
- option_parser.on('--changelog-path=PATH', 'Use this file instead of CHANGELOG.md') do |name|
221
- options.changelog_path = name
222
- end
223
- end
224
- end
225
- end