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
7ac7cfeb
Commit
7ac7cfeb
authored
Nov 07, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored and added missing spec to light URL builder
parent
192918cd
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
174 additions
and
112 deletions
+174
-112
lib/gitlab/cycle_analytics/events.rb
lib/gitlab/cycle_analytics/events.rb
+4
-4
lib/gitlab/cycle_analytics/metrics_fetcher.rb
lib/gitlab/cycle_analytics/metrics_fetcher.rb
+0
-4
lib/gitlab/light_url_builder.rb
lib/gitlab/light_url_builder.rb
+4
-12
spec/lib/gitlab/cycle_analytics/events_spec.rb
spec/lib/gitlab/cycle_analytics/events_spec.rb
+1
-1
spec/lib/gitlab/url_builder_spec.rb
spec/lib/gitlab/url_builder_spec.rb
+46
-91
spec/lib/light_url_builder_spec.rb
spec/lib/light_url_builder_spec.rb
+119
-0
No files found.
lib/gitlab/cycle_analytics/events.rb
View file @
7ac7cfeb
...
@@ -52,7 +52,7 @@ module Gitlab
...
@@ -52,7 +52,7 @@ module Gitlab
private
private
def
parse_event
(
event
,
entity: :issue
)
def
parse_event
(
event
,
entity: :issue
)
event
[
'url'
]
=
Gitlab
::
LightUrlBuilder
.
build
(
entity:
entity
,
project:
@project
,
id:
event
[
'id'
])
event
[
'url'
]
=
Gitlab
::
LightUrlBuilder
.
build
(
entity:
entity
,
project:
@project
,
id:
event
[
'i
i
d'
])
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
)
event
[
'created_at'
]
=
interval_in_words
(
event
[
'created_at'
])
event
[
'created_at'
]
=
interval_in_words
(
event
[
'created_at'
])
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'
])
...
@@ -64,11 +64,11 @@ module Gitlab
...
@@ -64,11 +64,11 @@ module Gitlab
def
parse_build_event
(
event
)
def
parse_build_event
(
event
)
build
=
::
Ci
::
Build
.
find
(
event
[
'id'
])
build
=
::
Ci
::
Build
.
find
(
event
[
'id'
])
event
[
'name'
]
=
build
.
name
event
[
'name'
]
=
build
.
name
event
[
'url'
]
=
Gitlab
::
LightUrlBuilder
.
build
(
entity: :build
_url
,
project:
@project
,
id:
build
.
id
)
event
[
'url'
]
=
Gitlab
::
LightUrlBuilder
.
build
(
entity: :build
,
project:
@project
,
id:
build
.
id
)
event
[
'branch'
]
=
build
.
ref
event
[
'branch'
]
=
build
.
ref
event
[
'branch
_url'
]
=
Gitlab
::
LightUrlBuilder
.
build
(
entity: :branch_url
,
project:
@project
,
id:
build
.
ref
)
event
[
'branch
'
]
=
Gitlab
::
LightUrlBuilder
.
build
(
entity: :branch
,
project:
@project
,
id:
build
.
ref
)
event
[
'sha'
]
=
build
.
short_sha
event
[
'sha'
]
=
build
.
short_sha
event
[
'commit
_url'
]
=
Gitlab
::
LightUrlBuilder
.
build
(
entity: :commit_url
,
project:
@project
,
id:
build
.
sha
)
event
[
'commit
'
]
=
Gitlab
::
LightUrlBuilder
.
build
(
entity: :commit
,
project:
@project
,
id:
build
.
sha
)
event
[
'date'
]
=
build
.
started_at
event
[
'date'
]
=
build
.
started_at
event
[
'total_time'
]
=
build
.
duration
event
[
'total_time'
]
=
build
.
duration
event
[
'author_name'
]
=
build
.
author
.
try
(
:name
)
event
[
'author_name'
]
=
build
.
author
.
try
(
:name
)
...
...
lib/gitlab/cycle_analytics/metrics_fetcher.rb
View file @
7ac7cfeb
...
@@ -6,10 +6,6 @@ module Gitlab
...
@@ -6,10 +6,6 @@ module Gitlab
DEPLOYMENT_METRIC_STAGES
=
%i[production staging]
DEPLOYMENT_METRIC_STAGES
=
%i[production staging]
def
self
.
included
(
klass
)
klass
.
extend
self
end
private
private
def
calculate_metric
(
name
,
start_time_attrs
,
end_time_attrs
)
def
calculate_metric
(
name
,
start_time_attrs
,
end_time_attrs
)
...
...
lib/gitlab/light_url_builder.rb
View file @
7ac7cfeb
...
@@ -22,15 +22,15 @@ module Gitlab
...
@@ -22,15 +22,15 @@ module Gitlab
issue_url
issue_url
when
:user
when
:user
user_url
(
@id
)
user_url
(
@id
)
when
:user_avatar
_url
when
:user_avatar
user_avatar_url
user_avatar_url
when
:commit
_url
when
:commit
commit_url
commit_url
when
:merge_request
when
:merge_request
mr_url
mr_url
when
:build
_url
when
:build
namespace_project_build_url
(
@project
.
namespace
,
@project
,
@id
)
namespace_project_build_url
(
@project
.
namespace
,
@project
,
@id
)
when
:branch
_url
when
:branch
branch_url
branch_url
else
else
raise
NotImplementedError
.
new
(
"No URL builder defined for
#{
object
.
class
}
"
)
raise
NotImplementedError
.
new
(
"No URL builder defined for
#{
object
.
class
}
"
)
...
@@ -67,14 +67,6 @@ module Gitlab
...
@@ -67,14 +67,6 @@ module Gitlab
}.
merge!
(
@opts
))
}.
merge!
(
@opts
))
end
end
def
pipeline_url
namespace_project_build_url
({
namespace_id:
@project
.
namespace
,
project_id:
@project
,
id:
@id
}.
merge!
(
@opts
))
end
def
branch_url
def
branch_url
"
#{
project_url
(
@project
)
}
/commits/
#{
@id
}
"
"
#{
project_url
(
@project
)
}
/commits/
#{
@id
}
"
end
end
...
...
spec/lib/gitlab/cycle_analytics/events_spec.rb
View file @
7ac7cfeb
...
@@ -196,7 +196,7 @@ describe Gitlab::CycleAnalytics::Events do
...
@@ -196,7 +196,7 @@ describe Gitlab::CycleAnalytics::Events do
end
end
it
"has the author's name"
do
it
"has the author's name"
do
expect
(
subject
.
review_events
.
first
[
'author_name'
]).
to
eq
(
contex
t
.
author
.
name
)
expect
(
subject
.
review_events
.
first
[
'author_name'
]).
to
eq
(
MergeRequest
.
firs
t
.
author
.
name
)
end
end
end
end
...
...
spec/lib/gitlab/url_builder_spec.rb
View file @
7ac7cfeb
require
'spec_helper'
require
'spec_helper'
describe
Gitlab
::
UrlBuilder
,
lib:
true
do
describe
Gitlab
::
LightUrlBuilder
,
lib:
true
do
describe
'.build'
do
context
'when passing a Commit'
do
context
'when passing a Commit'
do
it
'returns a proper URL'
do
it
'returns a proper URL'
do
commit
=
build_stubbed
(
:commit
)
commit
=
build_stubbed
(
:commit
)
url
=
described_class
.
build
(
commit
)
url
=
described_class
.
build
(
entity: :commit
,
project:
commit
.
project
,
id:
commit
.
id
)
expect
(
url
).
to
eq
"
#{
Settings
.
gitlab
[
'url'
]
}
/
#{
commit
.
project
.
path_with_namespace
}
/commit/
#{
commit
.
id
}
"
expect
(
url
).
to
eq
"
#{
Settings
.
gitlab
[
'url'
]
}
/
#{
commit
.
project
.
path_with_namespace
}
/commit/
#{
commit
.
id
}
"
end
end
...
@@ -16,7 +15,7 @@ describe Gitlab::UrlBuilder, lib: true do
...
@@ -16,7 +15,7 @@ describe Gitlab::UrlBuilder, lib: true do
it
'returns a proper URL'
do
it
'returns a proper URL'
do
issue
=
build_stubbed
(
:issue
,
iid:
42
)
issue
=
build_stubbed
(
:issue
,
iid:
42
)
url
=
described_class
.
build
(
issue
)
url
=
described_class
.
build
(
entity: :issue
,
project:
issue
.
project
,
id:
issue
.
iid
)
expect
(
url
).
to
eq
"
#{
Settings
.
gitlab
[
'url'
]
}
/
#{
issue
.
project
.
path_with_namespace
}
/issues/
#{
issue
.
iid
}
"
expect
(
url
).
to
eq
"
#{
Settings
.
gitlab
[
'url'
]
}
/
#{
issue
.
project
.
path_with_namespace
}
/issues/
#{
issue
.
iid
}
"
end
end
...
@@ -26,94 +25,50 @@ describe Gitlab::UrlBuilder, lib: true do
...
@@ -26,94 +25,50 @@ describe Gitlab::UrlBuilder, lib: true do
it
'returns a proper URL'
do
it
'returns a proper URL'
do
merge_request
=
build_stubbed
(
:merge_request
,
iid:
42
)
merge_request
=
build_stubbed
(
:merge_request
,
iid:
42
)
url
=
described_class
.
build
(
merge_request
)
url
=
described_class
.
build
(
entity: :merge_request
,
project:
merge_request
.
project
,
id:
merge_request
.
iid
)
expect
(
url
).
to
eq
"
#{
Settings
.
gitlab
[
'url'
]
}
/
#{
merge_request
.
project
.
path_with_namespace
}
/merge_requests/
#{
merge_request
.
iid
}
"
expect
(
url
).
to
eq
"
#{
Settings
.
gitlab
[
'url'
]
}
/
#{
merge_request
.
project
.
path_with_namespace
}
/merge_requests/
#{
merge_request
.
iid
}
"
end
end
end
end
context
'when passing a Note'
do
context
'when passing a build'
do
context
'on a Commit'
do
it
'returns a proper URL'
do
it
'returns a proper URL'
do
note
=
build_stubbed
(
:note_on_commit
)
build
=
build_stubbed
(
:ci_build
,
project:
build_stubbed
(
:empty_project
)
)
url
=
described_class
.
build
(
note
)
url
=
described_class
.
build
(
entity: :build
,
project:
build
.
project
,
id:
build
.
id
)
expect
(
url
).
to
eq
"
#{
Settings
.
gitlab
[
'url'
]
}
/
#{
note
.
project
.
path_with_namespace
}
/commit/
#{
note
.
commit_id
}
#note_
#{
note
.
id
}
"
expect
(
url
).
to
eq
"
#{
Settings
.
gitlab
[
'url'
]
}
/
#{
build
.
project
.
path_with_namespace
}
/builds/
#{
build
.
id
}
"
end
end
end
end
context
'on a Commit Diff
'
do
context
'when passing a branch
'
do
it
'returns a proper URL'
do
it
'returns a proper URL'
do
note
=
build_stubbed
(
:diff_note_on_commit
)
branch
=
'branch_name'
project
=
build_stubbed
(
:empty_project
)
url
=
described_class
.
build
(
note
)
url
=
described_class
.
build
(
entity: :branch
,
project:
project
,
id:
branch
)
expect
(
url
).
to
eq
"
#{
Settings
.
gitlab
[
'url'
]
}
/
#{
note
.
project
.
path_with_namespace
}
/commit/
#{
note
.
commit_id
}
#note_
#{
note
.
id
}
"
expect
(
url
).
to
eq
"
#{
Settings
.
gitlab
[
'url'
]
}
/
#{
project
.
path_with_namespace
}
/commits/
#{
branch
}
"
end
end
end
end
context
'on an Issue
'
do
context
'on a User
'
do
it
'returns a proper URL'
do
it
'returns a proper URL'
do
issue
=
create
(
:issue
,
iid:
42
)
user
=
build_stubbed
(
:user
)
note
=
build_stubbed
(
:note_on_issue
,
noteable:
issue
)
url
=
described_class
.
build
(
not
e
)
url
=
described_class
.
build
(
entity: :user
,
id:
user
.
usernam
e
)
expect
(
url
).
to
eq
"
#{
Settings
.
gitlab
[
'url'
]
}
/
#{
issue
.
project
.
path_with_namespace
}
/issues/
#{
issue
.
iid
}
#note_
#{
note
.
id
}
"
expect
(
url
).
to
eq
"
#{
Settings
.
gitlab
[
'url'
]
}
/
#{
user
.
username
}
"
end
end
end
end
context
'on a MergeRequest
'
do
context
'on a user avatar
'
do
it
'returns a proper URL'
do
it
'returns a proper URL'
do
merge_request
=
create
(
:merge_request
,
iid:
42
)
user
=
create
(
:user
)
note
=
build_stubbed
(
:note_on_merge_request
,
noteable:
merge_request
)
url
=
described_class
.
build
(
note
)
url
=
described_class
.
build
(
entity: :user_avatar
,
id:
user
.
id
)
expect
(
url
).
to
eq
"
#{
Settings
.
gitlab
[
'url'
]
}
/
#{
merge_request
.
project
.
path_with_namespace
}
/merge_requests/
#{
merge_request
.
iid
}
#note_
#{
note
.
id
}
"
expect
(
url
).
to
eq
user
.
avatar_url
end
end
context
'on a MergeRequest Diff'
do
it
'returns a proper URL'
do
merge_request
=
create
(
:merge_request
,
iid:
42
)
note
=
build_stubbed
(
:diff_note_on_merge_request
,
noteable:
merge_request
)
url
=
described_class
.
build
(
note
)
expect
(
url
).
to
eq
"
#{
Settings
.
gitlab
[
'url'
]
}
/
#{
merge_request
.
project
.
path_with_namespace
}
/merge_requests/
#{
merge_request
.
iid
}
#note_
#{
note
.
id
}
"
end
end
context
'on a ProjectSnippet'
do
it
'returns a proper URL'
do
project_snippet
=
create
(
:project_snippet
)
note
=
build_stubbed
(
:note_on_project_snippet
,
noteable:
project_snippet
)
url
=
described_class
.
build
(
note
)
expect
(
url
).
to
eq
"
#{
Settings
.
gitlab
[
'url'
]
}
/
#{
project_snippet
.
project
.
path_with_namespace
}
/snippets/
#{
note
.
noteable_id
}
#note_
#{
note
.
id
}
"
end
end
context
'on another object'
do
it
'returns a proper URL'
do
project
=
build_stubbed
(
:project
)
expect
{
described_class
.
build
(
project
)
}.
to
raise_error
(
NotImplementedError
,
'No URL builder defined for Project'
)
end
end
end
context
'when passing a WikiPage'
do
it
'returns a proper URL'
do
wiki_page
=
build
(
:wiki_page
)
url
=
described_class
.
build
(
wiki_page
)
expect
(
url
).
to
eq
"
#{
Gitlab
.
config
.
gitlab
.
url
}#{
wiki_page
.
wiki
.
wiki_base_path
}
/
#{
wiki_page
.
slug
}
"
end
end
end
end
end
end
end
spec/lib/light_url_builder_spec.rb
0 → 100644
View file @
7ac7cfeb
require
'spec_helper'
describe
Gitlab
::
UrlBuilder
,
lib:
true
do
describe
'.build'
do
context
'when passing a Commit'
do
it
'returns a proper URL'
do
commit
=
build_stubbed
(
:commit
)
url
=
described_class
.
build
(
commit
)
expect
(
url
).
to
eq
"
#{
Settings
.
gitlab
[
'url'
]
}
/
#{
commit
.
project
.
path_with_namespace
}
/commit/
#{
commit
.
id
}
"
end
end
context
'when passing an Issue'
do
it
'returns a proper URL'
do
issue
=
build_stubbed
(
:issue
,
iid:
42
)
url
=
described_class
.
build
(
issue
)
expect
(
url
).
to
eq
"
#{
Settings
.
gitlab
[
'url'
]
}
/
#{
issue
.
project
.
path_with_namespace
}
/issues/
#{
issue
.
iid
}
"
end
end
context
'when passing a MergeRequest'
do
it
'returns a proper URL'
do
merge_request
=
build_stubbed
(
:merge_request
,
iid:
42
)
url
=
described_class
.
build
(
merge_request
)
expect
(
url
).
to
eq
"
#{
Settings
.
gitlab
[
'url'
]
}
/
#{
merge_request
.
project
.
path_with_namespace
}
/merge_requests/
#{
merge_request
.
iid
}
"
end
end
context
'when passing a Note'
do
context
'on a Commit'
do
it
'returns a proper URL'
do
note
=
build_stubbed
(
:note_on_commit
)
url
=
described_class
.
build
(
note
)
expect
(
url
).
to
eq
"
#{
Settings
.
gitlab
[
'url'
]
}
/
#{
note
.
project
.
path_with_namespace
}
/commit/
#{
note
.
commit_id
}
#note_
#{
note
.
id
}
"
end
end
context
'on a Commit Diff'
do
it
'returns a proper URL'
do
note
=
build_stubbed
(
:diff_note_on_commit
)
url
=
described_class
.
build
(
note
)
expect
(
url
).
to
eq
"
#{
Settings
.
gitlab
[
'url'
]
}
/
#{
note
.
project
.
path_with_namespace
}
/commit/
#{
note
.
commit_id
}
#note_
#{
note
.
id
}
"
end
end
context
'on an Issue'
do
it
'returns a proper URL'
do
issue
=
create
(
:issue
,
iid:
42
)
note
=
build_stubbed
(
:note_on_issue
,
noteable:
issue
)
url
=
described_class
.
build
(
note
)
expect
(
url
).
to
eq
"
#{
Settings
.
gitlab
[
'url'
]
}
/
#{
issue
.
project
.
path_with_namespace
}
/issues/
#{
issue
.
iid
}
#note_
#{
note
.
id
}
"
end
end
context
'on a MergeRequest'
do
it
'returns a proper URL'
do
merge_request
=
create
(
:merge_request
,
iid:
42
)
note
=
build_stubbed
(
:note_on_merge_request
,
noteable:
merge_request
)
url
=
described_class
.
build
(
note
)
expect
(
url
).
to
eq
"
#{
Settings
.
gitlab
[
'url'
]
}
/
#{
merge_request
.
project
.
path_with_namespace
}
/merge_requests/
#{
merge_request
.
iid
}
#note_
#{
note
.
id
}
"
end
end
context
'on a MergeRequest Diff'
do
it
'returns a proper URL'
do
merge_request
=
create
(
:merge_request
,
iid:
42
)
note
=
build_stubbed
(
:diff_note_on_merge_request
,
noteable:
merge_request
)
url
=
described_class
.
build
(
note
)
expect
(
url
).
to
eq
"
#{
Settings
.
gitlab
[
'url'
]
}
/
#{
merge_request
.
project
.
path_with_namespace
}
/merge_requests/
#{
merge_request
.
iid
}
#note_
#{
note
.
id
}
"
end
end
context
'on a ProjectSnippet'
do
it
'returns a proper URL'
do
project_snippet
=
create
(
:project_snippet
)
note
=
build_stubbed
(
:note_on_project_snippet
,
noteable:
project_snippet
)
url
=
described_class
.
build
(
note
)
expect
(
url
).
to
eq
"
#{
Settings
.
gitlab
[
'url'
]
}
/
#{
project_snippet
.
project
.
path_with_namespace
}
/snippets/
#{
note
.
noteable_id
}
#note_
#{
note
.
id
}
"
end
end
context
'on another object'
do
it
'returns a proper URL'
do
project
=
build_stubbed
(
:project
)
expect
{
described_class
.
build
(
project
)
}.
to
raise_error
(
NotImplementedError
,
'No URL builder defined for Project'
)
end
end
end
context
'when passing a WikiPage'
do
it
'returns a proper URL'
do
wiki_page
=
build
(
:wiki_page
)
url
=
described_class
.
build
(
wiki_page
)
expect
(
url
).
to
eq
"
#{
Gitlab
.
config
.
gitlab
.
url
}#{
wiki_page
.
wiki
.
wiki_base_path
}
/
#{
wiki_page
.
slug
}
"
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