Merge branch 'master' into develop
This commit is contained in:
commit
47c0332b55
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -0,0 +1 @@
|
||||||
|
coverage/
|
|
@ -32,7 +32,7 @@ To make it easier for users and contributors to see precisely what notable chang
|
||||||
### *Why should I care?*
|
### *Why should I care?*
|
||||||
Because software tools are for people. If you don’t care, why are you contributing to open source? Surely, there must be a kernel (ha!) of care somewhere in that lovely little brain of yours.
|
Because software tools are for people. If you don’t care, why are you contributing to open source? Surely, there must be a kernel (ha!) of care somewhere in that lovely little brain of yours.
|
||||||
|
|
||||||
> :copyright: *[http://keepachangelog.com](http://keepachangelog.com/)*
|
> :arrow_right: *[http://keepachangelog.com](http://keepachangelog.com/)*
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ It's time to create this token or wait for 1 hour before GitHub reset the counte
|
||||||
## Migrating from a manual changelog
|
## Migrating from a manual changelog
|
||||||
|
|
||||||
Knowing how dedicated you are to your project, you probably haven't been waiting for github-changelog-generator to keep a changelog,
|
Knowing how dedicated you are to your project, you probably haven't been waiting for github-changelog-generator to keep a changelog,
|
||||||
but you most likely wouln't like to have to open issues and PRs for all past features listed in your historic changelog.
|
but you most likely wouldn't like to have to open issues and PRs for all past features listed in your historic changelog.
|
||||||
|
|
||||||
That's where `--base` comes handy. This option lets you pass a static changelog to be appended at the end of the generated entries.
|
That's where `--base` comes handy. This option lets you pass a static changelog to be appended at the end of the generated entries.
|
||||||
|
|
||||||
|
|
|
@ -7,22 +7,16 @@ module GitHubChangelogGenerator
|
||||||
class Parser
|
class Parser
|
||||||
# parse options with optparse
|
# parse options with optparse
|
||||||
def self.parse_options
|
def self.parse_options
|
||||||
options = get_default_options
|
options = default_options
|
||||||
|
|
||||||
parser_file = ParserFile.new options
|
ParserFile.new(options).parse!
|
||||||
parser_file.parse!
|
|
||||||
|
|
||||||
parser = setup_parser(options)
|
parser = setup_parser(options)
|
||||||
parser.parse!
|
parser.parse!
|
||||||
|
|
||||||
if options[:user].nil? || options[:project].nil?
|
user_and_project_from_git(options)
|
||||||
detect_user_and_project(options, ARGV[0], ARGV[1])
|
|
||||||
end
|
|
||||||
|
|
||||||
if !options[:user] || !options[:project]
|
abort(parser.banner) unless options[:user] && options[:project]
|
||||||
puts parser.banner
|
|
||||||
exit
|
|
||||||
end
|
|
||||||
|
|
||||||
print_options(options)
|
print_options(options)
|
||||||
|
|
||||||
|
@ -165,8 +159,8 @@ module GitHubChangelogGenerator
|
||||||
end
|
end
|
||||||
|
|
||||||
# just get default options
|
# just get default options
|
||||||
def self.get_default_options
|
def self.default_options
|
||||||
options = {
|
{
|
||||||
tag1: nil,
|
tag1: nil,
|
||||||
tag2: nil,
|
tag2: nil,
|
||||||
date_format: "%Y-%m-%d",
|
date_format: "%Y-%m-%d",
|
||||||
|
@ -194,14 +188,19 @@ module GitHubChangelogGenerator
|
||||||
enhancement_prefix: "**Implemented enhancements:**",
|
enhancement_prefix: "**Implemented enhancements:**",
|
||||||
git_remote: "origin"
|
git_remote: "origin"
|
||||||
}
|
}
|
||||||
|
end
|
||||||
|
|
||||||
options
|
def self.user_and_project_from_git(options)
|
||||||
|
if options[:user].nil? || options[:project].nil?
|
||||||
|
detect_user_and_project(options, ARGV[0], ARGV[1])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Detects user and project from git
|
# Detects user and project from git
|
||||||
def self.detect_user_and_project(options, arg0 = nil, arg1 = nil)
|
def self.detect_user_and_project(options, arg0 = nil, arg1 = nil)
|
||||||
options[:user], options[:project] = user_project_from_option(arg0, arg1, options[:github_site])
|
options[:user], options[:project] = user_project_from_option(arg0, arg1, options[:github_site])
|
||||||
if !options[:user] || !options[:project]
|
return if options[:user] && options[:project]
|
||||||
|
|
||||||
if ENV["RUBYLIB"] =~ /ruby-debug-ide/
|
if ENV["RUBYLIB"] =~ /ruby-debug-ide/
|
||||||
options[:user] = "skywinder"
|
options[:user] = "skywinder"
|
||||||
options[:project] = "changelog_test"
|
options[:project] = "changelog_test"
|
||||||
|
@ -210,7 +209,6 @@ module GitHubChangelogGenerator
|
||||||
options[:user], options[:project] = user_project_from_remote(remote)
|
options[:user], options[:project] = user_project_from_remote(remote)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
# Try to find user and project name from git remote output
|
# Try to find user and project name from git remote output
|
||||||
#
|
#
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
module GitHubChangelogGenerator
|
module GitHubChangelogGenerator
|
||||||
|
ParserError = Class.new(StandardError)
|
||||||
|
|
||||||
class ParserFile
|
class ParserFile
|
||||||
def initialize(options)
|
def initialize(options)
|
||||||
@options = options
|
@options = options
|
||||||
|
@ -22,7 +24,7 @@ module GitHubChangelogGenerator
|
||||||
value = false if value =~ (/^(false|f|no|n|0)$/i)
|
value = false if value =~ (/^(false|f|no|n|0)$/i)
|
||||||
@options[key_sym] = value
|
@options[key_sym] = value
|
||||||
rescue
|
rescue
|
||||||
raise "Config file #{file} is incorrect in line \"#{line.gsub(/[\n\r]+/, '')}\""
|
raise ParserError, "Config file #{file} is incorrect in line \"#{line.gsub(/[\n\r]+/, '')}\""
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns a the setting as a symbol and its string value sans newlines.
|
# Returns a the setting as a symbol and its string value sans newlines.
|
||||||
|
|
|
@ -53,31 +53,28 @@ module GitHubChangelogGenerator
|
||||||
|
|
||||||
@heading_structures.each do |regexp|
|
@heading_structures.each do |regexp|
|
||||||
matches = Regexp.new(regexp).match(heading)
|
matches = Regexp.new(regexp).match(heading)
|
||||||
captures.merge!(Hash[matches.names.map.zip(matches.captures)]) unless matches.nil?
|
if matches
|
||||||
|
captures.merge!(Hash[matches.names.zip(matches.captures)])
|
||||||
# Try Regular Expressions until you find one that delivers results
|
break
|
||||||
break unless matches.nil?
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
captures
|
captures
|
||||||
end
|
end
|
||||||
|
|
||||||
# Parse the given ChangeLog data into a Hash
|
# Parse the given ChangeLog data into a list of Hashes
|
||||||
#
|
#
|
||||||
# @param [String] data File data from the ChangeLog.md
|
# @param [String] data File data from the ChangeLog.md
|
||||||
# @return [Hash] Parsed data, e.g. [{ 'version' => ..., 'url' => ..., 'date' => ..., 'content' => ...}, ...]
|
# @return [Array<Hash>] Parsed data, e.g. [{ 'version' => ..., 'url' => ..., 'date' => ..., 'content' => ...}, ...]
|
||||||
def parse(data)
|
def parse(data)
|
||||||
sections = data.split(/^## .+?$/)
|
sections = data.split(/^## .+?$/)
|
||||||
headings = data.scan(/^## .+?$/)
|
headings = data.scan(/^## .+?$/)
|
||||||
changelog = []
|
|
||||||
|
|
||||||
headings.each_with_index do |heading, index|
|
headings.each_with_index.map do |heading, index|
|
||||||
captures = parse_heading(heading)
|
section = parse_heading(heading)
|
||||||
captures["content"] = sections.at(index + 1)
|
section["content"] = sections.at(index + 1)
|
||||||
changelog.push captures
|
section
|
||||||
end
|
end
|
||||||
|
|
||||||
changelog
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def read(file_path)
|
def read(file_path)
|
||||||
|
|
|
@ -43,11 +43,9 @@ module GitHubChangelogGenerator
|
||||||
|
|
||||||
task @name do
|
task @name do
|
||||||
# mimick parse_options
|
# mimick parse_options
|
||||||
options = Parser.get_default_options
|
options = Parser.default_options
|
||||||
|
|
||||||
if options[:user].nil? || options[:project].nil?
|
Parser.user_and_project_from_git(options)
|
||||||
Parser.detect_user_and_project(options)
|
|
||||||
end
|
|
||||||
|
|
||||||
OPTIONS.each do |o|
|
OPTIONS.each do |o|
|
||||||
v = instance_variable_get("@#{o}")
|
v = instance_variable_get("@#{o}")
|
||||||
|
|
|
@ -20,11 +20,11 @@ describe GitHubChangelogGenerator::ParserFile do
|
||||||
let(:options) { { params_file: "spec/files/github_changelog_params_incorrect" } }
|
let(:options) { { params_file: "spec/files/github_changelog_params_incorrect" } }
|
||||||
let(:options_before_change) { options.dup }
|
let(:options_before_change) { options.dup }
|
||||||
let(:parse) { GitHubChangelogGenerator::ParserFile.new(options) }
|
let(:parse) { GitHubChangelogGenerator::ParserFile.new(options) }
|
||||||
it { expect { parse.parse! }.to raise_error }
|
it { expect { parse.parse! }.to raise_error(GitHubChangelogGenerator::ParserError) }
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when override default values" do
|
context "when override default values" do
|
||||||
let(:default_options) { GitHubChangelogGenerator::Parser.get_default_options }
|
let(:default_options) { GitHubChangelogGenerator::Parser.default_options }
|
||||||
let(:options) { { params_file: "spec/files/github_changelog_params_override" }.merge(default_options) }
|
let(:options) { { params_file: "spec/files/github_changelog_params_override" }.merge(default_options) }
|
||||||
let(:options_before_change) { options.dup }
|
let(:options_before_change) { options.dup }
|
||||||
let(:parse) { GitHubChangelogGenerator::ParserFile.new(options) }
|
let(:parse) { GitHubChangelogGenerator::ParserFile.new(options) }
|
||||||
|
|
Loading…
Reference in New Issue
Block a user