summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2019-02-07 12:55:23 +0000
committerNick Thomas <nick@gitlab.com>2019-02-13 16:30:02 +0000
commitf034a352507f09aca1a656f2bbf88c8dd8af103b (patch)
tree76795b58872436bde6ffb8b592bbfec20f11d079
parentbd17881bf592c0b8c662cc189c4e27bed8895f98 (diff)
downloadgitlab-ce-f034a352507f09aca1a656f2bbf88c8dd8af103b.tar.gz
Move change category detection to a helper
-rw-r--r--danger/documentation/Dangerfile13
-rw-r--r--danger/plugins/helper.rb17
2 files changed, 18 insertions, 12 deletions
diff --git a/danger/documentation/Dangerfile b/danger/documentation/Dangerfile
index 188331cc87c..76e81f5f62f 100644
--- a/danger/documentation/Dangerfile
+++ b/danger/documentation/Dangerfile
@@ -1,17 +1,6 @@
# frozen_string_literal: true
-# All the files/directories that should be reviewed by the Docs team.
-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)
+docs_paths_to_review = helper.changes_by_category[:documentation]
unless docs_paths_to_review.empty?
message 'This merge request adds or changes files that require a ' \
diff --git a/danger/plugins/helper.rb b/danger/plugins/helper.rb
index f4eb9119266..1a2710463ad 100644
--- a/danger/plugins/helper.rb
+++ b/danger/plugins/helper.rb
@@ -30,5 +30,22 @@ module Danger
.to_a
.sort
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