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
67b579c5
Commit
67b579c5
authored
Oct 25, 2018
by
Mark Chao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow getting all paths (old & new) involved in MR
Fetch database columns directly if available
parent
e48ce632
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
110 additions
and
0 deletions
+110
-0
app/models/compare.rb
app/models/compare.rb
+11
-0
app/models/merge_request.rb
app/models/merge_request.rb
+12
-0
app/models/merge_request_diff.rb
app/models/merge_request_diff.rb
+7
-0
spec/models/compare_spec.rb
spec/models/compare_spec.rb
+29
-0
spec/models/merge_request_diff_spec.rb
spec/models/merge_request_diff_spec.rb
+13
-0
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+38
-0
No files found.
app/models/compare.rb
View file @
67b579c5
# frozen_string_literal: true
# frozen_string_literal: true
require
'set'
class
Compare
class
Compare
include
Gitlab
::
Utils
::
StrongMemoize
include
Gitlab
::
Utils
::
StrongMemoize
...
@@ -77,4 +79,13 @@ class Compare
...
@@ -77,4 +79,13 @@ class Compare
head_sha:
head_commit_sha
head_sha:
head_commit_sha
)
)
end
end
def
modified_paths
paths
=
Set
.
new
diffs
.
diff_files
.
each
do
|
diff
|
paths
.
add
diff
.
old_path
paths
.
add
diff
.
new_path
end
paths
.
to_a
end
end
end
app/models/merge_request.rb
View file @
67b579c5
...
@@ -409,6 +409,18 @@ class MergeRequest < ActiveRecord::Base
...
@@ -409,6 +409,18 @@ class MergeRequest < ActiveRecord::Base
merge_request_diff
&
.
real_size
||
diffs
.
real_size
merge_request_diff
&
.
real_size
||
diffs
.
real_size
end
end
def
modified_paths
(
past_merge_request_diff:
nil
)
diffs
=
if
past_merge_request_diff
past_merge_request_diff
elsif
compare
compare
else
self
.
merge_request_diff
end
diffs
.
modified_paths
end
def
diff_base_commit
def
diff_base_commit
if
persisted?
if
persisted?
merge_request_diff
.
base_commit
merge_request_diff
.
base_commit
...
...
app/models/merge_request_diff.rb
View file @
67b579c5
...
@@ -6,6 +6,7 @@ class MergeRequestDiff < ActiveRecord::Base
...
@@ -6,6 +6,7 @@ class MergeRequestDiff < ActiveRecord::Base
include
ManualInverseAssociation
include
ManualInverseAssociation
include
IgnorableColumn
include
IgnorableColumn
include
EachBatch
include
EachBatch
include
Gitlab
::
Utils
::
StrongMemoize
# Don't display more than 100 commits at once
# Don't display more than 100 commits at once
COMMITS_SAFE_SIZE
=
100
COMMITS_SAFE_SIZE
=
100
...
@@ -234,6 +235,12 @@ class MergeRequestDiff < ActiveRecord::Base
...
@@ -234,6 +235,12 @@ class MergeRequestDiff < ActiveRecord::Base
end
end
# rubocop: enable CodeReuse/ServiceClass
# rubocop: enable CodeReuse/ServiceClass
def
modified_paths
strong_memoize
(
:modified_paths
)
do
merge_request_diff_files
.
pluck
(
:new_path
,
:old_path
).
flatten
.
uniq
end
end
private
private
def
create_merge_request_diff_files
(
diffs
)
def
create_merge_request_diff_files
(
diffs
)
...
...
spec/models/compare_spec.rb
View file @
67b579c5
...
@@ -92,4 +92,33 @@ describe Compare do
...
@@ -92,4 +92,33 @@ describe Compare do
expect
(
subject
.
diff_refs
.
head_sha
).
to
eq
(
head_commit
.
id
)
expect
(
subject
.
diff_refs
.
head_sha
).
to
eq
(
head_commit
.
id
)
end
end
end
end
describe
'#modified_paths'
do
context
'changes are present'
do
let
(
:raw_compare
)
do
Gitlab
::
Git
::
Compare
.
new
(
project
.
repository
.
raw_repository
,
'before-create-delete-modify-move'
,
'after-create-delete-modify-move'
)
end
it
'returns affected file paths, without duplication'
do
expect
(
subject
.
modified_paths
).
to
contain_exactly
(
*
%w{
foo/for_move.txt
foo/bar/for_move.txt
foo/for_create.txt
foo/for_delete.txt
foo/for_edit.txt
}
)
end
end
context
'changes are absent'
do
let
(
:start_commit
)
{
sample_commit
}
let
(
:head_commit
)
{
sample_commit
}
it
'returns empty array'
do
expect
(
subject
.
modified_paths
).
to
eq
([])
end
end
end
end
end
spec/models/merge_request_diff_spec.rb
View file @
67b579c5
...
@@ -232,4 +232,17 @@ describe MergeRequestDiff do
...
@@ -232,4 +232,17 @@ describe MergeRequestDiff do
expect
(
commits
.
map
(
&
:sha
)).
to
match_array
(
commit_shas
)
expect
(
commits
.
map
(
&
:sha
)).
to
match_array
(
commit_shas
)
end
end
end
end
describe
'#modified_paths'
do
subject
do
diff
=
create
(
:merge_request_diff
)
create
(
:merge_request_diff_file
,
:new_file
,
merge_request_diff:
diff
)
create
(
:merge_request_diff_file
,
:renamed_file
,
merge_request_diff:
diff
)
diff
end
it
'returns affected file paths'
do
expect
(
subject
.
modified_paths
).
to
eq
(
%w{foo bar baz}
)
end
end
end
end
spec/models/merge_request_spec.rb
View file @
67b579c5
...
@@ -631,6 +631,44 @@ describe MergeRequest do
...
@@ -631,6 +631,44 @@ describe MergeRequest do
end
end
end
end
describe
'#modified_paths'
do
let
(
:paths
)
{
double
(
:paths
)
}
subject
(
:merge_request
)
{
build
(
:merge_request
)
}
before
do
expect
(
diff
).
to
receive
(
:modified_paths
).
and_return
(
paths
)
end
context
'when past_merge_request_diff is specified'
do
let
(
:another_diff
)
{
double
(
:merge_request_diff
)
}
let
(
:diff
)
{
another_diff
}
it
'returns affected file paths from specified past_merge_request_diff'
do
expect
(
merge_request
.
modified_paths
(
past_merge_request_diff:
another_diff
)).
to
eq
(
paths
)
end
end
context
'when compare is present'
do
let
(
:compare
)
{
double
(
:compare
)
}
let
(
:diff
)
{
compare
}
it
'returns affected file paths from compare'
do
merge_request
.
compare
=
compare
expect
(
merge_request
.
modified_paths
).
to
eq
(
paths
)
end
end
context
'when no arguments provided'
do
let
(
:diff
)
{
merge_request
.
merge_request_diff
}
subject
(
:merge_request
)
{
create
(
:merge_request
,
source_branch:
'feature'
,
target_branch:
'master'
)
}
it
'returns affected file paths for merge_request_diff'
do
expect
(
merge_request
.
modified_paths
).
to
eq
(
paths
)
end
end
end
describe
"#related_notes"
do
describe
"#related_notes"
do
let!
(
:merge_request
)
{
create
(
:merge_request
)
}
let!
(
:merge_request
)
{
create
(
:merge_request
)
}
...
...
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