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.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -1
- data/.solargraph.yml +23 -0
- data/.vscode/launch.json +19 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +26 -0
- data/README.md +165 -47
- data/Rakefile +7 -4
- data/create_github_release.gemspec +7 -4
- data/exe/create-github-release +5 -1
- data/lib/create_github_release/assertion_base.rb +0 -2
- 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 +136 -76
- data/lib/create_github_release/release_assertions.rb +2 -1
- data/lib/create_github_release/release_tasks.rb +2 -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 +13 -14
- data/lib/create_github_release/version.rb +1 -1
- data/lib/create_github_release.rb +1 -2
- metadata +31 -25
- data/lib/create_github_release/command_line_options.rb +0 -367
- data/lib/create_github_release/command_line_parser.rb +0 -225
@@ -0,0 +1,93 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'validations'
|
4
|
+
|
5
|
+
module CreateGithubRelease
|
6
|
+
module CommandLine
|
7
|
+
# Validates a set of options after the options have been fully initialized
|
8
|
+
# @api private
|
9
|
+
class Validator
|
10
|
+
# Create a new instance of this class
|
11
|
+
# @param options [CreateGithubRelease::CommandLine::Options] the options to validate
|
12
|
+
# @api private
|
13
|
+
def initialize(options)
|
14
|
+
@options = options
|
15
|
+
end
|
16
|
+
|
17
|
+
# Returns `true` if all options are valid and `false` otherwise
|
18
|
+
#
|
19
|
+
# * If the options are valid, returns `true` clears the `#errors` array
|
20
|
+
# * If the options are not valid, returns `false` and populates the `#errors` array
|
21
|
+
#
|
22
|
+
# @example when all options are valid
|
23
|
+
# options = CreateGithubRelease::CommandLine::Options.new
|
24
|
+
# options.release_type = 'major'
|
25
|
+
# options.valid? #=> true
|
26
|
+
# options.errors #=> []
|
27
|
+
#
|
28
|
+
# @example when one or more options are not valid
|
29
|
+
# options = CreateGithubRelease::CommandLine::Options.new
|
30
|
+
# options.release_type #=> nil
|
31
|
+
# options.valid? #=> false
|
32
|
+
# options.errors #=> ["--release-type must be given and be one of 'major', 'minor', 'patch'"]
|
33
|
+
#
|
34
|
+
# @return [Boolean]
|
35
|
+
#
|
36
|
+
def valid?
|
37
|
+
@errors = []
|
38
|
+
validation_classes.each do |validation_class|
|
39
|
+
validation = validation_class.new(options)
|
40
|
+
@errors << validation.error unless validation.valid?
|
41
|
+
end
|
42
|
+
@errors.empty?
|
43
|
+
end
|
44
|
+
|
45
|
+
# Returns an array of error messages
|
46
|
+
#
|
47
|
+
# * If the options are valid, returns an empty array
|
48
|
+
# * If the options are not valid, returns an array of error messages
|
49
|
+
#
|
50
|
+
# @example when all options are valid
|
51
|
+
# options = CreateGithubRelease::CommandLine::Options.new
|
52
|
+
# options.release_type = 'major'
|
53
|
+
# options.valid? #=> true
|
54
|
+
# options.errors #=> []
|
55
|
+
#
|
56
|
+
# @example when one or more options are not valid
|
57
|
+
# options = CreateGithubRelease::CommandLine::Options.new
|
58
|
+
# options.release_type #=> nil
|
59
|
+
# options.quiet = options.verbose = true
|
60
|
+
# options.valid? #=> false
|
61
|
+
# options.errors #=> [
|
62
|
+
# "Both --quiet and --verbose cannot be given",
|
63
|
+
# "--release-type must be given and be one of 'major', 'minor', 'patch'"
|
64
|
+
# ]
|
65
|
+
#
|
66
|
+
# @return [Array<String>] an array of error messages
|
67
|
+
#
|
68
|
+
def errors
|
69
|
+
valid?
|
70
|
+
@errors
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
# The options to validate
|
76
|
+
# @return [CreateGithubRelease::CommandLine::Options]
|
77
|
+
# @api private
|
78
|
+
attr_reader :options
|
79
|
+
|
80
|
+
# Returns an array of validation classes
|
81
|
+
# @return [Array<CreateGithubRelease::Validations::Base>]
|
82
|
+
# @api private
|
83
|
+
def validation_classes
|
84
|
+
[].tap do |validation_classes|
|
85
|
+
CreateGithubRelease::CommandLine::Validations.constants.each do |constant_name|
|
86
|
+
constant = Validations.const_get(constant_name)
|
87
|
+
validation_classes << constant if constant.is_a?(Class) && constant_name.to_s.start_with?('Validate')
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CreateGithubRelease
|
4
|
+
# This module has all the classes and modules for the command line interface
|
5
|
+
#
|
6
|
+
# The Parser class is the main interface. It parses and validates the command line
|
7
|
+
# arguments and returns an instance of the Options class.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# parser = CreateGithubRelease::CommandLine::Parser.new
|
11
|
+
# options = parser.parse(*ARGV)
|
12
|
+
# if !option.valid?
|
13
|
+
# puts options.errors
|
14
|
+
# exit 1
|
15
|
+
# end
|
16
|
+
# # ... do something with the options
|
17
|
+
#
|
18
|
+
# @api public
|
19
|
+
#
|
20
|
+
module CommandLine
|
21
|
+
# An array of the valid release types
|
22
|
+
# @return [Array<String>]
|
23
|
+
# @api private
|
24
|
+
VALID_RELEASE_TYPES = %w[major minor patch pre release first].freeze
|
25
|
+
|
26
|
+
# Regex pattern for a [valid git reference](https://git-scm.com/docs/git-check-ref-format)
|
27
|
+
# @return [Regexp]
|
28
|
+
# @api private
|
29
|
+
VALID_REF_PATTERN = /^(?:(?:[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*)|(?:[a-zA-Z0-9-]+))$/
|
30
|
+
|
31
|
+
# An array of the allowed options that can be passed to `.new`
|
32
|
+
# @return [Array<Symbol>]
|
33
|
+
ALLOWED_OPTIONS = %i[
|
34
|
+
release_type pre pre_type default_branch release_branch remote last_release_version
|
35
|
+
next_release_version changelog_path quiet verbose
|
36
|
+
].freeze
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
require_relative 'command_line/options'
|
41
|
+
require_relative 'command_line/parser'
|
42
|
+
require_relative 'command_line/validations'
|
43
|
+
require_relative 'command_line/validator'
|