Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
99ba0bc7
Commit
99ba0bc7
authored
Jun 30, 2020
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow files to belong to multiple categories in the roulette
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
91895122
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
129 additions
and
123 deletions
+129
-123
lib/gitlab/danger/helper.rb
lib/gitlab/danger/helper.rb
+11
-8
spec/lib/gitlab/danger/helper_spec.rb
spec/lib/gitlab/danger/helper_spec.rb
+118
-115
No files found.
lib/gitlab/danger/helper.rb
View file @
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 categor
y a file is in, e.g., `:frontend` or `:backend`
# @return
[Symbol]
def
categor
y
_for_file
(
file
)
_
,
categor
y
=
CATEGORIES
.
find
{
|
regexp
,
_
|
regexp
.
match?
(
file
)
}
# Determines the categor
ies a file is in, e.g., `[:frontend]`, `[:backend]`, or `%i[frontend engineering_productivity]`.
# @return
Array<Symbol>
def
categor
ies
_for_file
(
file
)
_
,
categor
ies
=
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
,
...
...
spec/lib/gitlab/danger/helper_spec.rb
View file @
99ba0bc7
...
...
@@ -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
.
categor
y
_for_file
(
path
)
}
subject
{
helper
.
categor
ies
_for_file
(
path
)
}
it
{
is_expected
.
to
eq
(
expected_categor
y
)
}
it
{
is_expected
.
to
eq
(
expected_categor
ies
)
}
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment