Merge branch 'develop'

This commit is contained in:
Petr Korolev 2015-08-24 17:53:06 +03:00
commit ddf2624bf9
3 changed files with 92 additions and 9 deletions

View File

@ -52,6 +52,7 @@ module GitHubChangelogGenerator
[newer_tag_link, newer_tag_name, newer_tag_time] [newer_tag_link, newer_tag_name, newer_tag_time]
end end
# @return [Object] try to find newest tag using #Reader and :base option if specified otherwise returns nil
def detect_since_tag def detect_since_tag
if @options[:base] && File.file?(@options[:base]) if @options[:base] && File.file?(@options[:base])
reader = GitHubChangelogGenerator::Reader.new reader = GitHubChangelogGenerator::Reader.new
@ -69,6 +70,8 @@ module GitHubChangelogGenerator
filter_excluded_tags(filtered_tags) filter_excluded_tags(filtered_tags)
end end
# @param [Array] all_tags all tags
# @return [Array] filtered tags according :since_tag option
def filter_since_tag(all_tags) def filter_since_tag(all_tags)
filtered_tags = all_tags filtered_tags = all_tags
tag = @options[:since_tag] tag = @options[:since_tag]
@ -88,6 +91,29 @@ module GitHubChangelogGenerator
filtered_tags filtered_tags
end end
# @param [Array] all_tags all tags
# @return [Array] filtered tags according :due_tag option
def filter_due_tag(all_tags)
filtered_tags = all_tags
tag = @options[:due_tag]
if tag
if (all_tags.count > 0) && (all_tags.map(&:name).include? tag)
idx = all_tags.index { |t| t.name == tag }
last_index = all_tags.count - 1
if idx > 0 && idx < last_index
filtered_tags = all_tags[idx + 1..last_index]
else
filtered_tags = []
end
else
Helper.log.warn "Warning: can't find tag #{tag}, specified with --due-tag option."
end
end
filtered_tags
end
# @param [Array] all_tags all tags
# @return [Array] filtered tags according :between_tags option
def filter_between_tags(all_tags) def filter_between_tags(all_tags)
filtered_tags = all_tags filtered_tags = all_tags
if @options[:between_tags] if @options[:between_tags]
@ -101,6 +127,8 @@ module GitHubChangelogGenerator
filtered_tags filtered_tags
end end
# @param [Array] all_tags all tags
# @return [Array] filtered tags according :exclude_tags option
def filter_excluded_tags(all_tags) def filter_excluded_tags(all_tags)
filtered_tags = all_tags filtered_tags = all_tags
if @options[:exclude_tags] if @options[:exclude_tags]

View File

@ -119,6 +119,9 @@ module GitHubChangelogGenerator
opts.on("--since-tag x", "Change log will start after specified tag") do |v| opts.on("--since-tag x", "Change log will start after specified tag") do |v|
options[:since_tag] = v options[:since_tag] = v
end end
opts.on("--due-tag x", "Change log will end before specified tag") do |v|
options[:due_tag] = v
end
opts.on("--max-issues [NUMBER]", Integer, "Max number of issues to fetch from GitHub. Default is unlimited") do |max| opts.on("--max-issues [NUMBER]", Integer, "Max number of issues to fetch from GitHub. Default is unlimited") do |max|
options[:max_issues] = max options[:max_issues] = max
end end

View File

@ -90,6 +90,7 @@ describe GitHubChangelogGenerator::Generator do
end end
describe "#filter_since_tag" do describe "#filter_since_tag" do
context "with filled array" do
subject { generator.filter_since_tag(tags_mash_from_strings(%w(1 2 3))) } subject { generator.filter_since_tag(tags_mash_from_strings(%w(1 2 3))) }
context "with valid since tag" do context "with valid since tag" do
@ -99,12 +100,63 @@ describe GitHubChangelogGenerator::Generator do
end end
context "with invalid since tag" do context "with invalid since tag" do
let(:generator) { GitHubChangelogGenerator::Generator.new(since_tag: %w(invalid tags)) } let(:generator) { GitHubChangelogGenerator::Generator.new(since_tag: "Invalid tag") }
it { is_expected.to be_a Array } it { is_expected.to be_a Array }
it { is_expected.to match_array(tags_mash_from_strings(%w(1 2 3))) } it { is_expected.to match_array(tags_mash_from_strings(%w(1 2 3))) }
end end
end end
context "with empty array" do
subject { generator.filter_since_tag(tags_mash_from_strings(%w())) }
context "with valid since tag" do
let(:generator) { GitHubChangelogGenerator::Generator.new(since_tag: "2") }
it { is_expected.to be_a Array }
it { is_expected.to match_array(tags_mash_from_strings(%w())) }
end
context "with invalid since tag" do
let(:generator) { GitHubChangelogGenerator::Generator.new(since_tag: "Invalid tag") }
it { is_expected.to be_a Array }
it { is_expected.to match_array(tags_mash_from_strings(%w())) }
end
end
end
describe "#filter_due_tag" do
context "with filled array" do
subject { generator.filter_due_tag(tags_mash_from_strings(%w(1 2 3))) }
context "with valid due tag" do
let(:generator) { GitHubChangelogGenerator::Generator.new(due_tag: "2") }
it { is_expected.to be_a Array }
it { is_expected.to match_array(tags_mash_from_strings(%w(3))) }
end
context "with invalid due tag" do
let(:generator) { GitHubChangelogGenerator::Generator.new(due_tag: "Invalid tag") }
it { is_expected.to be_a Array }
it { is_expected.to match_array(tags_mash_from_strings(%w(1 2 3))) }
end
end
context "with empty array" do
subject { generator.filter_due_tag(tags_mash_from_strings(%w())) }
context "with valid due tag" do
let(:generator) { GitHubChangelogGenerator::Generator.new(due_tag: "2") }
it { is_expected.to be_a Array }
it { is_expected.to match_array(tags_mash_from_strings(%w())) }
end
context "with invalid due tag" do
let(:generator) { GitHubChangelogGenerator::Generator.new(due_tag: "Invalid tag") }
it { is_expected.to be_a Array }
it { is_expected.to match_array(tags_mash_from_strings(%w())) }
end
end
end
describe "#get_time_of_tag" do describe "#get_time_of_tag" do
current_time = Time.now current_time = Time.now
before(:all) { @generator = GitHubChangelogGenerator::Generator.new } before(:all) { @generator = GitHubChangelogGenerator::Generator.new }