summaryrefslogtreecommitdiff
path: root/danger/pajamas/Dangerfile
blob: 36bf7672cbfdbddf8a4aa0aba78b6697cb6a11dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# frozen_string_literal: true
# rubocop:disable Style/SignalException

PATTERNS = %w[
  %a.btn.btn-
  %button.btn.btn-
  .alert
  .alert-danger
  .alert-dismissible
  .alert-info
  .alert-link
  .alert-primary
  .alert-success
  .alert-warning
  .nav-tabs
  .toolbar-button-icon
  .tooltip
  .tooltip-inner
  <button
  <tabs
  bs-callout
  createFlash
  deprecated-modal
  gl-deprecated-button
  gl-deprecated-dropdown
  gl-deprecated-dropdown-divider
  gl-deprecated-dropdown-header
  gl-deprecated-dropdown-item
  has-tooltip
  has_tooltip
  initDeprecatedJQueryDropdown
  loading-button
  v-popover
  v-tooltip
  with_tooltip
].freeze

BLOCKING_PATTERNS = %w[
  pagination-button
  graphql_pagination
].freeze

def get_added_lines(files)
  lines = []
  files.each do |file|
    lines += helper.changed_lines(file).select { |line| %r{^[+]}.match?(line) }
  end
  lines
end

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)
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 + blocking_components_in_mr).empty?

markdown(<<~MARKDOWN)
  ## Deprecated components

MARKDOWN

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.

    * #{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