Move change category detection to a helper

This commit is contained in:
Nick Thomas 2019-02-07 12:55:23 +00:00
parent bd17881bf5
commit f034a35250
No known key found for this signature in database
GPG key ID: 2A313A47AFADACE9
2 changed files with 18 additions and 12 deletions

View file

@ -1,17 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
# All the files/directories that should be reviewed by the Docs team. docs_paths_to_review = helper.changes_by_category[:documentation]
DOCS_FILES = [
'doc/'
].freeze
def docs_paths_requiring_review(files)
files.select do |file|
DOCS_FILES.any? { |pattern| file.start_with?(pattern) }
end
end
docs_paths_to_review = docs_paths_requiring_review(helper.all_changed_files)
unless docs_paths_to_review.empty? unless docs_paths_to_review.empty?
message 'This merge request adds or changes files that require a ' \ message 'This merge request adds or changes files that require a ' \

View file

@ -30,5 +30,22 @@ module Danger
.to_a .to_a
.sort .sort
end end
# @return [Hash<String,Array<String>>]
def changes_by_category
all_changed_files.inject(Hash.new { |h, k| h[k] = [] }) do |hsh, file|
hsh[category_for_file(file)] << file
end
end
def category_for_file(file)
_, category = CATEGORIES.find { |regexp, _| regexp.match?(file) }
category || :unknown
end
CATEGORIES = {
%r{\Adoc/} => :documentation
}
end end
end end