2016-10-05 19:35:55 +00:00
|
|
|
# frozen_string_literal: true
|
2017-05-24 22:11:02 +00:00
|
|
|
|
2016-10-05 21:31:19 +00:00
|
|
|
require "delegate"
|
2017-10-14 19:52:26 +00:00
|
|
|
require "github_changelog_generator/helper"
|
|
|
|
|
2016-10-05 19:35:55 +00:00
|
|
|
module GitHubChangelogGenerator
|
2017-10-14 19:28:02 +00:00
|
|
|
# This class wraps Options, and knows a list of known options. Others options
|
|
|
|
# will raise exceptions.
|
2016-10-05 19:35:55 +00:00
|
|
|
class Options < SimpleDelegator
|
2017-10-14 19:28:02 +00:00
|
|
|
# Raised on intializing with unknown keys in the values hash,
|
|
|
|
# and when trying to store a value on an unknown key.
|
2016-10-05 20:57:28 +00:00
|
|
|
UnsupportedOptionError = Class.new(ArgumentError)
|
|
|
|
|
2017-10-14 19:28:02 +00:00
|
|
|
# List of valid option names
|
2017-05-24 22:11:02 +00:00
|
|
|
KNOWN_OPTIONS = %i[
|
|
|
|
add_issues_wo_labels
|
|
|
|
add_pr_wo_labels
|
|
|
|
author
|
|
|
|
base
|
|
|
|
between_tags
|
|
|
|
bug_labels
|
|
|
|
bug_prefix
|
|
|
|
cache_file
|
|
|
|
cache_log
|
|
|
|
compare_link
|
|
|
|
date_format
|
|
|
|
due_tag
|
|
|
|
enhancement_labels
|
|
|
|
enhancement_prefix
|
2017-10-10 18:27:23 +00:00
|
|
|
breaking_labels
|
|
|
|
breaking_prefix
|
2017-05-24 22:11:02 +00:00
|
|
|
exclude_labels
|
|
|
|
exclude_tags
|
|
|
|
exclude_tags_regex
|
|
|
|
filter_issues_by_milestone
|
|
|
|
frontmatter
|
|
|
|
future_release
|
|
|
|
github_endpoint
|
|
|
|
github_site
|
|
|
|
header
|
|
|
|
http_cache
|
|
|
|
include_labels
|
|
|
|
issue_prefix
|
|
|
|
issue_line_labels
|
|
|
|
issues
|
|
|
|
max_issues
|
|
|
|
merge_prefix
|
|
|
|
output
|
|
|
|
project
|
|
|
|
pulls
|
|
|
|
release_branch
|
|
|
|
release_url
|
2017-10-14 19:00:56 +00:00
|
|
|
require
|
2017-05-24 22:11:02 +00:00
|
|
|
simple_list
|
|
|
|
since_tag
|
|
|
|
ssl_ca_file
|
|
|
|
token
|
|
|
|
unreleased
|
|
|
|
unreleased_label
|
|
|
|
unreleased_only
|
|
|
|
user
|
|
|
|
usernames_as_github_logins
|
|
|
|
verbose
|
2016-10-05 19:35:55 +00:00
|
|
|
]
|
|
|
|
|
2017-10-14 19:28:02 +00:00
|
|
|
# @param values [Hash]
|
|
|
|
#
|
|
|
|
# @raise [UnsupportedOptionError] if given values contain unknown options
|
2016-10-05 19:35:55 +00:00
|
|
|
def initialize(values)
|
|
|
|
super(values)
|
2016-10-05 20:57:28 +00:00
|
|
|
unsupported_options.any? && raise(UnsupportedOptionError, unsupported_options.inspect)
|
|
|
|
end
|
|
|
|
|
2017-10-14 19:28:02 +00:00
|
|
|
# Set option key to val.
|
|
|
|
#
|
|
|
|
# @param key [Symbol]
|
|
|
|
# @param val [Object]
|
|
|
|
#
|
|
|
|
# @raise [UnsupportedOptionError] when trying to set an unknown option
|
2016-10-05 20:57:28 +00:00
|
|
|
def []=(key, val)
|
|
|
|
supported_option?(key) || raise(UnsupportedOptionError, key.inspect)
|
|
|
|
values[key] = val
|
2016-10-05 19:35:55 +00:00
|
|
|
end
|
|
|
|
|
2017-10-14 19:28:02 +00:00
|
|
|
# @return [Hash]
|
2016-10-05 19:35:55 +00:00
|
|
|
def to_hash
|
|
|
|
values
|
|
|
|
end
|
|
|
|
|
2017-10-14 19:00:56 +00:00
|
|
|
# Loads the configured Ruby files from the --require option.
|
|
|
|
def load_custom_ruby_files
|
|
|
|
self[:require].each { |f| require f }
|
|
|
|
end
|
|
|
|
|
2017-10-14 19:52:26 +00:00
|
|
|
# Pretty-prints a censored options hash, if :verbose.
|
|
|
|
def print_options
|
|
|
|
return unless self[:verbose]
|
|
|
|
Helper.log.info "Using these options:"
|
|
|
|
pp(censored_values)
|
|
|
|
puts ""
|
|
|
|
end
|
|
|
|
|
2016-10-05 19:35:55 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def values
|
|
|
|
__getobj__
|
|
|
|
end
|
|
|
|
|
2017-10-14 19:52:26 +00:00
|
|
|
# Returns a censored options hash.
|
|
|
|
#
|
|
|
|
# @return [Hash] The GitHub `:token` key is censored in the output.
|
|
|
|
def censored_values
|
|
|
|
values.clone.tap { |opts| opts[:token] = opts[:token].nil? ? "No token used" : "hidden value" }
|
|
|
|
end
|
|
|
|
|
2016-10-05 19:35:55 +00:00
|
|
|
def unsupported_options
|
2017-02-08 20:58:30 +00:00
|
|
|
values.keys - KNOWN_OPTIONS
|
2016-10-05 20:57:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def supported_option?(key)
|
2017-02-08 20:58:30 +00:00
|
|
|
KNOWN_OPTIONS.include?(key)
|
2016-10-05 19:35:55 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|