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
a0d9ea8a
Commit
a0d9ea8a
authored
Oct 03, 2019
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sure project insights stick on its own
parent
ca664282
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
21 deletions
+55
-21
changelogs/unreleased/33337-fix-insights-only-projects-for-project.yml
...released/33337-fix-insights-only-projects-for-project.yml
+5
-0
ee/lib/gitlab/insights/finders/issuable_finder.rb
ee/lib/gitlab/insights/finders/issuable_finder.rb
+16
-13
ee/spec/lib/gitlab/insights/finders/issuable_finder_spec.rb
ee/spec/lib/gitlab/insights/finders/issuable_finder_spec.rb
+34
-8
No files found.
changelogs/unreleased/33337-fix-insights-only-projects-for-project.yml
0 → 100644
View file @
a0d9ea8a
---
title
:
Make sure project insights stick on its own
merge_request
:
18082
author
:
type
:
fixed
ee/lib/gitlab/insights/finders/issuable_finder.rb
View file @
a0d9ea8a
...
...
@@ -31,6 +31,8 @@ module Gitlab
# Returns an Active Record relation of issuables.
def
find
return
unless
entity_args
relation
=
finder
.
new
(
current_user
,
finder_args
)
.
execute
...
...
@@ -69,23 +71,24 @@ module Gitlab
state:
query
[
:issuable_state
]
||
'opened'
,
label_name:
query
[
:filter_labels
],
sort:
'created_asc'
,
created_after:
created_after_argument
,
projects:
finder_projects
}.
merge
(
entity_arg
)
created_after:
created_after_argument
}.
merge
(
entity_args
)
end
def
entity_arg
case
entity
when
::
Project
if
finder_projects
{}
# We just rely on projects argument
def
entity_args
strong_memoize
(
:entity_args
)
do
case
entity
when
::
Project
if
finder_projects
{
project_id:
entity
.
id
}
if
finder_projects
.
exists?
(
entity
.
id
)
# rubocop: disable CodeReuse/ActiveRecord
else
{
project_id:
entity
.
id
}
end
when
::
Namespace
{
group_id:
entity
.
id
,
projects:
finder_projects
}
else
{
project_id:
entity
.
id
}
raise
InvalidEntityError
,
"Entity class `
#{
entity
.
class
}
` is not supported. Supported classes are Project and Namespace!"
end
when
::
Namespace
{
group_id:
entity
.
id
}
else
raise
InvalidEntityError
,
"Entity class `
#{
entity
.
class
}
` is not supported. Supported classes are Project and Namespace!"
end
end
...
...
ee/spec/lib/gitlab/insights/finders/issuable_finder_spec.rb
View file @
a0d9ea8a
...
...
@@ -170,9 +170,14 @@ RSpec.describe Gitlab::Insights::Finders::IssuableFinder do
context
'when `projects.only` are specified by two ids'
do
let
(
:projects
)
{
{
only:
[
project
.
id
,
other_project
.
id
]
}
}
it
'returns issuables for all projects'
do
expect
(
subject
.
to_a
)
.
to
eq
([
issuable0
,
issuable1
,
issuable2
,
issuable3
,
issuable4
])
it
'returns issuables for all valid projects'
do
expected
=
[
issuable0
,
issuable1
,
issuable2
,
issuable3
,
issuable4
]
if
entity
.
id
==
project
.
id
expected
.
shift
(
2
)
# Those are from other_project
end
expect
(
subject
.
to_a
).
to
eq
(
expected
)
end
end
...
...
@@ -185,10 +190,10 @@ RSpec.describe Gitlab::Insights::Finders::IssuableFinder do
end
context
'when `projects.only` are specified by bad id and good id'
do
let
(
:projects
)
{
{
only:
[
0
,
other_
project
.
id
]
}
}
let
(
:projects
)
{
{
only:
[
0
,
project
.
id
]
}
}
it
'returns issuables for good project'
do
expect
(
subject
.
to_a
).
to
eq
([
issuable
0
,
issuable1
])
expect
(
subject
.
to_a
).
to
eq
([
issuable
2
,
issuable3
,
issuable4
])
end
end
...
...
@@ -203,9 +208,22 @@ RSpec.describe Gitlab::Insights::Finders::IssuableFinder do
context
'when `projects.only` are specified by project full path and id'
do
let
(
:projects
)
{
{
only:
[
project
.
id
,
other_project
.
full_path
]
}
}
it
'returns issuables for all projects'
do
expect
(
subject
.
to_a
)
.
to
eq
([
issuable0
,
issuable1
,
issuable2
,
issuable3
,
issuable4
])
it
'returns issuables for all valid projects'
do
expected
=
[
issuable0
,
issuable1
,
issuable2
,
issuable3
,
issuable4
]
if
entity
.
id
==
project
.
id
expected
.
shift
(
2
)
# Those are from other_project
end
expect
(
subject
.
to_a
).
to
eq
(
expected
)
end
end
context
'when `projects.only` are specified by duplicated projects'
do
let
(
:projects
)
{
{
only:
[
project
.
id
,
project
.
full_path
]
}
}
it
'returns issuables for that project without duplicated issuables'
do
expect
(
subject
.
to_a
).
to
eq
([
issuable2
,
issuable3
,
issuable4
])
end
end
...
...
@@ -216,6 +234,14 @@ RSpec.describe Gitlab::Insights::Finders::IssuableFinder do
expect
(
subject
.
to_a
).
to
be_empty
end
end
context
'when `projects.only` are specified by unrelated project'
do
let
(
:projects
)
{
{
only:
[
create
(
:project
,
:public
).
id
]
}
}
it
'returns nothing'
do
expect
(
subject
.
to_a
).
to
be_empty
end
end
end
end
...
...
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