diff options
-rw-r--r-- | Dangerfile | 1 | ||||
-rw-r--r-- | danger/css/Dangerfile | 21 | ||||
-rw-r--r-- | lib/gitlab/danger/helper.rb | 19 |
3 files changed, 41 insertions, 0 deletions
diff --git a/Dangerfile b/Dangerfile index d0a605f8d8e..9633a7b95ed 100644 --- a/Dangerfile +++ b/Dangerfile @@ -18,5 +18,6 @@ unless helper.release_automation? danger.import_dangerfile(path: 'danger/roulette') danger.import_dangerfile(path: 'danger/single_codebase') danger.import_dangerfile(path: 'danger/gitlab_ui_wg') + danger.import_dangerfile(path: 'danger/css') danger.import_dangerfile(path: 'danger/ce_ee_vue_templates') end diff --git a/danger/css/Dangerfile b/danger/css/Dangerfile new file mode 100644 index 00000000000..1758a286bcd --- /dev/null +++ b/danger/css/Dangerfile @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +css_paths_to_review = helper.changes_by_category[:css] + +unless css_paths_to_review.empty? + message 'This Merge Request adds page-specific CSS.' + + markdown(<<~MARKDOWN) +## Page Specific CSS review + +This Merge Request adds page specific CSS in the following files: + +* #{css_paths_to_review.map { |path| "`#{path}`" }.join("\n* ")} + +Please double check if any of the additions could be done through utility classes. See: + +- [CSS Cleanup](https://gitlab.com/groups/gitlab-org/-/epics/950) for the guidelines towards cleaning our CSS. +- [Documentation about utility classes](https://docs.gitlab.com/ce/development/fe_guide/style_guide_scss.html#utility-classes) for more information on existing classes. + MARKDOWN + +end diff --git a/lib/gitlab/danger/helper.rb b/lib/gitlab/danger/helper.rb index 1ecf4a12db7..4440033f903 100644 --- a/lib/gitlab/danger/helper.rb +++ b/lib/gitlab/danger/helper.rb @@ -34,6 +34,17 @@ module Gitlab .sort end + # Returns a list of all files that have been added or where new code has been added. + # + # @return [Array<String>] + def additions_files + Set.new + .merge(git.added_files.to_a) + .merge(git.insertions) + .to_a + .sort + end + def ee? ENV['CI_PROJECT_NAME'] == 'gitlab-ee' || File.exist?('../../CHANGELOG-EE.md') end @@ -53,6 +64,12 @@ module Gitlab end end + def additions_by_category + additions_files.each_with_object(Hash.new { |h, k| h[k] = [] }) do |file, hash| + hash[category_for_file(file)] << file + end + end + # Determines the category a file is in, e.g., `:frontend` or `:backend` # @return[Symbol] def category_for_file(file) @@ -80,6 +97,8 @@ module Gitlab %r{\A(CONTRIBUTING|LICENSE|MAINTENANCE|PHILOSOPHY|PROCESS|README)(\.md)?\z} => :none, # To reinstate roulette for documentation, set to `:docs`. %r{\A(ee/)?app/(assets|views)/} => :frontend, + %r{\A(ee/)?app/assets/stylesheets/pages} => :css, + %r{\A(ee/)?public/} => :frontend, %r{\A(ee/)?spec/(javascripts|frontend)/} => :frontend, %r{\A(ee/)?vendor/assets/} => :frontend, |