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
67fa45e7
Commit
67fa45e7
authored
Feb 27, 2020
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow issues/merge_requests as an issuable_type in Insights config
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
abda9897
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
8 deletions
+40
-8
changelogs/unreleased/13005-allow-to-use-issue-issues-and-merge_request-merge_requests-for-issu.yml
...ssue-issues-and-merge_request-merge_requests-for-issu.yml
+5
-0
ee/lib/gitlab/insights/finders/issuable_finder.rb
ee/lib/gitlab/insights/finders/issuable_finder.rb
+4
-2
ee/spec/lib/gitlab/insights/finders/issuable_finder_spec.rb
ee/spec/lib/gitlab/insights/finders/issuable_finder_spec.rb
+31
-6
No files found.
changelogs/unreleased/13005-allow-to-use-issue-issues-and-merge_request-merge_requests-for-issu.yml
0 → 100644
View file @
67fa45e7
---
title
:
Allow issues/merge_requests as an issuable_type in Insights configuration
merge_request
:
26061
author
:
type
:
added
ee/lib/gitlab/insights/finders/issuable_finder.rb
View file @
67fa45e7
...
@@ -29,6 +29,10 @@ module Gitlab
...
@@ -29,6 +29,10 @@ module Gitlab
@projects
=
projects
@projects
=
projects
end
end
def
issuable_type
@issuable_type
||=
query
[
:issuable_type
]
&
.
to_s
&
.
singularize
&
.
to_sym
end
# Returns an Active Record relation of issuables.
# Returns an Active Record relation of issuables.
def
find
def
find
return
unless
entity_args
return
unless
entity_args
...
@@ -59,8 +63,6 @@ module Gitlab
...
@@ -59,8 +63,6 @@ module Gitlab
attr_reader
:entity
,
:current_user
,
:query
,
:projects
attr_reader
:entity
,
:current_user
,
:query
,
:projects
def
finder
def
finder
issuable_type
=
query
[
:issuable_type
]
&
.
to_sym
FINDERS
[
issuable_type
]
||
FINDERS
[
issuable_type
]
||
raise
(
InvalidIssuableTypeError
,
"Invalid `:issuable_type` option: `
#{
query
[
:issuable_type
]
}
`. Allowed values are
#{
FINDERS
.
keys
}
!"
)
raise
(
InvalidIssuableTypeError
,
"Invalid `:issuable_type` option: `
#{
query
[
:issuable_type
]
}
`. Allowed values are
#{
FINDERS
.
keys
}
!"
)
end
end
...
...
ee/spec/lib/gitlab/insights/finders/issuable_finder_spec.rb
View file @
67fa45e7
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
require
'spec_helper'
require
'spec_helper'
RSpec
.
describe
Gitlab
::
Insights
::
Finders
::
IssuableFinder
do
RSpec
.
describe
Gitlab
::
Insights
::
Finders
::
IssuableFinder
do
using
RSpec
::
Parameterized
::
TableSyntax
around
do
|
example
|
around
do
|
example
|
Timecop
.
freeze
(
Time
.
utc
(
2019
,
3
,
5
))
{
example
.
run
}
Timecop
.
freeze
(
Time
.
utc
(
2019
,
3
,
5
))
{
example
.
run
}
end
end
...
@@ -14,11 +16,34 @@ RSpec.describe Gitlab::Insights::Finders::IssuableFinder do
...
@@ -14,11 +16,34 @@ RSpec.describe Gitlab::Insights::Finders::IssuableFinder do
}
}
end
end
describe
'#issuable_type'
do
subject
{
described_class
.
new
(
build
(
:project
),
nil
,
query:
{
issuable_type:
issuable_type_in_query
}).
issuable_type
}
where
(
:issuable_type_in_query
,
:expected_issuable_type
)
do
'issue'
|
:issue
'issues'
|
:issue
'merge_request'
|
:merge_request
'merge_requests'
|
:merge_request
end
with_them
do
it
{
is_expected
.
to
eq
(
expected_issuable_type
)
}
end
end
describe
'#find'
do
describe
'#find'
do
def
find
(
entity
,
query
:,
projects:
{})
def
find
(
entity
,
query
:,
projects:
{})
described_class
.
new
(
entity
,
nil
,
query:
query
,
projects:
projects
).
find
described_class
.
new
(
entity
,
nil
,
query:
query
,
projects:
projects
).
find
end
end
it
'calls issuable_type'
do
finder
=
described_class
.
new
(
build
(
:project
),
nil
,
query:
{
issuable_type:
'issue'
})
expect
(
finder
).
to
receive
(
:issuable_type
).
and_call_original
finder
.
find
end
it
'raises an error for an invalid :issuable_type option'
do
it
'raises an error for an invalid :issuable_type option'
do
expect
do
expect
do
find
(
build
(
:project
),
query:
{
issuable_type:
'foo'
})
find
(
build
(
:project
),
query:
{
issuable_type:
'foo'
})
...
@@ -54,11 +79,11 @@ RSpec.describe Gitlab::Insights::Finders::IssuableFinder do
...
@@ -54,11 +79,11 @@ RSpec.describe Gitlab::Insights::Finders::IssuableFinder do
let
(
:label_create
)
{
create
(
label_type
,
label_entity_association_key
=>
entity
,
name:
'Create'
)
}
let
(
:label_create
)
{
create
(
label_type
,
label_entity_association_key
=>
entity
,
name:
'Create'
)
}
let
(
:label_quality
)
{
create
(
label_type
,
label_entity_association_key
=>
entity
,
name:
'Quality'
)
}
let
(
:label_quality
)
{
create
(
label_type
,
label_entity_association_key
=>
entity
,
name:
'Quality'
)
}
let
(
:extra_issuable_attrs
)
{
[{},
{},
{},
{},
{},
{}]
}
let
(
:extra_issuable_attrs
)
{
[{},
{},
{},
{},
{},
{}]
}
let!
(
:issuable0
)
{
create
(
:"labeled_
#{
issuable_type
}
"
,
:opened
,
created_at:
Time
.
utc
(
2018
,
1
,
1
),
project_association_key
=>
project
,
**
extra_issuable_attrs
[
0
])
}
let!
(
:issuable0
)
{
create
(
:"labeled_
#{
issuable_type
.
singularize
}
"
,
:opened
,
created_at:
Time
.
utc
(
2018
,
1
,
1
),
project_association_key
=>
project
,
**
extra_issuable_attrs
[
0
])
}
let!
(
:issuable1
)
{
create
(
:"labeled_
#{
issuable_type
}
"
,
:opened
,
created_at:
Time
.
utc
(
2018
,
2
,
1
),
labels:
[
label_bug
,
label_manage
],
project_association_key
=>
project
,
**
extra_issuable_attrs
[
1
])
}
let!
(
:issuable1
)
{
create
(
:"labeled_
#{
issuable_type
.
singularize
}
"
,
:opened
,
created_at:
Time
.
utc
(
2018
,
2
,
1
),
labels:
[
label_bug
,
label_manage
],
project_association_key
=>
project
,
**
extra_issuable_attrs
[
1
])
}
let!
(
:issuable2
)
{
create
(
:"labeled_
#{
issuable_type
}
"
,
:opened
,
created_at:
Time
.
utc
(
2019
,
2
,
6
),
labels:
[
label_bug
,
label_plan
],
project_association_key
=>
project
,
**
extra_issuable_attrs
[
2
])
}
let!
(
:issuable2
)
{
create
(
:"labeled_
#{
issuable_type
.
singularize
}
"
,
:opened
,
created_at:
Time
.
utc
(
2019
,
2
,
6
),
labels:
[
label_bug
,
label_plan
],
project_association_key
=>
project
,
**
extra_issuable_attrs
[
2
])
}
let!
(
:issuable3
)
{
create
(
:"labeled_
#{
issuable_type
}
"
,
:opened
,
created_at:
Time
.
utc
(
2019
,
2
,
20
),
labels:
[
label_bug
,
label_create
],
project_association_key
=>
project
,
**
extra_issuable_attrs
[
3
])
}
let!
(
:issuable3
)
{
create
(
:"labeled_
#{
issuable_type
.
singularize
}
"
,
:opened
,
created_at:
Time
.
utc
(
2019
,
2
,
20
),
labels:
[
label_bug
,
label_create
],
project_association_key
=>
project
,
**
extra_issuable_attrs
[
3
])
}
let!
(
:issuable4
)
{
create
(
:"labeled_
#{
issuable_type
}
"
,
:opened
,
created_at:
Time
.
utc
(
2019
,
3
,
5
),
labels:
[
label_bug
,
label_quality
],
project_association_key
=>
project
,
**
extra_issuable_attrs
[
4
])
}
let!
(
:issuable4
)
{
create
(
:"labeled_
#{
issuable_type
.
singularize
}
"
,
:opened
,
created_at:
Time
.
utc
(
2019
,
3
,
5
),
labels:
[
label_bug
,
label_quality
],
project_association_key
=>
project
,
**
extra_issuable_attrs
[
4
])
}
let
(
:query
)
do
let
(
:query
)
do
base_query
.
merge
(
base_query
.
merge
(
issuable_type:
issuable_type
,
issuable_type:
issuable_type
,
...
@@ -71,7 +96,7 @@ RSpec.describe Gitlab::Insights::Finders::IssuableFinder do
...
@@ -71,7 +96,7 @@ RSpec.describe Gitlab::Insights::Finders::IssuableFinder do
it
'avoids N + 1 queries'
do
it
'avoids N + 1 queries'
do
control_queries
=
ActiveRecord
::
QueryRecorder
.
new
{
subject
.
map
{
|
issuable
|
issuable
.
labels
.
map
(
&
:title
)
}
}
control_queries
=
ActiveRecord
::
QueryRecorder
.
new
{
subject
.
map
{
|
issuable
|
issuable
.
labels
.
map
(
&
:title
)
}
}
create
(
:"labeled_
#{
issuable_type
}
"
,
:opened
,
created_at:
Time
.
utc
(
2019
,
3
,
5
),
labels:
[
label_bug
],
project_association_key
=>
project
,
**
extra_issuable_attrs
[
5
])
create
(
:"labeled_
#{
issuable_type
.
singularize
}
"
,
:opened
,
created_at:
Time
.
utc
(
2019
,
3
,
5
),
labels:
[
label_bug
],
project_association_key
=>
project
,
**
extra_issuable_attrs
[
5
])
expect
do
expect
do
find
(
entity
,
query:
query
).
map
{
|
issuable
|
issuable
.
labels
.
map
(
&
:title
)
}
find
(
entity
,
query:
query
).
map
{
|
issuable
|
issuable
.
labels
.
map
(
&
:title
)
}
...
...
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