Rspec and README
This commit is contained in:
parent
31b4294ed6
commit
ba7c565374
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +0,0 @@
|
|||
*.swp
|
10
README.md
10
README.md
|
@ -84,6 +84,16 @@ Type `github_changelog_generator --help` for details.
|
|||
|
||||
More detailed info about params you can find in Wiki page: [**Advanced change log generation examples**](https://github.com/skywinder/github-changelog-generator/wiki/Advanced-change-log-generation-examples)
|
||||
|
||||
### Params File
|
||||
You can put Params in a .github_changelog_generator file in Project Root to override default params:
|
||||
|
||||
Example:
|
||||
```
|
||||
unreleased=false
|
||||
future-release=5.0.0
|
||||
since-tag=1.0.0
|
||||
```
|
||||
|
||||
### GitHub token
|
||||
|
||||
Since GitHub allows you to make only 50 requests without authentication it's recommended to run this script with a token (`-t, --token` option)
|
||||
|
|
|
@ -9,12 +9,12 @@ module GitHubChangelogGenerator
|
|||
def self.parse_options
|
||||
options = get_default_options
|
||||
|
||||
parser_file = ParserFile.new options
|
||||
parser_file.parse!
|
||||
|
||||
parser = setup_parser(options)
|
||||
parser.parse!
|
||||
|
||||
parser_file = ParseFile.new options
|
||||
parser_file.parse!
|
||||
|
||||
if options[:user].nil? || options[:project].nil?
|
||||
detect_user_and_project(options, ARGV[0], ARGV[1])
|
||||
end
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
module GitHubChangelogGenerator
|
||||
class ParseFile
|
||||
class ParserFile
|
||||
def initialize(options)
|
||||
@options = options
|
||||
end
|
||||
|
||||
def file
|
||||
File.expand_path(".github_changelog_generator")
|
||||
File.expand_path(@options[:params_file] || ".github_changelog_generator")
|
||||
end
|
||||
|
||||
def has_file?
|
||||
File.exists?(file)
|
||||
def file?
|
||||
File.exist?(file)
|
||||
end
|
||||
|
||||
def file_open
|
||||
|
@ -17,12 +17,20 @@ module GitHubChangelogGenerator
|
|||
end
|
||||
|
||||
def parse!
|
||||
return false unless has_file?
|
||||
return unless file?
|
||||
file_open.each do |line|
|
||||
begin
|
||||
key, value = line.split("=")
|
||||
key_sym = key.sub('-', '_').to_sym
|
||||
@options[key_sym] = value.gsub(/[\n\r]+/, '')
|
||||
end
|
||||
key_sym = key.sub("-", "_").to_sym
|
||||
value = value.gsub(/[\n\r]+/, "")
|
||||
value = true if value =~ (/^(true|t|yes|y|1)$/i)
|
||||
value = false if value =~ (/^(false|f|no|n|0)$/i)
|
||||
@options[key_sym] = value
|
||||
rescue
|
||||
raise "File #{file} is incorrect in line \"#{line.gsub(/[\n\r]+/, '')}\""
|
||||
end
|
||||
end
|
||||
@options
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
0
spec/files/github_changelog_params_empty
Normal file
0
spec/files/github_changelog_params_empty
Normal file
2
spec/files/github_changelog_params_incorrect
Normal file
2
spec/files/github_changelog_params_incorrect
Normal file
|
@ -0,0 +1,2 @@
|
|||
unreleased_label: staging
|
||||
unreleased: false
|
2
spec/files/github_changelog_params_override
Normal file
2
spec/files/github_changelog_params_override
Normal file
|
@ -0,0 +1,2 @@
|
|||
unreleased_label=staging
|
||||
unreleased=false
|
32
spec/unit/parse_file_spec.rb
Normal file
32
spec/unit/parse_file_spec.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
describe GitHubChangelogGenerator::ParserFile do
|
||||
describe ".github_changelog_generator" do
|
||||
context "when no has file" do
|
||||
let(:options) { {} }
|
||||
let(:parse) { GitHubChangelogGenerator::ParserFile.new(options) }
|
||||
subject { parse.parse! }
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
|
||||
context "when file is empty" do
|
||||
let(:options) { { params_file: "spec/files/github_changelog_params_empty" } }
|
||||
let(:parse) { GitHubChangelogGenerator::ParserFile.new(options) }
|
||||
subject { parse.parse! }
|
||||
it { is_expected.to be_a(Hash) }
|
||||
it { is_expected.to eq(options) }
|
||||
end
|
||||
|
||||
context "when file is incorrect" do
|
||||
let(:options) { { params_file: "spec/files/github_changelog_params_incorrect" } }
|
||||
let(:parse) { GitHubChangelogGenerator::ParserFile.new(options) }
|
||||
it { expect { fail.raise! }.to raise_error RuntimeError }
|
||||
end
|
||||
|
||||
context "when override default values" do
|
||||
let(:options) { { params_file: "spec/files/github_changelog_params_override" }.merge(GitHubChangelogGenerator::Parser.get_default_options) }
|
||||
let(:parse) { GitHubChangelogGenerator::ParserFile.new(options) }
|
||||
subject { parse.parse! }
|
||||
it { is_expected.to be_a(Hash) }
|
||||
it { is_expected.to eq(options.merge(unreleased_label: "staging", unreleased: false)) }
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user