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
3a4a45bc
Commit
3a4a45bc
authored
Jul 16, 2020
by
Alina Mihaila
Committed by
Rémy Coutable
Jul 16, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve tests and helper
- Add more tests - Use telemetry_labels in danger file - Revert test change
parent
8b414961
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
3 deletions
+54
-3
ee/lib/ee/gitlab/usage_data.rb
ee/lib/ee/gitlab/usage_data.rb
+4
-1
lib/gitlab/danger/helper.rb
lib/gitlab/danger/helper.rb
+25
-2
spec/lib/gitlab/danger/helper_spec.rb
spec/lib/gitlab/danger/helper_spec.rb
+25
-0
No files found.
ee/lib/ee/gitlab/usage_data.rb
View file @
3a4a45bc
...
@@ -227,7 +227,10 @@ module EE
...
@@ -227,7 +227,10 @@ module EE
:creator_id
,
:creator_id
,
start:
user_minimum_id
,
start:
user_minimum_id
,
finish:
user_maximum_id
),
finish:
user_maximum_id
),
protected_branches:
distinct_count
(
::
Project
.
with_protected_branches
.
where
(
time_period
),
:creator_id
,
start:
user_minimum_id
,
finish:
user_maximum_id
),
protected_branches:
distinct_count
(
::
Project
.
with_protected_branches
.
where
(
time_period
),
:creator_id
,
start:
user_minimum_id
,
finish:
user_maximum_id
),
suggestions:
distinct_count
(
::
Note
.
with_suggestions
.
where
(
time_period
),
suggestions:
distinct_count
(
::
Note
.
with_suggestions
.
where
(
time_period
),
:author_id
,
:author_id
,
start:
user_minimum_id
,
start:
user_minimum_id
,
...
...
lib/gitlab/danger/helper.rb
View file @
3a4a45bc
...
@@ -34,6 +34,18 @@ module Gitlab
...
@@ -34,6 +34,18 @@ module Gitlab
.
sort
.
sort
end
end
# Returns a string containing changed lines as git diff
#
# Considering changing a line in lib/gitlab/usage_data.rb it will return:
#
# [ "--- a/lib/gitlab/usage_data.rb",
# "+++ b/lib/gitlab/usage_data.rb",
# "+ # Test change",
# "- # Old change" ]
def
changed_lines
(
changed_file
)
git
.
diff_for_file
(
changed_file
).
patch
.
split
(
"
\n
"
).
select
{
|
line
|
%r{^[+-]}
.
match?
(
line
)
}
end
def
all_ee_changes
def
all_ee_changes
all_changed_files
.
grep
(
%r{
\A
ee/}
)
all_changed_files
.
grep
(
%r{
\A
ee/}
)
end
end
...
@@ -77,10 +89,19 @@ module Gitlab
...
@@ -77,10 +89,19 @@ module Gitlab
end
end
end
end
# Determines the categories a file is in, e.g., `[:frontend]`, `[:backend]`, or `%i[frontend engineering_productivity]`.
# Determines the categories a file is in, e.g., `[:frontend]`, `[:backend]`, or `%i[frontend engineering_productivity]`
# using filename regex and specific change regex if given.
#
# @return Array<Symbol>
# @return Array<Symbol>
def
categories_for_file
(
file
)
def
categories_for_file
(
file
)
_
,
categories
=
CATEGORIES
.
find
{
|
regexp
,
_
|
regexp
.
match?
(
file
)
}
_
,
categories
=
CATEGORIES
.
find
do
|
key
,
_
|
filename_regex
,
changes_regex
=
Array
(
key
)
found
=
filename_regex
.
match?
(
file
)
found
&&=
changed_lines
(
file
).
any?
{
|
changed_line
|
changes_regex
.
match?
(
changed_line
)
}
if
changes_regex
found
end
Array
(
categories
||
:unknown
)
Array
(
categories
||
:unknown
)
end
end
...
@@ -102,6 +123,8 @@ module Gitlab
...
@@ -102,6 +123,8 @@ module Gitlab
}.
freeze
}.
freeze
# First-match win, so be sure to put more specific regex at the top...
# First-match win, so be sure to put more specific regex at the top...
CATEGORIES
=
{
CATEGORIES
=
{
[
%r{usage_data}
,
%r{^(
\+
|-).*(count|distinct_count)
\(
.*
\)
(.*)$}
]
=>
[
:database
,
:backend
],
%r{
\A
doc/.*(
\.
(md|png|gif|jpg))
\z
}
=>
:docs
,
%r{
\A
doc/.*(
\.
(md|png|gif|jpg))
\z
}
=>
:docs
,
%r{
\A
(CONTRIBUTING|LICENSE|MAINTENANCE|PHILOSOPHY|PROCESS|README)(
\.
md)?
\z
}
=>
:docs
,
%r{
\A
(CONTRIBUTING|LICENSE|MAINTENANCE|PHILOSOPHY|PROCESS|README)(
\.
md)?
\z
}
=>
:docs
,
...
...
spec/lib/gitlab/danger/helper_spec.rb
View file @
3a4a45bc
...
@@ -166,7 +166,12 @@ RSpec.describe Gitlab::Danger::Helper do
...
@@ -166,7 +166,12 @@ RSpec.describe Gitlab::Danger::Helper do
end
end
describe
'#categories_for_file'
do
describe
'#categories_for_file'
do
before
do
allow
(
fake_git
).
to
receive
(
:diff_for_file
).
with
(
'usage_data.rb'
)
{
double
(
:diff
,
patch:
"+ count(User.active)"
)
}
end
where
(
:path
,
:expected_categories
)
do
where
(
:path
,
:expected_categories
)
do
'usage_data.rb'
|
[
:database
,
:backend
]
'doc/foo.md'
|
[
:docs
]
'doc/foo.md'
|
[
:docs
]
'CONTRIBUTING.md'
|
[
:docs
]
'CONTRIBUTING.md'
|
[
:docs
]
'LICENSE'
|
[
:docs
]
'LICENSE'
|
[
:docs
]
...
@@ -287,6 +292,26 @@ RSpec.describe Gitlab::Danger::Helper do
...
@@ -287,6 +292,26 @@ RSpec.describe Gitlab::Danger::Helper do
it
{
is_expected
.
to
eq
(
expected_categories
)
}
it
{
is_expected
.
to
eq
(
expected_categories
)
}
end
end
context
'having specific changes'
do
it
'has database and backend categories'
do
allow
(
fake_git
).
to
receive
(
:diff_for_file
).
with
(
'usage_data.rb'
)
{
double
(
:diff
,
patch:
"+ count(User.active)"
)
}
expect
(
helper
.
categories_for_file
(
'usage_data.rb'
)).
to
eq
([
:database
,
:backend
])
end
it
'has backend category'
do
allow
(
fake_git
).
to
receive
(
:diff_for_file
).
with
(
'usage_data.rb'
)
{
double
(
:diff
,
patch:
"+ alt_usage_data(User.active)"
)
}
expect
(
helper
.
categories_for_file
(
'usage_data.rb'
)).
to
eq
([
:backend
])
end
it
'has backend category for changes outside usage_data files'
do
allow
(
fake_git
).
to
receive
(
:diff_for_file
).
with
(
'user.rb'
)
{
double
(
:diff
,
patch:
"+ count(User.active)"
)
}
expect
(
helper
.
categories_for_file
(
'user.rb'
)).
to
eq
([
:backend
])
end
end
end
end
describe
'#label_for_category'
do
describe
'#label_for_category'
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