debian-mirror-gitlab/danger/specs/Dangerfile

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

62 lines
2.6 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2020-07-28 23:09:34 +05:30
NO_SPECS_LABELS = [
2022-05-07 20:08:51 +05:30
'maintenance::pipelines',
2023-03-04 22:38:38 +05:30
'maintenance::refactor',
2022-05-07 20:08:51 +05:30
'maintenance::workflow',
2020-07-28 23:09:34 +05:30
'documentation',
'QA'
].freeze
2021-04-29 21:17:54 +05:30
NO_NEW_SPEC_MESSAGE = <<~MSG
2018-11-18 11:00:15 +05:30
You've made some app changes, but didn't add any tests.
That's OK as long as you're refactoring existing code,
but please consider adding any of the %<labels>s labels.
MSG
2021-04-29 21:17:54 +05:30
EE_CHANGE_WITH_FOSS_SPEC_CHANGE_MESSAGE = <<~MSG
2020-06-23 00:09:42 +05:30
You've made some EE-specific changes, but only made changes to FOSS tests.
This could be a sign that you're testing an EE-specific behavior in a FOSS test.
2018-11-18 11:00:15 +05:30
2020-06-23 00:09:42 +05:30
Please make sure the spec files pass in AS-IF-FOSS mode either:
1. Locally with `FOSS_ONLY=1 bin/rspec -- %<spec_files>s`.
1. In the MR pipeline by verifying that the `rspec foss-impact` job has passed.
2021-11-18 22:05:49 +05:30
1. In the MR pipelines by setting the ~"pipeline:run-as-if-foss" label on the MR (you can do it with the `/label ~"pipeline:run-as-if-foss"` quick action) and start a new MR pipeline.
2020-06-23 00:09:42 +05:30
MSG
2021-04-29 21:17:54 +05:30
CONTROLLER_SPEC_DEPRECATION_MESSAGE = <<~MSG
2021-03-08 18:12:59 +05:30
Do not add new controller specs. We are moving from controller specs to
request specs (and/or feature specs). Please add request specs under
`/spec/requests` and/or `/ee/spec/requests` instead.
See https://gitlab.com/groups/gitlab-org/-/epics/5076 for information.
MSG
2021-11-18 22:05:49 +05:30
all_changed_files = helper.all_changed_files
has_app_changes = all_changed_files.grep(%r{\A(app|lib|db/(geo/)?(post_)?migrate)/}).any?
has_ee_app_changes = all_changed_files.grep(%r{\Aee/(app|lib|db/(geo/)?(post_)?migrate)/}).any?
spec_changes = specs.changed_specs_files(ee: :exclude)
2020-06-23 00:09:42 +05:30
has_spec_changes = spec_changes.any?
2021-11-18 22:05:49 +05:30
has_ee_spec_changes = specs.changed_specs_files(ee: :only).any?
2022-06-21 17:19:12 +05:30
new_specs_needed = (helper.mr_labels & NO_SPECS_LABELS).empty?
2018-11-18 11:00:15 +05:30
2020-06-23 00:09:42 +05:30
if (has_app_changes || has_ee_app_changes) && !(has_spec_changes || has_ee_spec_changes) && new_specs_needed
2020-05-24 23:13:21 +05:30
warn format(NO_NEW_SPEC_MESSAGE, labels: helper.labels_list(NO_SPECS_LABELS)), sticky: false
2018-11-18 11:00:15 +05:30
end
2020-06-23 00:09:42 +05:30
# The only changes outside `ee/` are in `spec/`
if has_ee_app_changes && has_spec_changes && !(has_app_changes || has_ee_spec_changes)
2021-11-18 22:05:49 +05:30
warn format(EE_CHANGE_WITH_FOSS_SPEC_CHANGE_MESSAGE, spec_files: spec_changes.join(" ")), sticky: false
2020-06-23 00:09:42 +05:30
end
2021-03-08 18:12:59 +05:30
# Forbidding a new file addition under `/spec/controllers` or `/ee/spec/controllers`
2022-01-26 12:08:38 +05:30
if helper.changes.added.files.grep(%r{^(ee/)?spec/controllers/}).any?
2021-03-08 18:12:59 +05:30
warn CONTROLLER_SPEC_DEPRECATION_MESSAGE
end
2021-11-18 22:05:49 +05:30
specs.changed_specs_files.each do |filename|
specs.add_suggestions_for_match_with_array(filename)
2022-11-25 23:54:43 +05:30
specs.add_suggestions_for_project_factory_usage(filename)
2023-03-04 22:38:38 +05:30
specs.add_suggestions_for_feature_category(filename)
2021-11-18 22:05:49 +05:30
end