Commit 69778de7 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Merge branch '218241-allow-files-to-have-multiple-categories' into 'master'

Allow files to belong to multiple categories in the roulette

Closes #218241

See merge request gitlab-org/gitlab!35660
parents 4eef5e5f 99ba0bc7
......@@ -73,16 +73,16 @@ module Gitlab
# @return [Hash<String,Array<String>>]
def changes_by_category
all_changed_files.each_with_object(Hash.new { |h, k| h[k] = [] }) do |file, hash|
hash[category_for_file(file)] << file
categories_for_file(file).each { |category| hash[category] << file }
end
end
# Determines the category a file is in, e.g., `:frontend` or `:backend`
# @return[Symbol]
def category_for_file(file)
_, category = CATEGORIES.find { |regexp, _| regexp.match?(file) }
# Determines the categories a file is in, e.g., `[:frontend]`, `[:backend]`, or `%i[frontend engineering_productivity]`.
# @return Array<Symbol>
def categories_for_file(file)
_, categories = CATEGORIES.find { |regexp, _| regexp.match?(file) }
category || :unknown
Array(categories || :unknown)
end
# Returns the GFM for a category label, making its best guess if it's not
......@@ -125,10 +125,13 @@ module Gitlab
jest\.config\.js |
package\.json |
yarn\.lock |
config/.+\.js |
\.gitlab/ci/frontend\.gitlab-ci\.yml
config/.+\.js
)\z}x => :frontend,
%r{(\A|/)(
\.gitlab/ci/frontend\.gitlab-ci\.yml
)\z}x => %i[frontend engineering_productivity],
%r{\A(ee/)?db/(?!fixtures)[^/]+} => :database,
%r{\A(ee/)?lib/gitlab/(database|background_migration|sql|github_import)(/|\.rb)} => :database,
%r{\A(app/models/project_authorization|app/services/users/refresh_authorized_projects_service)(/|\.rb)} => :database,
......
......@@ -165,125 +165,127 @@ RSpec.describe Gitlab::Danger::Helper do
end
end
describe '#category_for_file' do
where(:path, :expected_category) do
'doc/foo' | :none
'CONTRIBUTING.md' | :none
'LICENSE' | :none
'MAINTENANCE.md' | :none
'PHILOSOPHY.md' | :none
'PROCESS.md' | :none
'README.md' | :none
'ee/doc/foo' | :unknown
'ee/README' | :unknown
'app/assets/foo' | :frontend
'app/views/foo' | :frontend
'public/foo' | :frontend
'scripts/frontend/foo' | :frontend
'spec/javascripts/foo' | :frontend
'spec/frontend/bar' | :frontend
'vendor/assets/foo' | :frontend
'babel.config.js' | :frontend
'jest.config.js' | :frontend
'package.json' | :frontend
'yarn.lock' | :frontend
'config/foo.js' | :frontend
'config/deep/foo.js' | :frontend
'ee/app/assets/foo' | :frontend
'ee/app/views/foo' | :frontend
'ee/spec/javascripts/foo' | :frontend
'ee/spec/frontend/bar' | :frontend
'app/models/foo' | :backend
'bin/foo' | :backend
'config/foo' | :backend
'lib/foo' | :backend
'rubocop/foo' | :backend
'spec/foo' | :backend
'spec/foo/bar' | :backend
'ee/app/foo' | :backend
'ee/bin/foo' | :backend
'ee/spec/foo' | :backend
'ee/spec/foo/bar' | :backend
'generator_templates/foo' | :backend
'vendor/languages.yml' | :backend
'vendor/licenses.csv' | :backend
'file_hooks/examples/' | :backend
'Gemfile' | :backend
'Gemfile.lock' | :backend
'Rakefile' | :backend
'FOO_VERSION' | :backend
'Dangerfile' | :engineering_productivity
'danger/commit_messages/Dangerfile' | :engineering_productivity
'ee/danger/commit_messages/Dangerfile' | :engineering_productivity
'danger/commit_messages/' | :engineering_productivity
'ee/danger/commit_messages/' | :engineering_productivity
'.gitlab-ci.yml' | :engineering_productivity
'.gitlab/ci/cng.gitlab-ci.yml' | :engineering_productivity
'.gitlab/ci/ee-specific-checks.gitlab-ci.yml' | :engineering_productivity
'scripts/foo' | :engineering_productivity
'lib/gitlab/danger/foo' | :engineering_productivity
'ee/lib/gitlab/danger/foo' | :engineering_productivity
'.overcommit.yml.example' | :engineering_productivity
'.editorconfig' | :engineering_productivity
'tooling/overcommit/foo' | :engineering_productivity
'.codeclimate.yml' | :engineering_productivity
'lib/gitlab/ci/templates/Security/SAST.gitlab-ci.yml' | :backend
'ee/FOO_VERSION' | :unknown
'db/schema.rb' | :database
'db/structure.sql' | :database
'db/migrate/foo' | :database
'db/post_migrate/foo' | :database
'ee/db/migrate/foo' | :database
'ee/db/post_migrate/foo' | :database
'ee/db/geo/migrate/foo' | :database
'ee/db/geo/post_migrate/foo' | :database
'app/models/project_authorization.rb' | :database
'app/services/users/refresh_authorized_projects_service.rb' | :database
'lib/gitlab/background_migration.rb' | :database
'lib/gitlab/background_migration/foo' | :database
'ee/lib/gitlab/background_migration/foo' | :database
'lib/gitlab/database.rb' | :database
'lib/gitlab/database/foo' | :database
'ee/lib/gitlab/database/foo' | :database
'lib/gitlab/github_import.rb' | :database
'lib/gitlab/github_import/foo' | :database
'lib/gitlab/sql/foo' | :database
'rubocop/cop/migration/foo' | :database
'db/fixtures/foo.rb' | :backend
'ee/db/fixtures/foo.rb' | :backend
'qa/foo' | :qa
'ee/qa/foo' | :qa
'changelogs/foo' | :none
'ee/changelogs/foo' | :none
'locale/gitlab.pot' | :none
'FOO' | :unknown
'foo' | :unknown
'foo/bar.rb' | :backend
'foo/bar.js' | :frontend
'foo/bar.txt' | :none
'foo/bar.md' | :none
describe '#categories_for_file' do
where(:path, :expected_categories) do
'doc/foo' | [:none]
'CONTRIBUTING.md' | [:none]
'LICENSE' | [:none]
'MAINTENANCE.md' | [:none]
'PHILOSOPHY.md' | [:none]
'PROCESS.md' | [:none]
'README.md' | [:none]
'ee/doc/foo' | [:unknown]
'ee/README' | [:unknown]
'app/assets/foo' | [:frontend]
'app/views/foo' | [:frontend]
'public/foo' | [:frontend]
'scripts/frontend/foo' | [:frontend]
'spec/javascripts/foo' | [:frontend]
'spec/frontend/bar' | [:frontend]
'vendor/assets/foo' | [:frontend]
'babel.config.js' | [:frontend]
'jest.config.js' | [:frontend]
'package.json' | [:frontend]
'yarn.lock' | [:frontend]
'config/foo.js' | [:frontend]
'config/deep/foo.js' | [:frontend]
'ee/app/assets/foo' | [:frontend]
'ee/app/views/foo' | [:frontend]
'ee/spec/javascripts/foo' | [:frontend]
'ee/spec/frontend/bar' | [:frontend]
'.gitlab/ci/frontend.gitlab-ci.yml' | %i[frontend engineering_productivity]
'app/models/foo' | [:backend]
'bin/foo' | [:backend]
'config/foo' | [:backend]
'lib/foo' | [:backend]
'rubocop/foo' | [:backend]
'spec/foo' | [:backend]
'spec/foo/bar' | [:backend]
'ee/app/foo' | [:backend]
'ee/bin/foo' | [:backend]
'ee/spec/foo' | [:backend]
'ee/spec/foo/bar' | [:backend]
'generator_templates/foo' | [:backend]
'vendor/languages.yml' | [:backend]
'vendor/licenses.csv' | [:backend]
'file_hooks/examples/' | [:backend]
'Gemfile' | [:backend]
'Gemfile.lock' | [:backend]
'Rakefile' | [:backend]
'FOO_VERSION' | [:backend]
'Dangerfile' | [:engineering_productivity]
'danger/commit_messages/Dangerfile' | [:engineering_productivity]
'ee/danger/commit_messages/Dangerfile' | [:engineering_productivity]
'danger/commit_messages/' | [:engineering_productivity]
'ee/danger/commit_messages/' | [:engineering_productivity]
'.gitlab-ci.yml' | [:engineering_productivity]
'.gitlab/ci/cng.gitlab-ci.yml' | [:engineering_productivity]
'.gitlab/ci/ee-specific-checks.gitlab-ci.yml' | [:engineering_productivity]
'scripts/foo' | [:engineering_productivity]
'lib/gitlab/danger/foo' | [:engineering_productivity]
'ee/lib/gitlab/danger/foo' | [:engineering_productivity]
'.overcommit.yml.example' | [:engineering_productivity]
'.editorconfig' | [:engineering_productivity]
'tooling/overcommit/foo' | [:engineering_productivity]
'.codeclimate.yml' | [:engineering_productivity]
'lib/gitlab/ci/templates/Security/SAST.gitlab-ci.yml' | [:backend]
'ee/FOO_VERSION' | [:unknown]
'db/schema.rb' | [:database]
'db/structure.sql' | [:database]
'db/migrate/foo' | [:database]
'db/post_migrate/foo' | [:database]
'ee/db/migrate/foo' | [:database]
'ee/db/post_migrate/foo' | [:database]
'ee/db/geo/migrate/foo' | [:database]
'ee/db/geo/post_migrate/foo' | [:database]
'app/models/project_authorization.rb' | [:database]
'app/services/users/refresh_authorized_projects_service.rb' | [:database]
'lib/gitlab/background_migration.rb' | [:database]
'lib/gitlab/background_migration/foo' | [:database]
'ee/lib/gitlab/background_migration/foo' | [:database]
'lib/gitlab/database.rb' | [:database]
'lib/gitlab/database/foo' | [:database]
'ee/lib/gitlab/database/foo' | [:database]
'lib/gitlab/github_import.rb' | [:database]
'lib/gitlab/github_import/foo' | [:database]
'lib/gitlab/sql/foo' | [:database]
'rubocop/cop/migration/foo' | [:database]
'db/fixtures/foo.rb' | [:backend]
'ee/db/fixtures/foo.rb' | [:backend]
'qa/foo' | [:qa]
'ee/qa/foo' | [:qa]
'changelogs/foo' | [:none]
'ee/changelogs/foo' | [:none]
'locale/gitlab.pot' | [:none]
'FOO' | [:unknown]
'foo' | [:unknown]
'foo/bar.rb' | [:backend]
'foo/bar.js' | [:frontend]
'foo/bar.txt' | [:none]
'foo/bar.md' | [:none]
end
with_them do
subject { helper.category_for_file(path) }
subject { helper.categories_for_file(path) }
it { is_expected.to eq(expected_category) }
it { is_expected.to eq(expected_categories) }
end
end
......@@ -296,6 +298,7 @@ RSpec.describe Gitlab::Danger::Helper do
:frontend | '~frontend'
:none | ''
:qa | '~QA'
:engineering_productivity | '~"Engineering Productivity" for CI, Danger'
end
with_them do
......
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