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
f089a230
Commit
f089a230
authored
Aug 13, 2019
by
Pavel Shutsin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backport EE changes for productivity analytics
Improve diff lines count efficiency
parent
fd561023
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
93 additions
and
4 deletions
+93
-4
app/models/merge_request_diff.rb
app/models/merge_request_diff.rb
+5
-1
lib/gitlab/git/diff_collection.rb
lib/gitlab/git/diff_collection.rb
+6
-0
spec/lib/gitlab/git/diff_collection_spec.rb
spec/lib/gitlab/git/diff_collection_spec.rb
+69
-0
spec/models/merge_request/metrics_spec.rb
spec/models/merge_request/metrics_spec.rb
+0
-2
spec/models/merge_request_diff_spec.rb
spec/models/merge_request_diff_spec.rb
+13
-1
No files found.
app/models/merge_request_diff.rb
View file @
f089a230
...
...
@@ -197,7 +197,7 @@ class MergeRequestDiff < ApplicationRecord
def
lines_count
strong_memoize
(
:lines_count
)
do
diffs
.
diff_files
.
sum
(
&
:line_count
)
raw_diffs
(
limits:
false
).
line_count
end
end
...
...
@@ -222,6 +222,10 @@ class MergeRequestDiff < ApplicationRecord
commits
.
last
end
def
last_commit
commits
.
first
end
def
base_commit
return
unless
base_commit_sha
...
...
lib/gitlab/git/diff_collection.rb
View file @
f089a230
...
...
@@ -81,6 +81,12 @@ module Gitlab
end
end
def
line_count
populate!
@line_count
end
def
decorate!
collection
=
each_with_index
do
|
element
,
i
|
@array
[
i
]
=
yield
(
element
)
...
...
spec/lib/gitlab/git/diff_collection_spec.rb
View file @
f089a230
...
...
@@ -74,6 +74,11 @@ describe Gitlab::Git::DiffCollection, :seed_helper do
end
end
describe
'#line_count'
do
subject
{
super
().
line_count
}
it
{
is_expected
.
to
eq
file_count
*
line_count
}
end
context
'when limiting is disabled'
do
let
(
:limits
)
{
false
}
...
...
@@ -100,6 +105,11 @@ describe Gitlab::Git::DiffCollection, :seed_helper do
expect
(
subject
.
size
).
to
eq
(
3
)
end
end
describe
'#line_count'
do
subject
{
super
().
line_count
}
it
{
is_expected
.
to
eq
file_count
*
line_count
}
end
end
end
...
...
@@ -120,6 +130,12 @@ describe Gitlab::Git::DiffCollection, :seed_helper do
subject
{
super
().
real_size
}
it
{
is_expected
.
to
eq
(
'0+'
)
}
end
describe
'#line_count'
do
subject
{
super
().
line_count
}
it
{
is_expected
.
to
eq
1000
}
end
it
{
expect
(
subject
.
size
).
to
eq
(
0
)
}
context
'when limiting is disabled'
do
...
...
@@ -139,6 +155,12 @@ describe Gitlab::Git::DiffCollection, :seed_helper do
subject
{
super
().
real_size
}
it
{
is_expected
.
to
eq
(
'3'
)
}
end
describe
'#line_count'
do
subject
{
super
().
line_count
}
it
{
is_expected
.
to
eq
file_count
*
line_count
}
end
it
{
expect
(
subject
.
size
).
to
eq
(
3
)
}
end
end
...
...
@@ -164,6 +186,12 @@ describe Gitlab::Git::DiffCollection, :seed_helper do
subject
{
super
().
real_size
}
it
{
is_expected
.
to
eq
(
'10+'
)
}
end
describe
'#line_count'
do
subject
{
super
().
line_count
}
it
{
is_expected
.
to
eq
10
}
end
it
{
expect
(
subject
.
size
).
to
eq
(
10
)
}
context
'when limiting is disabled'
do
...
...
@@ -183,6 +211,12 @@ describe Gitlab::Git::DiffCollection, :seed_helper do
subject
{
super
().
real_size
}
it
{
is_expected
.
to
eq
(
'11'
)
}
end
describe
'#line_count'
do
subject
{
super
().
line_count
}
it
{
is_expected
.
to
eq
file_count
*
line_count
}
end
it
{
expect
(
subject
.
size
).
to
eq
(
11
)
}
end
end
...
...
@@ -204,6 +238,12 @@ describe Gitlab::Git::DiffCollection, :seed_helper do
subject
{
super
().
real_size
}
it
{
is_expected
.
to
eq
(
'3+'
)
}
end
describe
'#line_count'
do
subject
{
super
().
line_count
}
it
{
is_expected
.
to
eq
120
}
end
it
{
expect
(
subject
.
size
).
to
eq
(
3
)
}
context
'when limiting is disabled'
do
...
...
@@ -223,6 +263,12 @@ describe Gitlab::Git::DiffCollection, :seed_helper do
subject
{
super
().
real_size
}
it
{
is_expected
.
to
eq
(
'11'
)
}
end
describe
'#line_count'
do
subject
{
super
().
line_count
}
it
{
is_expected
.
to
eq
file_count
*
line_count
}
end
it
{
expect
(
subject
.
size
).
to
eq
(
11
)
}
end
end
...
...
@@ -248,6 +294,12 @@ describe Gitlab::Git::DiffCollection, :seed_helper do
subject
{
super
().
real_size
}
it
{
is_expected
.
to
eq
(
'10'
)
}
end
describe
'#line_count'
do
subject
{
super
().
line_count
}
it
{
is_expected
.
to
eq
file_count
*
line_count
}
end
it
{
expect
(
subject
.
size
).
to
eq
(
10
)
}
end
end
...
...
@@ -270,6 +322,12 @@ describe Gitlab::Git::DiffCollection, :seed_helper do
subject
{
super
().
real_size
}
it
{
is_expected
.
to
eq
(
'9+'
)
}
end
describe
'#line_count'
do
subject
{
super
().
line_count
}
it
{
is_expected
.
to
eq
file_count
*
line_count
}
end
it
{
expect
(
subject
.
size
).
to
eq
(
9
)
}
context
'when limiting is disabled'
do
...
...
@@ -289,6 +347,12 @@ describe Gitlab::Git::DiffCollection, :seed_helper do
subject
{
super
().
real_size
}
it
{
is_expected
.
to
eq
(
'10'
)
}
end
describe
'#line_count'
do
subject
{
super
().
line_count
}
it
{
is_expected
.
to
eq
file_count
*
line_count
}
end
it
{
expect
(
subject
.
size
).
to
eq
(
10
)
}
end
end
...
...
@@ -316,6 +380,11 @@ describe Gitlab::Git::DiffCollection, :seed_helper do
subject
{
super
().
real_size
}
it
{
is_expected
.
to
eq
(
'0'
)}
end
describe
'#line_count'
do
subject
{
super
().
line_count
}
it
{
is_expected
.
to
eq
0
}
end
end
describe
'#each'
do
...
...
spec/models/merge_request/metrics_spec.rb
View file @
f089a230
...
...
@@ -3,8 +3,6 @@
require
'spec_helper'
describe
MergeRequest
::
Metrics
do
subject
{
described_class
.
new
}
describe
'associations'
do
it
{
is_expected
.
to
belong_to
(
:merge_request
)
}
it
{
is_expected
.
to
belong_to
(
:latest_closed_by
).
class_name
(
'User'
)
}
...
...
spec/models/merge_request_diff_spec.rb
View file @
f089a230
...
...
@@ -400,6 +400,18 @@ describe MergeRequestDiff do
end
end
describe
'#first_commit'
do
it
'returns first commit'
do
expect
(
diff_with_commits
.
first_commit
.
sha
).
to
eq
(
diff_with_commits
.
merge_request_diff_commits
.
last
.
sha
)
end
end
describe
'#last_commit'
do
it
'returns last commit'
do
expect
(
diff_with_commits
.
last_commit
.
sha
).
to
eq
(
diff_with_commits
.
merge_request_diff_commits
.
first
.
sha
)
end
end
describe
'#commits_by_shas'
do
let
(
:commit_shas
)
{
diff_with_commits
.
commit_shas
}
...
...
@@ -489,7 +501,7 @@ describe MergeRequestDiff do
subject
{
diff_with_commits
}
it
'returns sum of all changed lines count in diff files'
do
expect
(
subject
.
lines_count
).
to
eq
1
0
9
expect
(
subject
.
lines_count
).
to
eq
1
8
9
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