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
0d136be6
Commit
0d136be6
authored
Mar 19, 2019
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce a new InsightsFeature#insights_config method
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
b89d7c4d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
91 additions
and
0 deletions
+91
-0
ee/app/models/concerns/insights_feature.rb
ee/app/models/concerns/insights_feature.rb
+15
-0
ee/spec/models/group_spec.rb
ee/spec/models/group_spec.rb
+44
-0
ee/spec/models/project_spec.rb
ee/spec/models/project_spec.rb
+32
-0
No files found.
ee/app/models/concerns/insights_feature.rb
View file @
0d136be6
...
...
@@ -12,4 +12,19 @@ module InsightsFeature
def
insights_available?
::
Feature
.
enabled?
(
:insights
,
self
)
&&
feature_available?
(
:insights
)
end
def
insights_config
return
self
.
insight
.
project
.
insights_config
if
self
.
respond_to?
(
:insight
)
&&
self
.
insight
return
unless
self
.
respond_to?
(
:repository
)
return
if
self
.
repository
.
empty?
insights_config_yml
=
self
.
repository
.
insights_config_for
(
self
.
repository
.
root_ref
)
return
unless
insights_config_yml
strong_memoize
(
:insights_config
)
do
::
Gitlab
::
Config
::
Loader
::
Yaml
.
new
(
insights_config_yml
).
load!
end
rescue
Gitlab
::
Config
::
Loader
::
FormatError
nil
end
end
ee/spec/models/group_spec.rb
View file @
0d136be6
...
...
@@ -400,4 +400,48 @@ describe Group do
let
(
:entity
)
{
group
}
end
end
describe
"#insights_config"
do
context
'when group has no Insights project configured'
do
it
'returns nil'
do
expect
(
group
.
insights_config
).
to
be_nil
end
end
context
'when group has an Insights project configured without a config file'
do
before
do
project
=
create
(
:project
,
group:
group
)
group
.
create_insight!
(
project:
project
)
end
it
'returns nil'
do
expect
(
group
.
insights_config
).
to
be_nil
end
end
context
'when group has an Insights project configured'
do
before
do
project
=
create
(
:project
,
:custom_repo
,
group:
group
,
files:
{
::
Gitlab
::
Insights
::
CONFIG_FILE_PATH
=>
insights_file_content
})
group
.
create_insight!
(
project:
project
)
end
context
'with a valid config file'
do
let
(
:insights_file_content
)
{
'key: monthlyBugsCreated'
}
it
'returns the insights config data'
do
insights_config
=
group
.
insights_config
expect
(
insights_config
).
to
eq
(
key:
'monthlyBugsCreated'
)
end
end
context
'with an invalid config file'
do
let
(
:insights_file_content
)
{
': foo bar'
}
it
'returns the insights config data'
do
expect
(
group
.
insights_config
).
to
be_nil
end
end
end
end
end
ee/spec/models/project_spec.rb
View file @
0d136be6
...
...
@@ -1735,6 +1735,38 @@ describe Project do
end
end
describe
"#insights_config"
do
context
'when project has no Insights config file'
do
it
'returns nil'
do
expect
(
create
(
:project
).
insights_config
).
to
be_nil
end
end
context
'when project has an Insights config file'
do
let
(
:project
)
do
create
(
:project
,
:custom_repo
,
files:
{
::
Gitlab
::
Insights
::
CONFIG_FILE_PATH
=>
insights_file_content
})
end
context
'with a valid config file'
do
let
(
:insights_file_content
)
{
'key: monthlyBugsCreated'
}
it
'returns the insights config data'
do
insights_config
=
project
.
insights_config
expect
(
insights_config
).
to
eq
(
key:
'monthlyBugsCreated'
)
end
end
context
'with an invalid config file'
do
let
(
:insights_file_content
)
{
': foo bar'
}
it
'returns the insights config data'
do
expect
(
project
.
insights_config
).
to
be_nil
end
end
end
end
# Despite stubbing the current node as the primary or secondary, the
# behaviour for EE::Project#lfs_http_url_to_repo() is to call
# Project#lfs_http_url_to_repo() which does not have a Geo context.
...
...
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