Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
ffc3b98c
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,发现更多精彩内容 >>
提交
ffc3b98c
编写于
12月 07, 2018
作者:
F
Felipe Artur
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[CE] - Add milestones autocomplete for epics
CE backport of
https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/8632
上级
420328d7
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
88 addition
and
25 deletion
+88
-25
lib/banzai/filter/milestone_reference_filter.rb
lib/banzai/filter/milestone_reference_filter.rb
+50
-16
spec/lib/banzai/filter/milestone_reference_filter_spec.rb
spec/lib/banzai/filter/milestone_reference_filter_spec.rb
+38
-9
未找到文件。
lib/banzai/filter/milestone_reference_filter.rb
浏览文件 @
ffc3b98c
...
@@ -4,6 +4,8 @@ module Banzai
...
@@ -4,6 +4,8 @@ module Banzai
module
Filter
module
Filter
# HTML filter that replaces milestone references with links.
# HTML filter that replaces milestone references with links.
class
MilestoneReferenceFilter
<
AbstractReferenceFilter
class
MilestoneReferenceFilter
<
AbstractReferenceFilter
include
Gitlab
::
Utils
::
StrongMemoize
self
.
reference_type
=
:milestone
self
.
reference_type
=
:milestone
def
self
.
object_class
def
self
.
object_class
...
@@ -13,16 +15,34 @@ module Banzai
...
@@ -13,16 +15,34 @@ module Banzai
# Links to project milestones contain the IID, but when we're handling
# Links to project milestones contain the IID, but when we're handling
# 'regular' references, we need to use the global ID to disambiguate
# 'regular' references, we need to use the global ID to disambiguate
# between group and project milestones.
# between group and project milestones.
def
find_object
(
p
rojec
t
,
id
)
def
find_object
(
p
aren
t
,
id
)
return
unless
project
.
is_a?
(
Projec
t
)
return
unless
valid_context?
(
paren
t
)
find_milestone_with_finder
(
p
rojec
t
,
id:
id
)
find_milestone_with_finder
(
p
aren
t
,
id:
id
)
end
end
def
find_object_from_link
(
project
,
iid
)
def
find_object_from_link
(
parent
,
iid
)
return
unless
project
.
is_a?
(
Project
)
return
unless
valid_context?
(
parent
)
find_milestone_with_finder
(
parent
,
iid:
iid
)
end
def
valid_context?
(
parent
)
strong_memoize
(
:valid_context
)
do
group_context?
(
parent
)
||
project_context?
(
parent
)
end
end
def
group_context?
(
parent
)
strong_memoize
(
:group_context
)
do
parent
.
is_a?
(
Group
)
end
end
find_milestone_with_finder
(
project
,
iid:
iid
)
def
project_context?
(
parent
)
strong_memoize
(
:project_context
)
do
parent
.
is_a?
(
Project
)
end
end
end
def
references_in
(
text
,
pattern
=
Milestone
.
reference_pattern
)
def
references_in
(
text
,
pattern
=
Milestone
.
reference_pattern
)
...
@@ -44,13 +64,15 @@ module Banzai
...
@@ -44,13 +64,15 @@ module Banzai
def
find_milestone
(
project_ref
,
namespace_ref
,
milestone_id
,
milestone_name
)
def
find_milestone
(
project_ref
,
namespace_ref
,
milestone_id
,
milestone_name
)
project_path
=
full_project_path
(
namespace_ref
,
project_ref
)
project_path
=
full_project_path
(
namespace_ref
,
project_ref
)
project
=
parent_from_ref
(
project_path
)
return
unless
project
&&
project
.
is_a?
(
Project
)
# Returns group if project is not found by path
parent
=
parent_from_ref
(
project_path
)
return
unless
parent
milestone_params
=
milestone_params
(
milestone_id
,
milestone_name
)
milestone_params
=
milestone_params
(
milestone_id
,
milestone_name
)
find_milestone_with_finder
(
p
rojec
t
,
milestone_params
)
find_milestone_with_finder
(
p
aren
t
,
milestone_params
)
end
end
def
milestone_params
(
iid
,
name
)
def
milestone_params
(
iid
,
name
)
...
@@ -61,16 +83,28 @@ module Banzai
...
@@ -61,16 +83,28 @@ module Banzai
end
end
end
end
def
find_milestone_with_finder
(
project
,
params
)
def
find_milestone_with_finder
(
parent
,
params
)
finder_params
=
{
project_ids:
[
project
.
id
],
order:
nil
,
state:
'all'
}
finder_params
=
milestone_finder_params
(
parent
,
params
[
:iid
].
present?
)
MilestonesFinder
.
new
(
finder_params
).
find_by
(
params
)
end
# We don't support IID lookups for group milestones, because IIDs can
def
milestone_finder_params
(
parent
,
find_by_iid
)
# clash between group and project milestones.
{
order:
nil
,
state:
'all'
}.
tap
do
|
params
|
if
project
.
group
&&
!
params
[
:iid
]
params
[
:project_ids
]
=
parent
.
id
if
project_context?
(
parent
)
finder_params
[
:group_ids
]
=
project
.
group
.
self_and_ancestors_ids
# We don't support IID lookups because IIDs can clash between
# group/project milestones and group/subgroup milestones.
params
[
:group_ids
]
=
self_and_ancestors_ids
(
parent
)
unless
find_by_iid
end
end
end
MilestonesFinder
.
new
(
finder_params
).
find_by
(
params
)
def
self_and_ancestors_ids
(
parent
)
if
group_context?
(
parent
)
parent
.
self_and_ancestors_ids
elsif
project_context?
(
parent
)
parent
.
group
&
.
self_and_ancestors_ids
end
end
end
def
url_for_object
(
milestone
,
project
)
def
url_for_object
(
milestone
,
project
)
...
...
spec/lib/banzai/filter/milestone_reference_filter_spec.rb
浏览文件 @
ffc3b98c
...
@@ -351,21 +351,50 @@ describe Banzai::Filter::MilestoneReferenceFilter do
...
@@ -351,21 +351,50 @@ describe Banzai::Filter::MilestoneReferenceFilter do
end
end
context
'group context'
do
context
'group context'
do
let
(
:
context
)
{
{
project:
nil
,
group:
create
(
:group
)
}
}
let
(
:
group
)
{
create
(
:group
)
}
let
(
:
milestone
)
{
create
(
:milestone
,
project:
project
)
}
let
(
:
context
)
{
{
project:
nil
,
group:
group
}
}
it
'links to a valid referenc
e'
do
context
'when project mileston
e'
do
reference
=
"
#{
project
.
full_path
}
%
#{
milestone
.
iid
}
"
let
(
:milestone
)
{
create
(
:milestone
,
project:
project
)
}
result
=
reference_filter
(
"See
#{
reference
}
"
,
context
)
it
'links to a valid reference'
do
reference
=
"
#{
project
.
full_path
}
%
#{
milestone
.
iid
}
"
expect
(
result
.
css
(
'a'
).
first
.
attr
(
'href'
)).
to
eq
(
urls
.
milestone_url
(
milestone
))
result
=
reference_filter
(
"See
#{
reference
}
"
,
context
)
expect
(
result
.
css
(
'a'
).
first
.
attr
(
'href'
)).
to
eq
(
urls
.
milestone_url
(
milestone
))
end
it
'ignores internal references'
do
exp
=
act
=
"See %
#{
milestone
.
iid
}
"
expect
(
reference_filter
(
act
,
context
).
to_html
).
to
eq
exp
end
end
end
it
'ignores internal references
'
do
context
'when group milestone
'
do
exp
=
act
=
"See %
#{
milestone
.
iid
}
"
let
(
:group_milestone
)
{
create
(
:milestone
,
title:
'group_milestone'
,
group:
group
)
}
expect
(
reference_filter
(
act
,
context
).
to_html
).
to
eq
exp
context
'for subgroups'
,
:nested_groups
do
let
(
:sub_group
)
{
create
(
:group
,
parent:
group
)
}
let
(
:sub_group_milestone
)
{
create
(
:milestone
,
title:
'sub_group_milestone'
,
group:
sub_group
)
}
it
'links to a valid reference of subgroup and group milestones'
do
[
group_milestone
,
sub_group_milestone
].
each
do
|
milestone
|
reference
=
"%
#{
milestone
.
title
}
"
result
=
reference_filter
(
"See
#{
reference
}
"
,
{
project:
nil
,
group:
sub_group
})
expect
(
result
.
css
(
'a'
).
first
.
attr
(
'href'
)).
to
eq
(
urls
.
milestone_url
(
milestone
))
end
end
end
it
'ignores internal references'
do
exp
=
act
=
"See %
#{
group_milestone
.
iid
}
"
expect
(
reference_filter
(
act
,
context
).
to_html
).
to
eq
exp
end
end
end
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录