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
Léo-Paul Géneau
gitlab-ce
Commits
1b5b2eac
Commit
1b5b2eac
authored
Nov 03, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added missing fields to plan events and updated spec
parent
8f7266cd
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
55 additions
and
28 deletions
+55
-28
app/controllers/projects/cycle_analytics/events_controller.rb
...controllers/projects/cycle_analytics/events_controller.rb
+12
-9
lib/gitlab/cycle_analytics/events.rb
lib/gitlab/cycle_analytics/events.rb
+8
-3
lib/gitlab/cycle_analytics/query_config.rb
lib/gitlab/cycle_analytics/query_config.rb
+1
-2
lib/gitlab/light_url_builder.rb
lib/gitlab/light_url_builder.rb
+15
-5
spec/lib/gitlab/cycle_analytics/events_spec.rb
spec/lib/gitlab/cycle_analytics/events_spec.rb
+19
-9
No files found.
app/controllers/projects/cycle_analytics/events_controller.rb
View file @
1b5b2eac
class
Projects::CycleAnalytics::EventsController
<
Projects
::
ApplicationController
class
Projects::CycleAnalytics::EventsController
<
Projects
::
ApplicationController
# TODO: fix authorization
# before_action :authorize_read_cycle_analytics!
# before_action :authorize_read_cycle_analytics!
# TODO: refactor +event_hash+
def
issue
def
issue
render_events
(
events
.
issue_events
)
render_events
(
issues:
events
.
issue_events
)
end
end
def
plan
def
plan
render_events
(
events
.
plan_events
)
render_events
(
commits:
events
.
plan_events
)
end
end
def
code
def
code
render_events
(
events
.
code_events
)
render_events
(
merge_requests:
events
.
code_events
)
end
end
def
test
def
test
render_events
(
events
.
test_events
)
render_events
(
builds:
events
.
test_events
)
end
end
def
review
def
review
render_events
(
events
.
review_events
)
render_events
(
merge_requests:
events
.
review_events
)
end
end
def
staging
def
staging
render_events
(
events
.
staging_events
)
render_events
(
builds:
events
.
staging_events
)
end
end
def
production
def
production
render_events
(
events
.
production_events
)
render_events
(
issues:
events
.
production_events
)
end
end
private
private
def
render_events
(
event_
list
)
def
render_events
(
event_
hash
)
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
html
format
.
html
format
.
json
{
render
json:
{
events:
event_list
}
}
format
.
json
{
render
json:
event_hash
}
end
end
end
end
...
...
lib/gitlab/cycle_analytics/events.rb
View file @
1b5b2eac
...
@@ -16,8 +16,13 @@ module Gitlab
...
@@ -16,8 +16,13 @@ module Gitlab
def
plan_events
def
plan_events
@fetcher
.
fetch
(
stage: :plan
).
each
do
|
event
|
@fetcher
.
fetch
(
stage: :plan
).
each
do
|
event
|
event
[
'total_time'
]
=
distance_of_time_in_words
(
event
[
'total_time'
].
to_f
)
event
[
'total_time'
]
=
distance_of_time_in_words
(
event
[
'total_time'
].
to_f
)
commits
=
event
.
delete
(
'commits'
)
commit
=
first_time_reference_commit
(
event
.
delete
(
'commits'
),
event
)
event
[
'commit'
]
=
first_time_reference_commit
(
commits
,
event
)
event
[
'title'
]
=
commit
.
title
event
[
'url'
]
=
Gitlab
::
LightUrlBuilder
.
build
(
entity: :commit_url
,
project:
@project
,
id:
commit
.
id
)
event
[
'sha'
]
=
commit
.
short_id
event
[
'author_name'
]
=
commit
.
author
.
name
event
[
'author_profile_url'
]
=
Gitlab
::
LightUrlBuilder
.
build
(
entity: :user
,
id:
commit
.
author
.
username
)
event
[
'author_avatar_url'
]
=
Gitlab
::
LightUrlBuilder
.
build
(
entity: :user_avatar_url
,
id:
commit
.
author
.
id
)
end
end
end
end
...
@@ -56,7 +61,7 @@ module Gitlab
...
@@ -56,7 +61,7 @@ module Gitlab
event
[
'author_profile_url'
]
=
Gitlab
::
LightUrlBuilder
.
build
(
entity: :user
,
id:
event
[
'author_username'
])
event
[
'author_profile_url'
]
=
Gitlab
::
LightUrlBuilder
.
build
(
entity: :user
,
id:
event
[
'author_username'
])
event
[
'author_avatar_url'
]
=
Gitlab
::
LightUrlBuilder
.
build
(
entity: :user_avatar_url
,
id:
event
[
'author_id'
])
event
[
'author_avatar_url'
]
=
Gitlab
::
LightUrlBuilder
.
build
(
entity: :user_avatar_url
,
id:
event
[
'author_id'
])
event
.
except
(
'author_id'
,
'author_username'
)
event
.
except
!
(
'author_id'
,
'author_username'
)
end
end
def
first_time_reference_commit
(
commits
,
event
)
def
first_time_reference_commit
(
commits
,
event
)
...
...
lib/gitlab/cycle_analytics/query_config.rb
View file @
1b5b2eac
...
@@ -34,8 +34,7 @@ module Gitlab
...
@@ -34,8 +34,7 @@ module Gitlab
{
start_time_attrs:
issue_metrics_table
[
:first_associated_with_milestone_at
],
{
start_time_attrs:
issue_metrics_table
[
:first_associated_with_milestone_at
],
end_time_attrs:
[
issue_metrics_table
[
:first_added_to_board_at
],
end_time_attrs:
[
issue_metrics_table
[
:first_added_to_board_at
],
issue_metrics_table
[
:first_mentioned_in_commit_at
]],
issue_metrics_table
[
:first_mentioned_in_commit_at
]],
projections:
[
mr_diff_table
[
:st_commits
].
as
(
'commits'
),
projections:
[
mr_diff_table
[
:st_commits
].
as
(
'commits'
)]
issue_metrics_table
[
:first_mentioned_in_commit_at
]]
}
}
end
end
...
...
lib/gitlab/light_url_builder.rb
View file @
1b5b2eac
...
@@ -23,8 +23,10 @@ module Gitlab
...
@@ -23,8 +23,10 @@ module Gitlab
user_url
(
@id
)
user_url
(
@id
)
when
:user_avatar_url
when
:user_avatar_url
user_avatar_url
user_avatar_url
when
:commit_url
commit_url
else
else
raise
NotImplementedError
.
new
(
"No URL builder defined for
#{
object
.
class
}
"
)
raise
NotImplementedError
.
new
(
"No URL builder defined for
#{
object
.
class
}
"
)
end
end
end
end
...
@@ -32,14 +34,22 @@ module Gitlab
...
@@ -32,14 +34,22 @@ module Gitlab
def
issue_url
def
issue_url
namespace_project_issue_url
({
namespace_project_issue_url
({
namespace_id:
@project
.
namespace
,
namespace_id:
@project
.
namespace
,
project_id:
@project
,
project_id:
@project
,
id:
@id
id:
@id
}.
merge!
(
@opts
))
}.
merge!
(
@opts
))
end
end
def
user_avatar_url
def
user_avatar_url
User
.
find
(
@id
).
avatar_url
User
.
find
(
@id
).
avatar_url
end
end
def
commit_url
namespace_project_commit_url
({
namespace_id:
@project
.
namespace
,
project_id:
@project
,
id:
@id
}.
merge!
(
@opts
))
end
end
end
end
end
spec/lib/gitlab/cycle_analytics/events_spec.rb
View file @
1b5b2eac
...
@@ -4,6 +4,7 @@ describe Gitlab::CycleAnalytics::Events do
...
@@ -4,6 +4,7 @@ describe Gitlab::CycleAnalytics::Events do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:from_date
)
{
10
.
days
.
ago
}
let
(
:from_date
)
{
10
.
days
.
ago
}
let
(
:user
)
{
create
(
:user
,
:admin
)
}
let
(
:user
)
{
create
(
:user
,
:admin
)
}
let!
(
:context
)
{
create
(
:issue
,
project:
project
,
created_at:
2
.
days
.
ago
)
}
subject
{
described_class
.
new
(
project:
project
,
from:
from_date
)
}
subject
{
described_class
.
new
(
project:
project
,
from:
from_date
)
}
...
@@ -12,8 +13,6 @@ describe Gitlab::CycleAnalytics::Events do
...
@@ -12,8 +13,6 @@ describe Gitlab::CycleAnalytics::Events do
end
end
describe
'#issue_events'
do
describe
'#issue_events'
do
let!
(
:context
)
{
create
(
:issue
,
project:
project
,
created_at:
2
.
days
.
ago
)
}
it
'has the total time'
do
it
'has the total time'
do
expect
(
subject
.
issue_events
.
first
[
'total_time'
]).
to
eq
(
'2 days'
)
expect
(
subject
.
issue_events
.
first
[
'total_time'
]).
to
eq
(
'2 days'
)
end
end
...
@@ -44,20 +43,32 @@ describe Gitlab::CycleAnalytics::Events do
...
@@ -44,20 +43,32 @@ describe Gitlab::CycleAnalytics::Events do
end
end
describe
'#plan_events'
do
describe
'#plan_events'
do
let!
(
:context
)
{
create
(
:issue
,
project:
project
,
created_at:
2
.
days
.
ago
)
}
it
'has a title'
do
expect
(
subject
.
plan_events
.
first
[
'title'
]).
not_to
be_nil
end
it
'has
the first referenced commit
'
do
it
'has
a sha short ID
'
do
expect
(
subject
.
plan_events
.
first
[
'
commit'
].
message
).
to
eq
(
'commit message'
)
expect
(
subject
.
plan_events
.
first
[
'
sha'
]).
not_to
be_nil
end
end
it
'has the total time'
do
it
'has the total time'
do
expect
(
subject
.
plan_events
.
first
[
'total_time'
]).
to
eq
(
'less than a minute'
)
expect
(
subject
.
plan_events
.
first
[
'total_time'
]).
to
eq
(
'less than a minute'
)
end
end
it
"has the author's URL"
do
expect
(
subject
.
plan_events
.
first
[
'author_profile_url'
]).
not_to
be_nil
end
it
"has the author's avatar URL"
do
expect
(
subject
.
plan_events
.
first
[
'author_avatar_url'
]).
not_to
be_nil
end
it
"has the author's name"
do
expect
(
subject
.
plan_events
.
first
[
'author_name'
]).
not_to
be_nil
end
end
end
describe
'#code_events'
do
describe
'#code_events'
do
let!
(
:context
)
{
create
(
:issue
,
project:
project
,
created_at:
2
.
days
.
ago
)
}
before
do
before
do
create_commit_referencing_issue
(
context
)
create_commit_referencing_issue
(
context
)
end
end
...
@@ -88,7 +99,6 @@ describe Gitlab::CycleAnalytics::Events do
...
@@ -88,7 +99,6 @@ describe Gitlab::CycleAnalytics::Events do
end
end
describe
'#test_events'
do
describe
'#test_events'
do
let!
(
:context
)
{
create
(
:issue
,
project:
project
,
created_at:
2
.
days
.
ago
)
}
let
(
:merge_request
)
{
MergeRequest
.
first
}
let
(
:merge_request
)
{
MergeRequest
.
first
}
let!
(
:pipeline
)
do
let!
(
:pipeline
)
do
create
(
:ci_pipeline
,
create
(
:ci_pipeline
,
...
@@ -140,7 +150,6 @@ describe Gitlab::CycleAnalytics::Events do
...
@@ -140,7 +150,6 @@ describe Gitlab::CycleAnalytics::Events do
end
end
describe
'#staging_events'
do
describe
'#staging_events'
do
let!
(
:context
)
{
create
(
:issue
,
project:
project
,
created_at:
2
.
days
.
ago
)
}
let
(
:merge_request
)
{
MergeRequest
.
first
}
let
(
:merge_request
)
{
MergeRequest
.
first
}
let!
(
:pipeline
)
do
let!
(
:pipeline
)
do
create
(
:ci_pipeline
,
create
(
:ci_pipeline
,
...
@@ -152,6 +161,7 @@ describe Gitlab::CycleAnalytics::Events do
...
@@ -152,6 +161,7 @@ describe Gitlab::CycleAnalytics::Events do
before
do
before
do
pipeline
.
run!
pipeline
.
run!
pipeline
.
succeed!
pipeline
.
succeed!
merge_merge_requests_closing_issue
(
context
)
merge_merge_requests_closing_issue
(
context
)
deploy_master
deploy_master
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