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
50eae640
Commit
50eae640
authored
Apr 06, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix specs and make tweaks
parent
f47b7374
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
50 additions
and
39 deletions
+50
-39
app/controllers/projects/merge_requests_controller.rb
app/controllers/projects/merge_requests_controller.rb
+35
-30
app/helpers/notes_helper.rb
app/helpers/notes_helper.rb
+2
-0
app/models/merge_request.rb
app/models/merge_request.rb
+1
-1
app/models/merge_request_diff.rb
app/models/merge_request_diff.rb
+4
-1
app/views/discussions/_discussion.html.haml
app/views/discussions/_discussion.html.haml
+5
-4
app/views/projects/merge_requests/show/_versions.html.haml
app/views/projects/merge_requests/show/_versions.html.haml
+1
-1
spec/features/merge_requests/merge_request_versions_spec.rb
spec/features/merge_requests/merge_request_versions_spec.rb
+2
-2
No files found.
app/controllers/projects/merge_requests_controller.rb
View file @
50eae640
...
@@ -100,39 +100,11 @@ class Projects::MergeRequestsController < Projects::ApplicationController
...
@@ -100,39 +100,11 @@ class Projects::MergeRequestsController < Projects::ApplicationController
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
html
{
define_discussion_vars
}
format
.
html
{
define_discussion_vars
}
format
.
json
do
format
.
json
do
@merge_request_diff
=
define_diff_vars
if
params
[
:diff_id
]
@merge_request
.
merge_request_diffs
.
viewable
.
find
(
params
[
:diff_id
])
else
@merge_request
.
merge_request_diff
end
define_diff_comment_vars
define_diff_comment_vars
@merge_request_diffs
=
@merge_request
.
merge_request_diffs
.
viewable
.
select_without_diff
@comparable_diffs
=
@merge_request_diffs
.
select
{
|
diff
|
diff
.
id
<
@merge_request_diff
.
id
}
if
params
[
:start_sha
].
present?
@start_sha
=
params
[
:start_sha
]
@start_version
=
@comparable_diffs
.
find
{
|
diff
|
diff
.
head_commit_sha
==
@start_sha
}
unless
@start_version
@start_sha
=
@merge_request_diff
.
head_commit_sha
@start_version
=
@merge_request_diff
end
end
@environment
=
@merge_request
.
environments_for
(
current_user
).
last
@environment
=
@merge_request
.
environments_for
(
current_user
).
last
@diff_notes_disabled
=
!
@merge_request_diff
.
latest?
||
@start_sha
@diffs
=
if
@start_sha
@merge_request_diff
.
compare_with
(
@start_sha
).
diffs
(
diff_options
)
else
@merge_request_diff
.
diffs
(
diff_options
)
end
render
json:
{
html:
view_to_html_string
(
"projects/merge_requests/show/_diffs"
)
}
render
json:
{
html:
view_to_html_string
(
"projects/merge_requests/show/_diffs"
)
}
end
end
end
end
...
@@ -144,16 +116,18 @@ class Projects::MergeRequestsController < Projects::ApplicationController
...
@@ -144,16 +116,18 @@ class Projects::MergeRequestsController < Projects::ApplicationController
def
diff_for_path
def
diff_for_path
if
params
[
:id
]
if
params
[
:id
]
merge_request
merge_request
define_diff_vars
define_diff_comment_vars
define_diff_comment_vars
else
else
build_merge_request
build_merge_request
@diffs
=
@merge_request
.
diffs
(
diff_options
)
@diff_notes_disabled
=
true
@diff_notes_disabled
=
true
@grouped_diff_discussions
=
{}
@grouped_diff_discussions
=
{}
end
end
define_commit_vars
define_commit_vars
render_diff_for_path
(
@
merge_request
.
diffs
(
diff_options
)
)
render_diff_for_path
(
@
diffs
)
end
end
def
commits
def
commits
...
@@ -590,12 +564,43 @@ class Projects::MergeRequestsController < Projects::ApplicationController
...
@@ -590,12 +564,43 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@base_commit
=
@merge_request
.
diff_base_commit
||
@merge_request
.
likely_diff_base_commit
@base_commit
=
@merge_request
.
diff_base_commit
||
@merge_request
.
likely_diff_base_commit
end
end
def
define_diff_vars
@merge_request_diff
=
if
params
[
:diff_id
]
@merge_request
.
merge_request_diffs
.
viewable
.
find
(
params
[
:diff_id
])
else
@merge_request
.
merge_request_diff
end
@merge_request_diffs
=
@merge_request
.
merge_request_diffs
.
viewable
.
select_without_diff
@comparable_diffs
=
@merge_request_diffs
.
select
{
|
diff
|
diff
.
id
<
@merge_request_diff
.
id
}
if
params
[
:start_sha
].
present?
@start_sha
=
params
[
:start_sha
]
@start_version
=
@comparable_diffs
.
find
{
|
diff
|
diff
.
head_commit_sha
==
@start_sha
}
unless
@start_version
@start_sha
=
@merge_request_diff
.
head_commit_sha
@start_version
=
@merge_request_diff
end
end
@diffs
=
if
@start_sha
@merge_request_diff
.
compare_with
(
@start_sha
).
diffs
(
diff_options
)
else
@merge_request_diff
.
diffs
(
diff_options
)
end
end
def
define_diff_comment_vars
def
define_diff_comment_vars
@new_diff_note_attrs
=
{
@new_diff_note_attrs
=
{
noteable_type:
'MergeRequest'
,
noteable_type:
'MergeRequest'
,
noteable_id:
@merge_request
.
id
noteable_id:
@merge_request
.
id
}
}
@diff_notes_disabled
=
!
@merge_request_diff
.
latest?
||
@start_sha
@use_legacy_diff_notes
=
!
@merge_request
.
has_complete_diff_refs?
@use_legacy_diff_notes
=
!
@merge_request
.
has_complete_diff_refs?
@grouped_diff_discussions
=
@merge_request
.
grouped_diff_discussions
(
@merge_request_diff
.
diff_refs
)
@grouped_diff_discussions
=
@merge_request
.
grouped_diff_discussions
(
@merge_request_diff
.
diff_refs
)
...
...
app/helpers/notes_helper.rb
View file @
50eae640
...
@@ -68,6 +68,8 @@ module NotesHelper
...
@@ -68,6 +68,8 @@ module NotesHelper
elsif
merge_request_diff
=
discussion
.
latest_merge_request_diff
elsif
merge_request_diff
=
discussion
.
latest_merge_request_diff
diff_id
=
merge_request_diff
.
id
diff_id
=
merge_request_diff
.
id
else
else
# If the discussion is not active, and we cannot find the latest
# merge request diff for this discussion, we return no path at all.
return
return
end
end
...
...
app/models/merge_request.rb
View file @
50eae640
...
@@ -369,7 +369,7 @@ class MergeRequest < ActiveRecord::Base
...
@@ -369,7 +369,7 @@ class MergeRequest < ActiveRecord::Base
def
merge_request_diff_for
(
diff_refs
)
def
merge_request_diff_for
(
diff_refs
)
@merge_request_diffs_by_diff_refs
||=
Hash
.
new
do
|
h
,
diff_refs
|
@merge_request_diffs_by_diff_refs
||=
Hash
.
new
do
|
h
,
diff_refs
|
h
[
diff_refs
]
=
merge_request_diffs
.
viewable
.
select_without_diff
.
with_diff_refs
(
diff_refs
).
take
h
[
diff_refs
]
=
merge_request_diffs
.
viewable
.
select_without_diff
.
find_by_diff_refs
(
diff_refs
)
end
end
@merge_request_diffs_by_diff_refs
[
diff_refs
]
@merge_request_diffs_by_diff_refs
[
diff_refs
]
...
...
app/models/merge_request_diff.rb
View file @
50eae640
...
@@ -26,12 +26,15 @@ class MergeRequestDiff < ActiveRecord::Base
...
@@ -26,12 +26,15 @@ class MergeRequestDiff < ActiveRecord::Base
end
end
scope
:viewable
,
->
{
without_state
(
:empty
)
}
scope
:viewable
,
->
{
without_state
(
:empty
)
}
scope
:with_diff_refs
,
->
(
diff_refs
)
{
where
(
start_commit_sha:
diff_refs
.
start_sha
,
head_commit_sha:
diff_refs
.
head_sha
,
base_commit_sha:
diff_refs
.
base_sha
)
}
# All diff information is collected from repository after object is created.
# All diff information is collected from repository after object is created.
# It allows you to override variables like head_commit_sha before getting diff.
# It allows you to override variables like head_commit_sha before getting diff.
after_create
:save_git_content
,
unless: :importing?
after_create
:save_git_content
,
unless: :importing?
def
self
.
find_by_diff_refs
(
diff_refs
)
where
(
start_commit_sha:
diff_refs
.
start_sha
,
head_commit_sha:
diff_refs
.
head_sha
,
base_commit_sha:
diff_refs
.
base_sha
)
end
def
self
.
select_without_diff
def
self
.
select_without_diff
select
(
column_names
-
[
'st_diffs'
])
select
(
column_names
-
[
'st_diffs'
])
end
end
...
...
app/views/discussions/_discussion.html.haml
View file @
50eae640
...
@@ -26,14 +26,15 @@
...
@@ -26,14 +26,15 @@
-
commit
=
discussion
.
noteable
-
commit
=
discussion
.
noteable
-
if
commit
-
if
commit
commit
commit
=
link_to
commit
.
short_id
,
discussion_diff_path
(
discussion
)
,
class:
'monospace'
=
link_to
commit
.
short_id
,
url
,
class:
'monospace'
-
else
-
else
a deleted commit
a deleted commit
-
else
-
else
-
unless
discussion
.
active?
a now outdated portion of
=
conditional_link_to
url
.
present?
,
url
do
=
conditional_link_to
url
.
present?
,
url
do
-
if
discussion
.
active?
the diff
the diff
-
else
an outdated diff
=
time_ago_with_tooltip
(
discussion
.
created_at
,
placement:
"bottom"
,
html_class:
"note-created-ago"
)
=
time_ago_with_tooltip
(
discussion
.
created_at
,
placement:
"bottom"
,
html_class:
"note-created-ago"
)
=
render
"discussions/headline"
,
discussion:
discussion
=
render
"discussions/headline"
,
discussion:
discussion
...
...
app/views/projects/merge_requests/show/_versions.html.haml
View file @
50eae640
...
@@ -80,7 +80,7 @@
...
@@ -80,7 +80,7 @@
-
if
@start_sha
-
if
@start_sha
Comment creation is disabled because you're comparing two versions of this merge request.
Comment creation is disabled because you're comparing two versions of this merge request.
-
else
-
else
Discussions on this old version of the merge request are displayed but comment creation
has been
disabled.
Discussions on this old version of the merge request are displayed but comment creation
is
disabled.
.pull-right
.pull-right
=
link_to
'Show latest version'
,
diffs_namespace_project_merge_request_path
(
@project
.
namespace
,
@project
,
@merge_request
),
class:
'btn btn-sm'
=
link_to
'Show latest version'
,
diffs_namespace_project_merge_request_path
(
@project
.
namespace
,
@project
,
@merge_request
),
class:
'btn btn-sm'
spec/features/merge_requests/merge_request_versions_spec.rb
View file @
50eae640
...
@@ -37,7 +37,7 @@ feature 'Merge Request versions', js: true, feature: true do
...
@@ -37,7 +37,7 @@ feature 'Merge Request versions', js: true, feature: true do
end
end
it
'show the message about disabled comments'
do
it
'show the message about disabled comments'
do
expect
(
page
).
to
have_content
'
Comments are
disabled'
expect
(
page
).
to
have_content
'
comment creation is
disabled'
end
end
end
end
...
@@ -66,7 +66,7 @@ feature 'Merge Request versions', js: true, feature: true do
...
@@ -66,7 +66,7 @@ feature 'Merge Request versions', js: true, feature: true do
end
end
it
'show the message about disabled comments'
do
it
'show the message about disabled comments'
do
expect
(
page
).
to
have_content
'Comment
s are
disabled'
expect
(
page
).
to
have_content
'Comment
creation is
disabled'
end
end
it
'show diff between new and old version'
do
it
'show diff between new and old version'
do
...
...
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