Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
89a67601
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
89a67601
编写于
12月 04, 2018
作者:
O
Oswaldo Ferreira
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Avoid 500's when serializing legacy diff notes
上级
e9e3820c
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
70 addition
and
15 deletion
+70
-15
app/controllers/projects/merge_requests/diffs_controller.rb
app/controllers/projects/merge_requests/diffs_controller.rb
+2
-5
changelogs/unreleased/osw-fix-grouping-by-file-path.yml
changelogs/unreleased/osw-fix-grouping-by-file-path.yml
+5
-0
lib/gitlab/diff/file_collection/base.rb
lib/gitlab/diff/file_collection/base.rb
+10
-0
lib/gitlab/diff/file_collection/compare.rb
lib/gitlab/diff/file_collection/compare.rb
+4
-0
spec/controllers/projects/merge_requests/diffs_controller_spec.rb
...trollers/projects/merge_requests/diffs_controller_spec.rb
+12
-0
spec/lib/gitlab/diff/file_collection/commit_spec.rb
spec/lib/gitlab/diff/file_collection/commit_spec.rb
+4
-0
spec/lib/gitlab/diff/file_collection/merge_request_diff_spec.rb
...ib/gitlab/diff/file_collection/merge_request_diff_spec.rb
+17
-10
spec/support/shared_examples/diff_file_collections.rb
spec/support/shared_examples/diff_file_collections.rb
+16
-0
未找到文件。
app/controllers/projects/merge_requests/diffs_controller.rb
浏览文件 @
89a67601
...
...
@@ -22,12 +22,9 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic
def
render_diffs
@environment
=
@merge_request
.
environments_for
(
current_user
).
last
notes_grouped_by_path
=
renderable_notes
.
group_by
{
|
note
|
note
.
position
.
file_path
}
@diffs
.
diff_files
.
each
do
|
diff_file
|
notes
=
notes_grouped_by_path
.
fetch
(
diff_file
.
file_path
,
[])
notes
.
each
{
|
note
|
diff_file
.
unfold_diff_lines
(
note
.
position
)
}
end
note_positions
=
renderable_notes
.
map
(
&
:position
).
compact
@diffs
.
unfold_diff_files
(
note_positions
)
@diffs
.
write_cache
...
...
changelogs/unreleased/osw-fix-grouping-by-file-path.yml
0 → 100644
浏览文件 @
89a67601
---
title
:
Avoid 500's when serializing legacy diff notes
merge_request
:
23544
author
:
type
:
fixed
lib/gitlab/diff/file_collection/base.rb
浏览文件 @
89a67601
...
...
@@ -34,6 +34,16 @@ module Gitlab
@diff_files
||=
diffs
.
decorate!
{
|
diff
|
decorate_diff!
(
diff
)
}
end
# This mutates `diff_files` lines.
def
unfold_diff_files
(
positions
)
positions_grouped_by_path
=
positions
.
group_by
{
|
position
|
position
.
file_path
}
diff_files
.
each
do
|
diff_file
|
positions
=
positions_grouped_by_path
.
fetch
(
diff_file
.
file_path
,
[])
positions
.
each
{
|
position
|
diff_file
.
unfold_diff_lines
(
position
)
}
end
end
def
diff_file_with_old_path
(
old_path
)
diff_files
.
find
{
|
diff_file
|
diff_file
.
old_path
==
old_path
}
end
...
...
lib/gitlab/diff/file_collection/compare.rb
浏览文件 @
89a67601
...
...
@@ -10,6 +10,10 @@ module Gitlab
diff_options:
diff_options
,
diff_refs:
diff_refs
)
end
def
unfold_diff_lines
(
positions
)
# no-op
end
end
end
end
...
...
spec/controllers/projects/merge_requests/diffs_controller_spec.rb
浏览文件 @
89a67601
...
...
@@ -36,6 +36,18 @@ describe Projects::MergeRequests::DiffsController do
end
end
context
'when note has no position'
do
before
do
create
(
:legacy_diff_note_on_merge_request
,
project:
project
,
noteable:
merge_request
,
position:
nil
)
end
it
'serializes merge request diff collection'
do
expect_any_instance_of
(
DiffsSerializer
).
to
receive
(
:represent
).
with
(
an_instance_of
(
Gitlab
::
Diff
::
FileCollection
::
MergeRequestDiff
),
an_instance_of
(
Hash
))
go
end
end
context
'with forked projects with submodules'
do
render_views
...
...
spec/lib/gitlab/diff/file_collection/commit_spec.rb
浏览文件 @
89a67601
...
...
@@ -12,4 +12,8 @@ describe Gitlab::Diff::FileCollection::Commit do
let
(
:diffable
)
{
project
.
commit
}
let
(
:stub_path
)
{
'bar/branch-test.txt'
}
end
it_behaves_like
'unfoldable diff'
do
let
(
:diffable
)
{
project
.
commit
}
end
end
spec/lib/gitlab/diff/file_collection/merge_request_diff_spec.rb
浏览文件 @
89a67601
...
...
@@ -2,22 +2,29 @@ require 'spec_helper'
describe
Gitlab
::
Diff
::
FileCollection
::
MergeRequestDiff
do
let
(
:merge_request
)
{
create
(
:merge_request
)
}
let
(
:diff_files
)
{
described_class
.
new
(
merge_request
.
merge_request_diff
,
diff_options:
nil
).
diff_files
}
let
(
:subject
)
{
described_class
.
new
(
merge_request
.
merge_request_diff
,
diff_options:
nil
)
}
let
(
:diff_files
)
{
subject
.
diff_files
}
it
'does not highlight binary files'
do
allow_any_instance_of
(
Gitlab
::
Diff
::
File
).
to
receive
(
:text?
).
and_return
(
false
)
describe
'#diff_files'
do
it
'does not highlight binary files'
do
allow_any_instance_of
(
Gitlab
::
Diff
::
File
).
to
receive
(
:text?
).
and_return
(
false
)
expect_any_instance_of
(
Gitlab
::
Diff
::
File
).
not_to
receive
(
:highlighted_diff_lines
)
expect_any_instance_of
(
Gitlab
::
Diff
::
File
).
not_to
receive
(
:highlighted_diff_lines
)
diff_files
end
diff_files
end
it
'does not highlight files marked as undiffable in .gitattributes'
do
allow_any_instance_of
(
Gitlab
::
Diff
::
File
).
to
receive
(
:diffable?
).
and_return
(
false
)
it
'does not highlight files marked as undiffable in .gitattributes'
do
allow_any_instance_of
(
Gitlab
::
Diff
::
File
).
to
receive
(
:diffable?
).
and_return
(
false
)
expect_any_instance_of
(
Gitlab
::
Diff
::
File
).
not_to
receive
(
:highlighted_diff_lines
)
expect_any_instance_of
(
Gitlab
::
Diff
::
File
).
not_to
receive
(
:highlighted_diff_lines
)
diff_files
end
end
diff_files
it_behaves_like
'unfoldable diff'
do
let
(
:diffable
)
{
merge_request
.
merge_request_diff
}
end
it
'it uses a different cache key if diff line keys change'
do
...
...
spec/support/shared_examples/diff_file_collections.rb
浏览文件 @
89a67601
...
...
@@ -45,3 +45,19 @@ shared_examples 'diff statistics' do |test_include_stats_flag: true|
end
end
end
shared_examples
'unfoldable diff'
do
let
(
:subject
)
{
described_class
.
new
(
diffable
,
diff_options:
nil
)
}
it
'calls Gitlab::Diff::File#unfold_diff_lines with correct position'
do
position
=
instance_double
(
Gitlab
::
Diff
::
Position
,
file_path:
'README'
)
readme_file
=
instance_double
(
Gitlab
::
Diff
::
File
,
file_path:
'README'
)
other_file
=
instance_double
(
Gitlab
::
Diff
::
File
,
file_path:
'foo.rb'
)
nil_path_file
=
instance_double
(
Gitlab
::
Diff
::
File
,
file_path:
nil
)
allow
(
subject
).
to
receive
(
:diff_files
)
{
[
readme_file
,
other_file
,
nil_path_file
]
}
expect
(
readme_file
).
to
receive
(
:unfold_diff_lines
).
with
(
position
)
subject
.
unfold_diff_files
([
position
])
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录