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
Tatuya Kamada
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
# TODO: fix authorization
# before_action :authorize_read_cycle_analytics!
# TODO: refactor +event_hash+
def
issue
render_events
(
events
.
issue_events
)
render_events
(
issues:
events
.
issue_events
)
end
def
plan
render_events
(
events
.
plan_events
)
render_events
(
commits:
events
.
plan_events
)
end
def
code
render_events
(
events
.
code_events
)
render_events
(
merge_requests:
events
.
code_events
)
end
def
test
render_events
(
events
.
test_events
)
render_events
(
builds:
events
.
test_events
)
end
def
review
render_events
(
events
.
review_events
)
render_events
(
merge_requests:
events
.
review_events
)
end
def
staging
render_events
(
events
.
staging_events
)
render_events
(
builds:
events
.
staging_events
)
end
def
production
render_events
(
events
.
production_events
)
render_events
(
issues:
events
.
production_events
)
end
private
def
render_events
(
event_
list
)
def
render_events
(
event_
hash
)
respond_to
do
|
format
|
format
.
html
format
.
json
{
render
json:
{
events:
event_list
}
}
format
.
json
{
render
json:
event_hash
}
end
end
...
...
lib/gitlab/cycle_analytics/events.rb
View file @
1b5b2eac
...
...
@@ -16,8 +16,13 @@ module Gitlab
def
plan_events
@fetcher
.
fetch
(
stage: :plan
).
each
do
|
event
|
event
[
'total_time'
]
=
distance_of_time_in_words
(
event
[
'total_time'
].
to_f
)
commits
=
event
.
delete
(
'commits'
)
event
[
'commit'
]
=
first_time_reference_commit
(
commits
,
event
)
commit
=
first_time_reference_commit
(
event
.
delete
(
'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
...
...
@@ -56,7 +61,7 @@ module Gitlab
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
.
except
(
'author_id'
,
'author_username'
)
event
.
except
!
(
'author_id'
,
'author_username'
)
end
def
first_time_reference_commit
(
commits
,
event
)
...
...
lib/gitlab/cycle_analytics/query_config.rb
View file @
1b5b2eac
...
...
@@ -34,8 +34,7 @@ module Gitlab
{
start_time_attrs:
issue_metrics_table
[
:first_associated_with_milestone_at
],
end_time_attrs:
[
issue_metrics_table
[
:first_added_to_board_at
],
issue_metrics_table
[
:first_mentioned_in_commit_at
]],
projections:
[
mr_diff_table
[
:st_commits
].
as
(
'commits'
),
issue_metrics_table
[
:first_mentioned_in_commit_at
]]
projections:
[
mr_diff_table
[
:st_commits
].
as
(
'commits'
)]
}
end
...
...
lib/gitlab/light_url_builder.rb
View file @
1b5b2eac
...
...
@@ -23,8 +23,10 @@ module Gitlab
user_url
(
@id
)
when
:user_avatar_url
user_avatar_url
when
:commit_url
commit_url
else
raise
NotImplementedError
.
new
(
"No URL builder defined for
#{
object
.
class
}
"
)
raise
NotImplementedError
.
new
(
"No URL builder defined for
#{
object
.
class
}
"
)
end
end
...
...
@@ -32,14 +34,22 @@ module Gitlab
def
issue_url
namespace_project_issue_url
({
namespace_id:
@project
.
namespace
,
project_id:
@project
,
id:
@id
}.
merge!
(
@opts
))
namespace_id:
@project
.
namespace
,
project_id:
@project
,
id:
@id
}.
merge!
(
@opts
))
end
def
user_avatar_url
User
.
find
(
@id
).
avatar_url
end
def
commit_url
namespace_project_commit_url
({
namespace_id:
@project
.
namespace
,
project_id:
@project
,
id:
@id
}.
merge!
(
@opts
))
end
end
end
spec/lib/gitlab/cycle_analytics/events_spec.rb
View file @
1b5b2eac
...
...
@@ -4,6 +4,7 @@ describe Gitlab::CycleAnalytics::Events do
let
(
:project
)
{
create
(
:project
)
}
let
(
:from_date
)
{
10
.
days
.
ago
}
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
)
}
...
...
@@ -12,8 +13,6 @@ describe Gitlab::CycleAnalytics::Events do
end
describe
'#issue_events'
do
let!
(
:context
)
{
create
(
:issue
,
project:
project
,
created_at:
2
.
days
.
ago
)
}
it
'has the total time'
do
expect
(
subject
.
issue_events
.
first
[
'total_time'
]).
to
eq
(
'2 days'
)
end
...
...
@@ -44,20 +43,32 @@ describe Gitlab::CycleAnalytics::Events do
end
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
expect
(
subject
.
plan_events
.
first
[
'
commit'
].
message
).
to
eq
(
'commit message'
)
it
'has
a sha short ID
'
do
expect
(
subject
.
plan_events
.
first
[
'
sha'
]).
not_to
be_nil
end
it
'has the total time'
do
expect
(
subject
.
plan_events
.
first
[
'total_time'
]).
to
eq
(
'less than a minute'
)
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
describe
'#code_events'
do
let!
(
:context
)
{
create
(
:issue
,
project:
project
,
created_at:
2
.
days
.
ago
)
}
before
do
create_commit_referencing_issue
(
context
)
end
...
...
@@ -88,7 +99,6 @@ describe Gitlab::CycleAnalytics::Events do
end
describe
'#test_events'
do
let!
(
:context
)
{
create
(
:issue
,
project:
project
,
created_at:
2
.
days
.
ago
)
}
let
(
:merge_request
)
{
MergeRequest
.
first
}
let!
(
:pipeline
)
do
create
(
:ci_pipeline
,
...
...
@@ -140,7 +150,6 @@ describe Gitlab::CycleAnalytics::Events do
end
describe
'#staging_events'
do
let!
(
:context
)
{
create
(
:issue
,
project:
project
,
created_at:
2
.
days
.
ago
)
}
let
(
:merge_request
)
{
MergeRequest
.
first
}
let!
(
:pipeline
)
do
create
(
:ci_pipeline
,
...
...
@@ -152,6 +161,7 @@ describe Gitlab::CycleAnalytics::Events do
before
do
pipeline
.
run!
pipeline
.
succeed!
merge_merge_requests_closing_issue
(
context
)
deploy_master
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