debian-mirror-gitlab/danger/qa_selector/Dangerfile

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

66 lines
2.2 KiB
Ruby
Raw Normal View History

2023-03-04 22:38:38 +05:30
# frozen_string_literal: true
2023-05-08 21:46:49 +05:30
return if helper.stable_branch?
2023-04-23 21:23:45 +05:30
data_qa_selectors = /qa_selector|data-qa-selector/
deprecated_qa_selectors = /(?!.*\bdata-qa-)(?=class=.*qa-.*|class: .*qa-.*)/
def filter_changed_lines(files, pattern)
2023-03-04 22:38:38 +05:30
lines = []
files.each do |file|
2023-04-23 21:23:45 +05:30
qa_selector_changed_lines = helper.changed_lines(file).select { |line| line =~ pattern }
2023-03-04 22:38:38 +05:30
next unless qa_selector_changed_lines.any?
lines += ["file `#{file}`:", qa_selector_changed_lines]
end
lines
end
changed_code_files = helper.changed_files(/\.(vue|haml|js|rb)$/)
return if changed_code_files.empty?
2023-04-23 21:23:45 +05:30
lines_with_qa_selectors = filter_changed_lines(changed_code_files, data_qa_selectors)
deprecated_qa_class = filter_changed_lines(changed_code_files, deprecated_qa_selectors)
2023-03-04 22:38:38 +05:30
2023-04-23 21:23:45 +05:30
return if (lines_with_qa_selectors + deprecated_qa_class).empty?
2023-03-04 22:38:38 +05:30
markdown(<<~MARKDOWN)
## QA Selectors
MARKDOWN
if lines_with_qa_selectors.any?
markdown(<<~MARKDOWN)
The following changed lines in this MR contain QA selectors:
* #{lines_with_qa_selectors.join("\n* ")}
Please ensure `e2e:package-and-test` job is run and the tests are passing.
For the list of known failures please refer to [the latest pipeline triage issue](https://gitlab.com/gitlab-org/quality/pipeline-triage/-/issues).
If your changes are under a feature flag, please check our [Testing with feature flags](https://docs.gitlab.com/ee/development/testing_guide/end_to_end/feature_flags.html#automatic-test-execution-when-a-feature-flag-definition-changes) documentation for instructions.
MARKDOWN
warn "This merge request contains lines with QA selectors. Please ensure `e2e:package-and-test` job is run."
end
2023-04-23 21:23:45 +05:30
if deprecated_qa_class.any?
markdown(<<~MARKDOWN)
### Deprecated .qa-selector class
The following lines in this MR contain deprecated qa class selectors:
* #{deprecated_qa_class.join("\n* ")}
Please ensure all deprecated qa class selectors are replaced with data-qa-selectors in accordance with our [Testing Guide](https://docs.gitlab.com/ee/development/testing_guide/end_to_end/page_objects.html#data-qa-selector-vs-qa-selector).
MARKDOWN
warn "This merge request contains deprecated .qa-selector CSS class. Please use data-qa-selector attribute instead."
end