Avoid nil bug in detect_since_tag
This commit is contained in:
parent
253fe49648
commit
9c6068f026
|
@ -54,13 +54,14 @@ module GitHubChangelogGenerator
|
|||
|
||||
# @return [Object] try to find newest tag using #Reader and :base option if specified otherwise returns nil
|
||||
def detect_since_tag
|
||||
@since_tag ||= @options[:since_tag]
|
||||
if @since_tag.nil? && @options[:base] && File.file?(@options[:base])
|
||||
reader = GitHubChangelogGenerator::Reader.new
|
||||
content = reader.read(@options[:base])
|
||||
@since_tag = content[0]["version"] if content.count && content
|
||||
@since_tag ||= @options.fetch(:since_tag) { version_of_first_item }
|
||||
end
|
||||
@since_tag
|
||||
|
||||
def version_of_first_item
|
||||
return unless File.file?(@options[:base].to_s)
|
||||
|
||||
sections = GitHubChangelogGenerator::Reader.new.read(@options[:base])
|
||||
sections.first["version"] if sections && sections.any?
|
||||
end
|
||||
|
||||
# Return tags after filtering tags in lists provided by option: --between-tags & --exclude-tags
|
||||
|
|
|
@ -206,7 +206,7 @@ describe GitHubChangelogGenerator::Generator do
|
|||
@generator.instance_variable_set :@fetcher, mock
|
||||
end
|
||||
subject do
|
||||
of_tag = @generator.get_time_of_tag tag_mash_with_name("valid_tag")
|
||||
of_tag = @generator.get_time_of_tag(tag_mash_with_name("valid_tag"))
|
||||
of_tag
|
||||
end
|
||||
it { is_expected.to be_a_kind_of(Time) }
|
||||
|
@ -215,31 +215,32 @@ describe GitHubChangelogGenerator::Generator do
|
|||
end
|
||||
|
||||
describe "#sort_tags_by_date" do
|
||||
time1 = Time.now
|
||||
time2 = Time.now
|
||||
time3 = Time.now
|
||||
let(:time1) { Time.now }
|
||||
let(:time2) { Time.now }
|
||||
let(:time3) { Time.now }
|
||||
|
||||
before(:all) do
|
||||
@generator = GitHubChangelogGenerator::Generator.new
|
||||
end
|
||||
context "sort unsorted tags" do
|
||||
tags = tags_mash_from_strings %w(valid_tag1 valid_tag2 valid_tag3)
|
||||
|
||||
before do
|
||||
@generator.instance_variable_set :@tag_times_hash, "valid_tag1" => time1, "valid_tag2" => time2, "valid_tag3" => time3
|
||||
@generator.instance_variable_set(:@tag_times_hash, "valid_tag1" => time1,
|
||||
"valid_tag2" => time2,
|
||||
"valid_tag3" => time3)
|
||||
end
|
||||
|
||||
subject do
|
||||
@generator.sort_tags_by_date tags
|
||||
@generator.sort_tags_by_date(tags)
|
||||
end
|
||||
context "sort unsorted tags" do
|
||||
let(:tags) { tags_mash_from_strings %w(valid_tag1 valid_tag2 valid_tag3) }
|
||||
|
||||
it { is_expected.to be_a_kind_of(Array) }
|
||||
it { is_expected.to match_array(tags.reverse!) }
|
||||
end
|
||||
context "sort sorted tags" do
|
||||
tags = tags_mash_from_strings %w(valid_tag3 valid_tag2 valid_tag1)
|
||||
before do
|
||||
@generator.instance_variable_set :@tag_times_hash, "valid_tag1" => time1, "valid_tag2" => time2, "valid_tag3" => time3
|
||||
end
|
||||
subject do
|
||||
@generator.sort_tags_by_date tags
|
||||
end
|
||||
let(:tags) { tags_mash_from_strings %w(valid_tag3 valid_tag2 valid_tag1) }
|
||||
|
||||
it { is_expected.to be_a_kind_of(Array) }
|
||||
it { is_expected.to match_array(tags) }
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user