Refactoring: introduce local, return early
- use #reject - add basic spec around it
This commit is contained in:
parent
4ceb065cae
commit
87b9962a8d
|
@ -4,14 +4,13 @@ module GitHubChangelogGenerator
|
||||||
# @param [Array] issues
|
# @param [Array] issues
|
||||||
# @return [Array] filtered array
|
# @return [Array] filtered array
|
||||||
def exclude_issues_by_labels(issues)
|
def exclude_issues_by_labels(issues)
|
||||||
unless @options[:exclude_labels].nil?
|
return issues if !@options[:exclude_labels] || @options[:exclude_labels].empty?
|
||||||
issues = issues.select do |issue|
|
|
||||||
var = issue.labels.map(&:name) & @options[:exclude_labels]
|
issues.reject do |issue|
|
||||||
!var.any?
|
labels = issue.labels.map(&:name)
|
||||||
|
(labels & @options[:exclude_labels]).any?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
issues
|
|
||||||
end
|
|
||||||
|
|
||||||
# @return [Array] filtered issues accourding milestone
|
# @return [Array] filtered issues accourding milestone
|
||||||
def filter_by_milestone(filtered_issues, tag_name, all_issues)
|
def filter_by_milestone(filtered_issues, tag_name, all_issues)
|
||||||
|
|
16
spec/unit/generator/generator_processor_spec.rb
Normal file
16
spec/unit/generator/generator_processor_spec.rb
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
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(:issues) { [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 be_empty
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user