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
5cae41b1
Commit
5cae41b1
authored
Jul 31, 2017
by
Jacob Vosmaer
Committed by
Lin Jen-Shin
Aug 02, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add option to use CommitLanguages RPC
parent
76ea118c
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
75 additions
and
51 deletions
+75
-51
GITALY_SERVER_VERSION
GITALY_SERVER_VERSION
+1
-1
app/controllers/projects/graphs_controller.rb
app/controllers/projects/graphs_controller.rb
+1
-17
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+27
-0
lib/gitlab/gitaly_client/commit_service.rb
lib/gitlab/gitaly_client/commit_service.rb
+7
-0
spec/controllers/projects/graphs_controller_spec.rb
spec/controllers/projects/graphs_controller_spec.rb
+0
-33
spec/lib/gitlab/git/repository_spec.rb
spec/lib/gitlab/git/repository_spec.rb
+39
-0
No files found.
GITALY_SERVER_VERSION
View file @
5cae41b1
0.2
5
.0
0.2
6
.0
app/controllers/projects/graphs_controller.rb
View file @
5cae41b1
...
...
@@ -43,23 +43,7 @@ class Projects::GraphsController < Projects::ApplicationController
end
def
get_languages
@languages
=
Linguist
::
Repository
.
new
(
@repository
.
rugged
,
@repository
.
rugged
.
head
.
target_id
).
languages
total
=
@languages
.
map
(
&
:last
).
sum
@languages
=
@languages
.
map
do
|
language
|
name
,
share
=
language
color
=
Linguist
::
Language
[
name
].
color
||
"#
#{
Digest
::
SHA256
.
hexdigest
(
name
)[
0
...
6
]
}
"
{
value:
(
share
.
to_f
*
100
/
total
).
round
(
2
),
label:
name
,
color:
color
,
highlight:
color
}
end
@languages
.
sort!
do
|
x
,
y
|
y
[
:value
]
<=>
x
[
:value
]
end
@languages
=
@project
.
repository
.
languages
end
def
fetch_graph
...
...
lib/gitlab/git/repository.rb
View file @
5cae41b1
...
...
@@ -636,6 +636,33 @@ module Gitlab
@attributes
.
attributes
(
path
)
end
def
languages
(
ref
=
nil
)
Gitlab
::
GitalyClient
.
migrate
(
:commit_languages
)
do
|
is_enabled
|
if
is_enabled
gitaly_commit_client
.
languages
(
ref
)
else
ref
||=
rugged
.
head
.
target_id
languages
=
Linguist
::
Repository
.
new
(
rugged
,
ref
).
languages
total
=
languages
.
map
(
&
:last
).
sum
languages
=
languages
.
map
do
|
language
|
name
,
share
=
language
color
=
Linguist
::
Language
[
name
].
color
||
"#
#{
Digest
::
SHA256
.
hexdigest
(
name
)[
0
...
6
]
}
"
{
value:
(
share
.
to_f
*
100
/
total
).
round
(
2
),
label:
name
,
color:
color
,
highlight:
color
}
end
languages
.
sort
do
|
x
,
y
|
y
[
:value
]
<=>
x
[
:value
]
end
end
end
end
def
gitaly_repository
Gitlab
::
GitalyClient
::
Util
.
repository
(
@storage
,
@relative_path
)
end
...
...
lib/gitlab/gitaly_client/commit_service.rb
View file @
5cae41b1
...
...
@@ -118,6 +118,13 @@ module Gitlab
consume_commits_response
(
response
)
end
def
languages
(
ref
=
nil
)
request
=
Gitaly
::
CommitLanguagesRequest
.
new
(
repository:
@gitaly_repo
,
revision:
ref
||
''
)
response
=
GitalyClient
.
call
(
@repository
.
storage
,
:commit_service
,
:commit_languages
,
request
)
response
.
languages
.
map
{
|
l
|
{
value:
l
.
share
.
round
(
2
),
label:
l
.
name
,
color:
l
.
color
,
highlight:
l
.
color
}
}
end
private
def
commit_diff_request_params
(
commit
,
options
=
{})
...
...
spec/controllers/projects/graphs_controller_spec.rb
View file @
5cae41b1
...
...
@@ -24,37 +24,4 @@ describe Projects::GraphsController do
expect
(
response
).
to
redirect_to
action: :charts
end
end
describe
'GET charts'
do
let
(
:linguist_repository
)
do
double
(
languages:
{
'Ruby'
=>
1000
,
'CoffeeScript'
=>
350
,
'NSIS'
=>
15
})
end
let
(
:expected_values
)
do
nsis_color
=
"#
#{
Digest
::
SHA256
.
hexdigest
(
'NSIS'
)[
0
...
6
]
}
"
[
# colors from Linguist:
{
label:
"Ruby"
,
color:
"#701516"
,
highlight:
"#701516"
},
{
label:
"CoffeeScript"
,
color:
"#244776"
,
highlight:
"#244776"
},
# colors from SHA256 fallback:
{
label:
"NSIS"
,
color:
nsis_color
,
highlight:
nsis_color
}
]
end
before
do
allow
(
Linguist
::
Repository
).
to
receive
(
:new
).
and_return
(
linguist_repository
)
end
it
'sets the correct colour according to language'
do
get
(
:charts
,
namespace_id:
project
.
namespace
,
project_id:
project
,
id:
'master'
)
expected_values
.
each
do
|
val
|
expect
(
assigns
(
:languages
)).
to
include
(
a_hash_including
(
val
))
end
end
end
end
spec/lib/gitlab/git/repository_spec.rb
View file @
5cae41b1
...
...
@@ -1127,6 +1127,45 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
end
describe
'#languages'
do
shared_examples
'languages'
do
it
'returns exactly the expected results'
do
languages
=
repository
.
languages
(
'4b4918a572fa86f9771e5ba40fbd48e1eb03e2c6'
)
expected_languages
=
[
{
value:
66.63
,
label:
"Ruby"
,
color:
"#701516"
,
highlight:
"#701516"
},
{
value:
22.96
,
label:
"JavaScript"
,
color:
"#f1e05a"
,
highlight:
"#f1e05a"
},
{
value:
7.9
,
label:
"HTML"
,
color:
"#e44b23"
,
highlight:
"#e44b23"
},
{
value:
2.51
,
label:
"CoffeeScript"
,
color:
"#244776"
,
highlight:
"#244776"
}
]
expect
(
languages
.
size
).
to
eq
(
expected_languages
.
size
)
expected_languages
.
size
.
times
do
|
i
|
a
=
expected_languages
[
i
]
b
=
languages
[
i
]
expect
(
a
.
keys
.
sort
).
to
eq
(
b
.
keys
.
sort
)
expect
(
a
[
:value
]).
to
be_within
(
0.1
).
of
(
b
[
:value
])
non_float_keys
=
a
.
keys
-
[
:value
]
expect
(
a
.
values_at
(
*
non_float_keys
)).
to
eq
(
b
.
values_at
(
*
non_float_keys
))
end
end
it
"uses the repository's HEAD when no ref is passed"
do
lang
=
repository
.
languages
.
first
expect
(
lang
[
:label
]).
to
eq
(
'Ruby'
)
end
end
it_behaves_like
'languages'
context
'with rugged'
,
skip_gitaly_mock:
true
do
it_behaves_like
'languages'
end
end
def
create_remote_branch
(
repository
,
remote_name
,
branch_name
,
source_branch_name
)
source_branch
=
repository
.
branches
.
find
{
|
branch
|
branch
.
name
==
source_branch_name
}
rugged
=
repository
.
rugged
...
...
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