Commit 5a3de8cb authored by Anastasia McDonald's avatar Anastasia McDonald Committed by Rémy Coutable

Change Pajamas Danger rule to fail on migrated components

See second task of https://gitlab.com/gitlab-com/www-gitlab-com/-/issues/8596
parent b33510a2
# frozen_string_literal: true
# rubocop:disable Style/SignalException
PATTERNS = %w[
createFlash
......@@ -12,6 +13,9 @@ PATTERNS = %w[
initDeprecatedJQueryDropdown
].freeze
BLOCKING_PATTERNS = %w[
].freeze
def get_added_lines(files)
lines = []
files.each do |file|
......@@ -25,19 +29,34 @@ changed_vue_haml_files = helper.changed_files(/.vue$|.haml$/)
return if changed_vue_haml_files.empty?
changed_lines_in_mr = get_added_lines(changed_vue_haml_files)
has_deprecated_components = changed_lines_in_mr.select { |i| i[/#{PATTERNS.join("|")}/] }
deprecated_components_in_mr = PATTERNS.select { |s| has_deprecated_components.join(" ")[s] }
deprecated_components_in_mr = PATTERNS.select { |pattern| changed_lines_in_mr.any? { |line| line[pattern] } }
blocking_components_in_mr = BLOCKING_PATTERNS.select { |pattern| changed_lines_in_mr.any? { |line| line[pattern] } }
return if deprecated_components_in_mr.empty?
warn "This merge request contains deprecated components. Please consider using Pajamas components instead."
return if (deprecated_components_in_mr + blocking_components_in_mr).empty?
markdown(<<~MARKDOWN)
## Deprecated components
The following components are deprecated:
MARKDOWN
* #{deprecated_components_in_mr.join("\n* ")}
if blocking_components_in_mr.any?
markdown(<<~MARKDOWN)
These deprecated components have already been migrated and can no longer be used. Please use [Pajamas components](https://design.gitlab.com/components/status/) instead.
Please consider using [Pajamas components](https://design.gitlab.com/components/status/) instead.
MARKDOWN
* #{blocking_components_in_mr.join("\n* ")}
MARKDOWN
fail "This merge request contains deprecated components that have been migrated and can no longer be used. Please use Pajamas components instead."
end
if deprecated_components_in_mr.any?
markdown(<<~MARKDOWN)
These deprecated components are in the process of being migrated. Please consider using [Pajamas components](https://design.gitlab.com/components/status/) instead.
* #{deprecated_components_in_mr.join("\n* ")}
MARKDOWN
warn "This merge request contains deprecated components. Please consider using Pajamas components instead."
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment