Danger: Ensure that all files are categorized
Problem
In MRs, from time to time, we are seeing the following warning from Danger:
!107001 (comment 1209582332) |
---|
![]() |
The usual follow-up from the actions is to add a file/directory to https://gitlab.com/gitlab-org/gitlab/blob/master/tooling/danger/project_helper.rb as suggested in that message.
This process is tedious and slow and we keep adding new categorized files.
Proposed solution
Ensure that all files are categorized via RSpec.
Example
Adding the following code to spec/tooling/danger/project_helper_spec.rb
could help to catch files without any category.
describe 'uncategorized files' do
let(:ignore_files) do
%r{
(?:
\.gitkeep |
\.gitignore
)
}x
end
it 'has none' do
files = `git ls-files`.split("\n").grep_v(ignore_files)
helper = project_helper.helper
uncategorized = files.select { helper.categories_for_file(_1).include?(:unknown) }
message = -> do
<<~MESSAGE
The following files have no category assigned:
#{uncategorized.join("\n")}
MESSAGE
end
expect(uncategorized).to be_empty, message
end
end
end
Running this patch gives the following list of files without category.
$ bin/rspec spec/tooling/danger/project_helper_spec.rb -e uncategorized
Run options: include {:full_description=>/uncategorized/}
Randomized with seed 1282
Tooling::Danger::ProjectHelper
#categories_for_file
uncategorized files
has none (FAILED - 1)
Failures:
1) Tooling::Danger::ProjectHelper#categories_for_file uncategorized files has none
Failure/Error: expect(uncategorized).to be_empty, message
The following files have no category assigned:
.csscomb.json
.dockerignore
.foreman
.git-blame-ignore-revs
.gitattributes
.gitlab/agents/review-apps/config.yaml
.gitlab/changelog_config.yml
.gitlab/route-map.yml
.gitlab/sast-ruleset.toml
.gitlab/secret-detection-ruleset.toml
.lefthook/pre-push/merge_conflicts
.license_encryption_key.pub
.mailmap
.markdownlint.yml
.projections.json.example
.solargraph.yml.example
.test_license_encryption_key.pub
.theia/settings.json
.vale.ini
.vscode/extensions.json
.yamllint
Dockerfile.assets
Guardfile
INSTALLATION_TYPE
Pipfile
Pipfile.lock
VERSION
config.ru
crowdin.yml
doc/.vale/vale-json.tmpl
doc/.vale/vale.tmpl
doc/ci/review_apps/img/continuous-delivery-review-apps.svg
doc/development/img/cache-hit.svg
doc/development/img/cache-miss.svg
doc/development/img/elasticsearch_architecture.svg
doc/user/img/markdown_audio.mp3
doc/user/img/markdown_video.mp4
docker-compose.yml
ee/LICENSE
ee/fixtures/insights/default.yml
fixtures/emojis/aliases.json
fixtures/emojis/digests.json
fixtures/emojis/index.json
fixtures/emojis/intents.json
fixtures/lib/gitlab/graphql/queries/author.fragment.graphql
fixtures/lib/gitlab/graphql/queries/bad.fragment.graphql
fixtures/lib/gitlab/graphql/queries/bad_argument.graphql
fixtures/lib/gitlab/graphql/queries/client.query.graphql
fixtures/lib/gitlab/graphql/queries/client_unused_fragment.graphql
fixtures/lib/gitlab/graphql/queries/connection.query.graphql
fixtures/lib/gitlab/graphql/queries/deeply/nested/bad_import.graphql
fixtures/lib/gitlab/graphql/queries/deeply/nested/query.graphql
fixtures/lib/gitlab/graphql/queries/duplicate_imports.graphql
fixtures/lib/gitlab/graphql/queries/ee/author.fragment.graphql
fixtures/lib/gitlab/graphql/queries/ee_else_ce.import.graphql
fixtures/lib/gitlab/graphql/queries/missing_argument.graphql
fixtures/lib/gitlab/graphql/queries/mixed_client.query.graphql
fixtures/lib/gitlab/graphql/queries/mixed_client_invalid.query.graphql
fixtures/lib/gitlab/graphql/queries/mixed_client_skipped_argument.graphql
fixtures/lib/gitlab/graphql/queries/mixed_client_unused_fragment.graphql
fixtures/lib/gitlab/graphql/queries/plans.customer.mutation.graphql
fixtures/lib/gitlab/graphql/queries/plans.customer.query.graphql
fixtures/lib/gitlab/graphql/queries/post.fragment.graphql
fixtures/lib/gitlab/graphql/queries/post_by_slug.graphql
fixtures/lib/gitlab/graphql/queries/post_by_slug.with_import.graphql
fixtures/lib/gitlab/graphql/queries/post_by_slug.with_import.misspelled.graphql
fixtures/lib/gitlab/graphql/queries/syntax-error.graphql
fixtures/lib/gitlab/graphql/queries/thingy.fragment.graphql
fixtures/lib/gitlab/graphql/queries/transitive_bad_import.fragment.graphql
fixtures/lib/gitlab/graphql/queries/transitive_bad_import.graphql
fixtures/lib/gitlab/graphql/queries/typedefs.graphql
fixtures/lib/gitlab/graphql/queries/unused_import.graphql
fixtures/lib/gitlab/graphql/queries/wrong_field.graphql
fixtures/lib/gitlab/graphql/queries/wrong_field.import.graphql
glfm_specification/output_example_snapshots/snapshot_spec.html
glfm_specification/output_spec/spec.html
locale/am_ET/gitlab.po
locale/ar_SA/gitlab.po
locale/as_IN/gitlab.po
locale/az_AZ/gitlab.po
locale/ba_RU/gitlab.po
locale/bg/gitlab.po
locale/bg/gitlab.po.time_stamp
locale/bn_BD/gitlab.po
locale/bn_IN/gitlab.po
locale/br_FR/gitlab.po
locale/bs_BA/gitlab.po
locale/ca_ES/gitlab.po
locale/cs_CZ/gitlab.po
locale/cy_GB/gitlab.po
locale/da_DK/gitlab.po
locale/de/gitlab.po
locale/de/gitlab.po.time_stamp
locale/el_GR/gitlab.po
locale/en_GB/gitlab.po
locale/eo/gitlab.po
locale/eo/gitlab.po.time_stamp
locale/es/gitlab.po
locale/es/gitlab.po.time_stamp
locale/et_EE/gitlab.po
locale/fa_IR/gitlab.po
locale/fi_FI/gitlab.po
locale/fil_PH/gitlab.po
locale/fr/gitlab.po
locale/fr/gitlab.po.time_stamp
locale/gl_ES/gitlab.po
locale/he_IL/gitlab.po
locale/hi_IN/gitlab.po
locale/hr_HR/gitlab.po
locale/hu_HU/gitlab.po
locale/hy_AM/gitlab.po
locale/id_ID/gitlab.po
locale/ig_NG/gitlab.po
locale/is_IS/gitlab.po
locale/it/gitlab.po
locale/it/gitlab.po.time_stamp
locale/ja/gitlab.po
locale/ja/gitlab.po.time_stamp
locale/ka_GE/gitlab.po
locale/kab/gitlab.po
locale/ko/gitlab.po
locale/ko/gitlab.po.time_stamp
locale/ku_TR/gitlab.po
locale/ky_KG/gitlab.po
locale/lt_LT/gitlab.po
locale/mk_MK/gitlab.po
locale/ml_IN/gitlab.po
locale/mn_MN/gitlab.po
locale/nb_NO/gitlab.po
locale/nl_NL/gitlab.po
locale/or_IN/gitlab.po
locale/pa_IN/gitlab.po
locale/pa_PK/gitlab.po
locale/pl_PL/gitlab.po
locale/pt_BR/gitlab.po
locale/pt_BR/gitlab.po.time_stamp
locale/pt_PT/gitlab.po
locale/ro_RO/gitlab.po
locale/ru/gitlab.po
locale/ru/gitlab.po.time_stamp
locale/si_LK/gitlab.po
locale/sk_SK/gitlab.po
locale/sl_SI/gitlab.po
locale/sq_AL/gitlab.po
locale/sr_CS/gitlab.po
locale/sr_SP/gitlab.po
locale/sv_SE/gitlab.po
locale/sw_KE/gitlab.po
locale/ta_IN/gitlab.po
locale/th_TH/gitlab.po
locale/tr_TR/gitlab.po
locale/uk/gitlab.po
locale/uk/gitlab.po.time_stamp
locale/ur_PK/gitlab.po
locale/uz_UZ/gitlab.po
locale/vi_VN/gitlab.po
locale/zh_CN/gitlab.po
locale/zh_CN/gitlab.po.time_stamp
locale/zh_HK/gitlab.po
locale/zh_HK/gitlab.po.time_stamp
locale/zh_TW/gitlab.po
locale/zh_TW/gitlab.po.time_stamp
patches/@rails+ujs+6.1.4-7.patch
"workhorse/testdata/file-\303\244.pdf"
# ./spec/tooling/danger/project_helper_spec.rb:318:in `block (4 levels) in <top (required)>'
Finished in 3.61 seconds (files took 1.2 seconds to load)
1 example, 1 failure
Failed examples:
rspec ./spec/tooling/danger/project_helper_spec.rb:305 # Tooling::Danger::ProjectHelper#categories_for_file uncategorized files has none
Randomized with seed 1282
If some of these files don't have a category we can still use :none
.
Risks
In order to avoid broken master we'd need to make sure that this check is always being run and not only if project_helper
changes.
Alternatively, we could not run this spec on master
.