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
a6305b26
Commit
a6305b26
authored
Aug 09, 2021
by
Luis Mejia
Committed by
Alper Akgun
Aug 09, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create rake task to update metrics status to data_available
parent
64f31cb5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
104 additions
and
0 deletions
+104
-0
lib/tasks/gitlab/product_intelligence.rake
lib/tasks/gitlab/product_intelligence.rake
+24
-0
spec/tasks/gitlab/product_intelligence_rake_spec.rb
spec/tasks/gitlab/product_intelligence_rake_spec.rb
+80
-0
No files found.
lib/tasks/gitlab/product_intelligence.rake
0 → 100644
View file @
a6305b26
# frozen_string_literal: true
namespace
:gitlab
do
namespace
:product_intelligence
do
# @example
# bundle exec rake gitlab:product_intelligence:activate_metrics MILESTONE=14.0
desc
'GitLab | Product Intelligence | Update milestone metrics status to data_available'
task
activate_metrics: :environment
do
milestone
=
ENV
[
'MILESTONE'
]
raise
"Please supply the MILESTONE env var"
.
color
(
:red
)
unless
milestone
.
present?
Gitlab
::
Usage
::
MetricDefinition
.
definitions
.
values
.
each
do
|
metric
|
next
if
metric
.
attributes
[
:milestone
]
!=
milestone
||
metric
.
attributes
[
:status
]
!=
'implemented'
metric
.
attributes
[
:status
]
=
'data_available'
path
=
metric
.
path
File
.
open
(
path
,
"w"
)
{
|
file
|
file
<<
metric
.
to_h
.
deep_stringify_keys
.
to_yaml
}
end
puts
"Task completed successfully"
end
end
end
spec/tasks/gitlab/product_intelligence_rake_spec.rb
0 → 100644
View file @
a6305b26
# frozen_string_literal: true
require
'rake_helper'
RSpec
.
describe
'gitlab:product_intelligence:activate_metrics'
,
:silence_stdout
do
def
fake_metric
(
key_path
,
milestone:
'test_milestone'
,
status:
'implemented'
)
Gitlab
::
Usage
::
MetricDefinition
.
new
(
key_path
,
{
key_path:
key_path
,
milestone:
milestone
,
status:
status
})
end
before
do
Rake
.
application
.
rake_require
'tasks/gitlab/product_intelligence'
stub_warn_user_is_not_gitlab
end
describe
'activate_metrics'
do
it
'fails if the MILESTONE env var is not set'
do
stub_env
(
'MILESTONE'
=>
nil
)
expect
{
run_rake_task
(
'gitlab:product_intelligence:activate_metrics'
)
}.
to
raise_error
(
RuntimeError
,
'Please supply the MILESTONE env var'
)
end
context
'with MILESTONE env var'
do
subject
do
updated_metrics
=
[]
file
=
double
(
'file'
)
allow
(
file
).
to
receive
(
:<<
)
{
|
contents
|
updated_metrics
<<
YAML
.
safe_load
(
contents
)
}
allow
(
File
).
to
receive
(
:open
).
and_yield
(
file
)
stub_env
(
'MILESTONE'
=>
'test_milestone'
)
run_rake_task
(
'gitlab:product_intelligence:activate_metrics'
)
updated_metrics
end
let
(
:metric_definitions
)
do
{
matching_metric:
fake_metric
(
'matching_metric'
),
matching_metric2:
fake_metric
(
'matching_metric2'
),
other_status_metric:
fake_metric
(
'other_status_metric'
,
status:
'deprecated'
),
other_milestone_metric:
fake_metric
(
'other_milestone_metric'
,
milestone:
'other_milestone'
)
}
end
before
do
allow
(
Gitlab
::
Usage
::
MetricDefinition
).
to
receive
(
:definitions
).
and_return
(
metric_definitions
)
end
context
'with metric matching status and milestone'
do
it
'updates matching_metric yaml file'
do
expect
(
subject
).
to
eq
([
{
'key_path'
=>
'matching_metric'
,
'milestone'
=>
'test_milestone'
,
'status'
=>
'data_available'
},
{
'key_path'
=>
'matching_metric2'
,
'milestone'
=>
'test_milestone'
,
'status'
=>
'data_available'
}
])
end
end
context
'without metrics definitions'
do
let
(
:metric_definitions
)
{
{}
}
it
'runs successfully with no updates'
do
expect
(
subject
).
to
eq
([])
end
end
context
'without matching metrics'
do
let
(
:metric_definitions
)
do
{
other_status_metric:
fake_metric
(
'other_status_metric'
,
status:
'deprecated'
),
other_milestone_metric:
fake_metric
(
'other_milestone_metric'
,
milestone:
'other_milestone'
)
}
end
it
'runs successfully with no updates'
do
expect
(
subject
).
to
eq
([])
end
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