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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
9cff3f8f
Commit
9cff3f8f
authored
Sep 07, 2016
by
Timothy Andrew
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test the `test` cycle analytics phase.
parent
de483c68
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
92 additions
and
2 deletions
+92
-2
app/models/cycle_analytics/queries.rb
app/models/cycle_analytics/queries.rb
+2
-2
spec/models/cycle_analytics/test_spec.rb
spec/models/cycle_analytics/test_spec.rb
+90
-0
No files found.
app/models/cycle_analytics/queries.rb
View file @
9cff3f8f
...
...
@@ -54,7 +54,7 @@ class CycleAnalytics
tip
=
merge_request
.
commits
.
first
return
unless
tip
pipeline
=
Ci
::
Pipeline
.
find_by_sha
(
tip
.
sha
)
pipeline
=
Ci
::
Pipeline
.
success
.
find_by_sha
(
tip
.
sha
)
pipeline
.
started_at
if
pipeline
end
end
...
...
@@ -65,7 +65,7 @@ class CycleAnalytics
tip
=
merge_request
.
commits
.
first
return
unless
tip
pipeline
=
Ci
::
Pipeline
.
find_by_sha
(
tip
.
sha
)
pipeline
=
Ci
::
Pipeline
.
success
.
find_by_sha
(
tip
.
sha
)
pipeline
.
finished_at
if
pipeline
end
end
...
...
spec/models/cycle_analytics/test_spec.rb
0 → 100644
View file @
9cff3f8f
require
'spec_helper'
describe
'CycleAnalytics#test'
,
feature:
true
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:from_date
)
{
10
.
days
.
ago
}
let
(
:user
)
{
create
(
:user
,
:admin
)
}
subject
{
CycleAnalytics
.
new
(
project
,
from:
from_date
)
}
def
create_merge_request_closing_issue
(
issue
,
message:
nil
)
source_branch
=
random_git_name
project
.
repository
.
add_branch
(
user
,
source_branch
,
'master'
)
sha
=
project
.
repository
.
commit_file
(
user
,
random_git_name
,
"content"
,
"commit message"
,
source_branch
,
false
)
project
.
repository
.
commit
(
sha
)
opts
=
{
title:
'Awesome merge_request'
,
description:
message
||
"Fixes
#{
issue
.
to_reference
}
"
,
source_branch:
source_branch
,
target_branch:
'master'
}
MergeRequests
::
CreateService
.
new
(
project
,
user
,
opts
).
execute
end
generate_cycle_analytics_spec
(
phase: :test
,
data_fn:
lambda
do
|
context
|
issue
=
context
.
create
(
:issue
,
project:
context
.
project
)
merge_request
=
context
.
create_merge_request_closing_issue
(
issue
)
{
pipeline:
context
.
create
(
:ci_pipeline
,
ref:
"refs/heads/
#{
merge_request
.
source_branch
}
"
,
sha:
merge_request
.
diff_head_sha
)
}
end
,
start_time_conditions:
[[
"pipeline is started"
,
->
(
context
,
data
)
{
data
[
:pipeline
].
run!
}]],
end_time_conditions:
[[
"pipeline is finished"
,
->
(
context
,
data
)
{
data
[
:pipeline
].
succeed!
}]])
context
"when the pipeline is for a regular merge request (that doesn't close an issue)"
do
it
"returns nil"
do
5
.
times
do
merge_request
=
create
(
:merge_request
)
pipeline
=
create
(
:ci_pipeline
,
ref:
"refs/heads/
#{
merge_request
.
source_branch
}
"
,
sha:
merge_request
.
diff_head_sha
)
pipeline
.
run!
pipeline
.
succeed!
end
expect
(
subject
.
test
).
to
be_nil
end
end
context
"when the pipeline is not for a merge request"
do
it
"returns nil"
do
5
.
times
do
pipeline
=
create
(
:ci_pipeline
,
ref:
"refs/heads/master"
,
sha:
project
.
repository
.
commit
(
'master'
).
sha
)
pipeline
.
run!
pipeline
.
succeed!
end
expect
(
subject
.
test
).
to
be_nil
end
end
context
"when the pipeline is dropped (failed)"
do
it
"returns nil"
do
5
.
times
do
issue
=
create
(
:issue
,
project:
project
)
merge_request
=
create_merge_request_closing_issue
(
issue
)
pipeline
=
create
(
:ci_pipeline
,
ref:
"refs/heads/
#{
merge_request
.
source_branch
}
"
,
sha:
merge_request
.
diff_head_sha
)
pipeline
.
run!
pipeline
.
drop!
end
expect
(
subject
.
test
).
to
be_nil
end
end
context
"when the pipeline is cancelled"
do
it
"returns nil"
do
5
.
times
do
issue
=
create
(
:issue
,
project:
project
)
merge_request
=
create_merge_request_closing_issue
(
issue
)
pipeline
=
create
(
:ci_pipeline
,
ref:
"refs/heads/
#{
merge_request
.
source_branch
}
"
,
sha:
merge_request
.
diff_head_sha
)
pipeline
.
run!
pipeline
.
cancel!
end
expect
(
subject
.
test
).
to
be_nil
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