Merge pull request #332 from olleolleolle/feature/exclude-issues-by-labels
[Refactor] Generator#exclude_issues_by_labels simpler, tested
This commit is contained in:
commit
035e160f5e
|
@ -4,13 +4,12 @@ module GitHubChangelogGenerator
|
|||
# @param [Array] issues
|
||||
# @return [Array] filtered array
|
||||
def exclude_issues_by_labels(issues)
|
||||
unless @options[:exclude_labels].nil?
|
||||
issues = issues.select do |issue|
|
||||
var = issue.labels.map(&:name) & @options[:exclude_labels]
|
||||
!var.any?
|
||||
end
|
||||
return issues if !@options[:exclude_labels] || @options[:exclude_labels].empty?
|
||||
|
||||
issues.reject do |issue|
|
||||
labels = issue.labels.map(&:name)
|
||||
(labels & @options[:exclude_labels]).any?
|
||||
end
|
||||
issues
|
||||
end
|
||||
|
||||
# @return [Array] filtered issues accourding milestone
|
||||
|
|
28
spec/unit/generator/generator_processor_spec.rb
Normal file
28
spec/unit/generator/generator_processor_spec.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
module GitHubChangelogGenerator
|
||||
describe Generator do
|
||||
context "#exclude_issues_by_labels" do
|
||||
let(:label) { double("the-bad-label", name: "BAD") }
|
||||
let(:issue) { double("the-issue-to-be-excluded", labels: [label]) }
|
||||
let(:good_label) { double("a-good-label", name: "GOOD") }
|
||||
let(:good_issue) { double("an-issue-to-be-kept", labels: [good_label]) }
|
||||
let(:issues) { [issue, good_issue] }
|
||||
subject(:generator) { described_class.new(exclude_labels: %w(BAD BOO))}
|
||||
|
||||
it "removes issues with labels in the exclude_label list" do
|
||||
result = generator.exclude_issues_by_labels(issues)
|
||||
|
||||
expect(result).to include(good_issue)
|
||||
expect(result).not_to include(issue)
|
||||
end
|
||||
|
||||
context "with no option given" do
|
||||
subject(:generator) { described_class.new }
|
||||
it "passes everything through when no option given" do
|
||||
result = generator.exclude_issues_by_labels(issues)
|
||||
|
||||
expect(result).to eq(issues)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user