Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
2cda5ec8
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,发现更多精彩内容 >>
提交
2cda5ec8
编写于
4月 02, 2018
作者:
O
Oswaldo Ferreira
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Render MR commit SHA instead "diffs" when viable
上级
38bc4acb
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
84 addition
and
5 deletion
+84
-5
changelogs/unreleased/osw-41401-render-mr-commit-sha-instead-diffs.yml
...released/osw-41401-render-mr-commit-sha-instead-diffs.yml
+5
-0
lib/banzai/filter/abstract_reference_filter.rb
lib/banzai/filter/abstract_reference_filter.rb
+2
-2
lib/banzai/filter/commit_range_reference_filter.rb
lib/banzai/filter/commit_range_reference_filter.rb
+1
-1
lib/banzai/filter/label_reference_filter.rb
lib/banzai/filter/label_reference_filter.rb
+1
-1
lib/banzai/filter/merge_request_reference_filter.rb
lib/banzai/filter/merge_request_reference_filter.rb
+39
-0
lib/banzai/filter/milestone_reference_filter.rb
lib/banzai/filter/milestone_reference_filter.rb
+1
-1
spec/lib/banzai/filter/merge_request_reference_filter_spec.rb
.../lib/banzai/filter/merge_request_reference_filter_spec.rb
+35
-0
未找到文件。
changelogs/unreleased/osw-41401-render-mr-commit-sha-instead-diffs.yml
0 → 100644
浏览文件 @
2cda5ec8
---
title
:
Render MR commit SHA instead "diffs" when viable
merge_request
:
author
:
type
:
added
lib/banzai/filter/abstract_reference_filter.rb
浏览文件 @
2cda5ec8
...
@@ -171,7 +171,7 @@ module Banzai
...
@@ -171,7 +171,7 @@ module Banzai
end
end
if
object
if
object
title
=
object_link_title
(
object
)
title
=
object_link_title
(
object
,
matches
)
klass
=
reference_class
(
object_sym
)
klass
=
reference_class
(
object_sym
)
data
=
data_attributes_for
(
link_content
||
match
,
parent
,
object
,
data
=
data_attributes_for
(
link_content
||
match
,
parent
,
object
,
...
@@ -216,7 +216,7 @@ module Banzai
...
@@ -216,7 +216,7 @@ module Banzai
extras
extras
end
end
def
object_link_title
(
object
)
def
object_link_title
(
object
,
matches
)
object
.
title
object
.
title
end
end
...
...
lib/banzai/filter/commit_range_reference_filter.rb
浏览文件 @
2cda5ec8
...
@@ -34,7 +34,7 @@ module Banzai
...
@@ -34,7 +34,7 @@ module Banzai
range
.
to_param
.
merge
(
only_path:
context
[
:only_path
]))
range
.
to_param
.
merge
(
only_path:
context
[
:only_path
]))
end
end
def
object_link_title
(
range
)
def
object_link_title
(
range
,
matches
)
nil
nil
end
end
end
end
...
...
lib/banzai/filter/label_reference_filter.rb
浏览文件 @
2cda5ec8
...
@@ -77,7 +77,7 @@ module Banzai
...
@@ -77,7 +77,7 @@ module Banzai
CGI
.
unescapeHTML
(
text
.
to_s
)
CGI
.
unescapeHTML
(
text
.
to_s
)
end
end
def
object_link_title
(
object
)
def
object_link_title
(
object
,
matches
)
# use title of wrapped element instead
# use title of wrapped element instead
nil
nil
end
end
...
...
lib/banzai/filter/merge_request_reference_filter.rb
浏览文件 @
2cda5ec8
...
@@ -17,10 +17,19 @@ module Banzai
...
@@ -17,10 +17,19 @@ module Banzai
only_path:
context
[
:only_path
])
only_path:
context
[
:only_path
])
end
end
def
object_link_title
(
object
,
matches
)
object_link_commit_title
(
object
,
matches
)
||
super
end
def
object_link_text_extras
(
object
,
matches
)
def
object_link_text_extras
(
object
,
matches
)
extras
=
super
extras
=
super
if
commit_ref
=
object_link_commit_ref
(
object
,
matches
)
return
extras
.
unshift
(
commit_ref
)
end
path
=
matches
[
:path
]
if
matches
.
names
.
include?
(
"path"
)
path
=
matches
[
:path
]
if
matches
.
names
.
include?
(
"path"
)
case
path
case
path
when
'/diffs'
when
'/diffs'
extras
.
unshift
"diffs"
extras
.
unshift
"diffs"
...
@@ -38,6 +47,36 @@ module Banzai
...
@@ -38,6 +47,36 @@ module Banzai
.
where
(
iid:
ids
.
to_a
)
.
where
(
iid:
ids
.
to_a
)
.
includes
(
target_project: :namespace
)
.
includes
(
target_project: :namespace
)
end
end
private
def
object_link_commit_title
(
object
,
matches
)
object_link_commit
(
object
,
matches
)
&
.
title
end
def
object_link_commit_ref
(
object
,
matches
)
object_link_commit
(
object
,
matches
)
&
.
short_id
end
def
object_link_commit
(
object
,
matches
)
return
unless
matches
.
names
.
include?
(
'query'
)
&&
query
=
matches
[
:query
]
# Removes leading "?". CGI.parse expects "arg1&arg2&arg3"
params
=
CGI
.
parse
(
query
.
sub
(
/^\?/
,
''
))
return
unless
commit_sha
=
params
[
'commit_id'
]
&
.
first
if
commit
=
find_commit_by_sha
(
object
,
commit_sha
)
Commit
.
from_hash
(
commit
.
to_hash
,
object
.
project
)
end
end
def
find_commit_by_sha
(
object
,
commit_sha
)
@all_commits
||=
{}
@all_commits
[
object
.
id
]
||=
object
.
all_commits
@all_commits
[
object
.
id
].
find
{
|
commit
|
commit
.
sha
==
commit_sha
}
end
end
end
end
end
end
end
lib/banzai/filter/milestone_reference_filter.rb
浏览文件 @
2cda5ec8
...
@@ -84,7 +84,7 @@ module Banzai
...
@@ -84,7 +84,7 @@ module Banzai
end
end
end
end
def
object_link_title
(
object
)
def
object_link_title
(
object
,
matches
)
nil
nil
end
end
end
end
...
...
spec/lib/banzai/filter/merge_request_reference_filter_spec.rb
浏览文件 @
2cda5ec8
...
@@ -196,6 +196,41 @@ describe Banzai::Filter::MergeRequestReferenceFilter do
...
@@ -196,6 +196,41 @@ describe Banzai::Filter::MergeRequestReferenceFilter do
end
end
end
end
context
'URL reference for a commit'
do
let
(
:mr
)
{
create
(
:merge_request
,
:with_diffs
)
}
let
(
:reference
)
do
urls
.
project_merge_request_url
(
mr
.
project
,
mr
)
+
"/diffs?commit_id=
#{
mr
.
diff_head_sha
}
"
end
let
(
:commit
)
{
mr
.
commits
.
find
{
|
commit
|
commit
.
sha
==
mr
.
diff_head_sha
}
}
it
'links to a valid reference'
do
doc
=
reference_filter
(
"See
#{
reference
}
"
)
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'href'
))
.
to
eq
reference
end
it
'has valid text'
do
doc
=
reference_filter
(
"See
#{
reference
}
"
)
expect
(
doc
.
text
).
to
eq
(
"See
#{
mr
.
to_reference
(
full:
true
)
}
(
#{
commit
.
short_id
}
)"
)
end
it
'has valid title attribute'
do
doc
=
reference_filter
(
"See
#{
reference
}
"
)
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'title'
)).
to
eq
(
commit
.
title
)
end
it
'ignores invalid commit short_ids on link text'
do
invalidate_commit_reference
=
urls
.
project_merge_request_url
(
mr
.
project
,
mr
)
+
"/diffs?commit_id=12345678"
doc
=
reference_filter
(
"See
#{
invalidate_commit_reference
}
"
)
expect
(
doc
.
text
).
to
eq
(
"See
#{
mr
.
to_reference
(
full:
true
)
}
(diffs)"
)
end
end
context
'cross-project URL reference'
do
context
'cross-project URL reference'
do
let
(
:namespace
)
{
create
(
:namespace
,
name:
'cross-reference'
)
}
let
(
:namespace
)
{
create
(
:namespace
,
name:
'cross-reference'
)
}
let
(
:project2
)
{
create
(
:project
,
:public
,
namespace:
namespace
)
}
let
(
:project2
)
{
create
(
:project
,
:public
,
namespace:
namespace
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录