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
989131c5
Commit
989131c5
authored
Dec 24, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Render milestone links as references
parent
331154ff
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
164 additions
and
18 deletions
+164
-18
app/models/milestone.rb
app/models/milestone.rb
+18
-0
lib/banzai/filter/abstract_reference_filter.rb
lib/banzai/filter/abstract_reference_filter.rb
+21
-17
lib/banzai/filter/milestone_reference_filter.rb
lib/banzai/filter/milestone_reference_filter.rb
+24
-0
lib/banzai/pipeline/gfm_pipeline.rb
lib/banzai/pipeline/gfm_pipeline.rb
+1
-0
lib/gitlab/reference_extractor.rb
lib/gitlab/reference_extractor.rb
+1
-1
spec/features/markdown_spec.rb
spec/features/markdown_spec.rb
+1
-0
spec/fixtures/markdown.md.erb
spec/fixtures/markdown.md.erb
+8
-0
spec/lib/banzai/filter/milestone_reference_filter_spec.rb
spec/lib/banzai/filter/milestone_reference_filter_spec.rb
+73
-0
spec/support/markdown_feature.rb
spec/support/markdown_feature.rb
+8
-0
spec/support/matchers/markdown_matchers.rb
spec/support/matchers/markdown_matchers.rb
+9
-0
No files found.
app/models/milestone.rb
View file @
989131c5
...
@@ -22,6 +22,7 @@ class Milestone < ActiveRecord::Base
...
@@ -22,6 +22,7 @@ class Milestone < ActiveRecord::Base
include
InternalId
include
InternalId
include
Sortable
include
Sortable
include
Referable
include
StripAttribute
include
StripAttribute
belongs_to
:project
belongs_to
:project
...
@@ -61,6 +62,23 @@ class Milestone < ActiveRecord::Base
...
@@ -61,6 +62,23 @@ class Milestone < ActiveRecord::Base
end
end
end
end
def
self
.
reference_pattern
nil
end
def
self
.
link_reference_pattern
super
(
"milestones"
,
/(?<milestone>\d+)/
)
end
def
to_reference
(
from_project
=
nil
)
h
=
Gitlab
::
Application
.
routes
.
url_helpers
h
.
namespace_project_milestone_url
(
self
.
project
.
namespace
,
self
.
project
,
self
)
end
def
reference_link_text
(
from_project
=
nil
)
%Q{<i class="fa fa-clock-o"></i> }
.
html_safe
+
self
.
title
end
def
expired?
def
expired?
if
due_date
if
due_date
due_date
.
past?
due_date
.
past?
...
...
lib/banzai/filter/abstract_reference_filter.rb
View file @
989131c5
...
@@ -60,27 +60,31 @@ module Banzai
...
@@ -60,27 +60,31 @@ module Banzai
end
end
def
call
def
call
# `#123`
if
object_class
.
reference_pattern
replace_text_nodes_matching
(
object_class
.
reference_pattern
)
do
|
content
|
# `#123`
object_link_filter
(
content
,
object_class
.
reference_pattern
)
replace_text_nodes_matching
(
object_class
.
reference_pattern
)
do
|
content
|
end
object_link_filter
(
content
,
object_class
.
reference_pattern
)
end
# `[Issue](#123)`, which is turned into
# `[Issue](#123)`, which is turned into
# `<a href="#123">Issue</a>`
# `<a href="#123">Issue</a>`
replace_link_nodes_with_href
(
object_class
.
reference_pattern
)
do
|
link
,
text
|
replace_link_nodes_with_href
(
object_class
.
reference_pattern
)
do
|
link
,
text
|
object_link_filter
(
link
,
object_class
.
reference_pattern
,
link_text:
text
)
object_link_filter
(
link
,
object_class
.
reference_pattern
,
link_text:
text
)
end
end
end
# `http://gitlab.example.com/namespace/project/issues/123`, which is turned into
if
object_class
.
link_reference_pattern
# `<a href="http://gitlab.example.com/namespace/project/issues/123">http://gitlab.example.com/namespace/project/issues/123</a>`
# `http://gitlab.example.com/namespace/project/issues/123`, which is turned into
replace_link_nodes_with_text
(
object_class
.
link_reference_pattern
)
do
|
text
|
# `<a href="http://gitlab.example.com/namespace/project/issues/123">http://gitlab.example.com/namespace/project/issues/123</a>`
object_link_filter
(
text
,
object_class
.
link_reference_pattern
)
replace_link_nodes_with_text
(
object_class
.
link_reference_pattern
)
do
|
text
|
end
object_link_filter
(
text
,
object_class
.
link_reference_pattern
)
end
# `[Issue](http://gitlab.example.com/namespace/project/issues/123)`, which is turned into
# `[Issue](http://gitlab.example.com/namespace/project/issues/123)`, which is turned into
# `<a href="http://gitlab.example.com/namespace/project/issues/123">Issue</a>`
# `<a href="http://gitlab.example.com/namespace/project/issues/123">Issue</a>`
replace_link_nodes_with_href
(
object_class
.
link_reference_pattern
)
do
|
link
,
text
|
replace_link_nodes_with_href
(
object_class
.
link_reference_pattern
)
do
|
link
,
text
|
object_link_filter
(
link
,
object_class
.
link_reference_pattern
,
link_text:
text
)
object_link_filter
(
link
,
object_class
.
link_reference_pattern
,
link_text:
text
)
end
end
end
end
end
...
...
lib/banzai/filter/milestone_reference_filter.rb
0 → 100644
View file @
989131c5
require
'banzai'
module
Banzai
module
Filter
# HTML filter that replaces milestone references with links.
#
# This filter supports cross-project references.
class
MilestoneReferenceFilter
<
AbstractReferenceFilter
def
self
.
object_class
Milestone
end
def
find_object
(
project
,
id
)
project
.
milestones
.
find_by
(
iid:
id
)
end
def
url_for_object
(
issue
,
project
)
h
=
Gitlab
::
Application
.
routes
.
url_helpers
h
.
namespace_project_milestone_url
(
project
.
namespace
,
project
,
milestone
,
only_path:
context
[
:only_path
])
end
end
end
end
lib/banzai/pipeline/gfm_pipeline.rb
View file @
989131c5
...
@@ -22,6 +22,7 @@ module Banzai
...
@@ -22,6 +22,7 @@ module Banzai
Filter
::
CommitRangeReferenceFilter
,
Filter
::
CommitRangeReferenceFilter
,
Filter
::
CommitReferenceFilter
,
Filter
::
CommitReferenceFilter
,
Filter
::
LabelReferenceFilter
,
Filter
::
LabelReferenceFilter
,
Filter
::
MilestoneReferenceFilter
,
Filter
::
TaskListFilter
Filter
::
TaskListFilter
]
]
...
...
lib/gitlab/reference_extractor.rb
View file @
989131c5
...
@@ -18,7 +18,7 @@ module Gitlab
...
@@ -18,7 +18,7 @@ module Gitlab
super
(
text
,
context
.
merge
(
project:
project
))
super
(
text
,
context
.
merge
(
project:
project
))
end
end
%i(user label merge_request snippet commit commit_range)
.
each
do
|
type
|
%i(user label m
ilestone m
erge_request snippet commit commit_range)
.
each
do
|
type
|
define_method
(
"
#{
type
}
s"
)
do
define_method
(
"
#{
type
}
s"
)
do
@references
[
type
]
||=
references
(
type
,
project:
project
,
current_user:
current_user
)
@references
[
type
]
||=
references
(
type
,
project:
project
,
current_user:
current_user
)
end
end
...
...
spec/features/markdown_spec.rb
View file @
989131c5
...
@@ -212,6 +212,7 @@ describe 'GitLab Markdown', feature: true do
...
@@ -212,6 +212,7 @@ describe 'GitLab Markdown', feature: true do
expect
(
doc
).
to
reference_commit_ranges
expect
(
doc
).
to
reference_commit_ranges
expect
(
doc
).
to
reference_commits
expect
(
doc
).
to
reference_commits
expect
(
doc
).
to
reference_labels
expect
(
doc
).
to
reference_labels
expect
(
doc
).
to
reference_milestones
end
end
end
end
...
...
spec/fixtures/markdown.md.erb
View file @
989131c5
...
@@ -214,6 +214,14 @@ References should be parseable even inside _<%= merge_request.to_reference %>_ e
...
@@ -214,6 +214,14 @@ References should be parseable even inside _<%= merge_request.to_reference %>_ e
- Ignored in links: [Link to
<%=
simple_label
.
to_reference
%>
](#label-link)
- Ignored in links: [Link to
<%=
simple_label
.
to_reference
%>
](#label-link)
- Link to label by reference: [Label](
<%=
label
.
to_reference
%>
)
- Link to label by reference: [Label](
<%=
label
.
to_reference
%>
)
#### MilestoneReferenceFilter
- Milestone:
<%=
milestone
.
to_reference
%>
- Milestone in another project:
<%=
xmilestone
.
to_reference
(
project
)
%>
- Ignored in code: `
<%=
milestone
.
to_reference
%>
`
- Ignored in links: [Link to
<%=
milestone
.
to_reference
%>
](#milestone-link)
- Link to milestone by URL: [Milestone](
<%=
urls
.
namespace_project_milestone_url
(
milestone
.
project
.
namespace
,
milestone
.
project
,
milestone
)
%>
)
### Task Lists
### Task Lists
- [ ] Incomplete task 1
- [ ] Incomplete task 1
...
...
spec/lib/banzai/filter/milestone_reference_filter_spec.rb
0 → 100644
View file @
989131c5
require
'spec_helper'
describe
Banzai
::
Filter
::
MilestoneReferenceFilter
,
lib:
true
do
include
FilterSpecHelper
let
(
:project
)
{
create
(
:project
,
:public
)
}
let
(
:milestone
)
{
create
(
:milestone
,
project:
project
)
}
it
'requires project context'
do
expect
{
described_class
.
call
(
''
)
}.
to
raise_error
(
ArgumentError
,
/:project/
)
end
%w(pre code a style)
.
each
do
|
elem
|
it
"ignores valid references contained inside '
#{
elem
}
' element"
do
exp
=
act
=
"<
#{
elem
}
>milestone
#{
milestone
.
to_reference
}
</
#{
elem
}
>"
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
end
end
context
'internal reference'
do
let
(
:reference
)
{
milestone
.
to_reference
}
it
'links to a valid reference'
do
doc
=
reference_filter
(
"See
#{
reference
}
"
)
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)).
to
eq
urls
.
namespace_project_milestone_url
(
project
.
namespace
,
project
,
milestone
)
end
it
'links with adjacent text'
do
doc
=
reference_filter
(
"milestone (
#{
reference
}
.)"
)
expect
(
doc
.
to_html
).
to
match
(
/\(<a.+><i.+><\/i>
#{
Regexp
.
escape
(
milestone
.
title
)
}
<\/a>\.\)/
)
end
it
'includes a title attribute'
do
doc
=
reference_filter
(
"milestone
#{
reference
}
"
)
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'title'
)).
to
eq
"Milestone:
#{
milestone
.
title
}
"
end
it
'escapes the title attribute'
do
milestone
.
update_attribute
(
:title
,
%{"></a>whatever<a title="}
)
doc
=
reference_filter
(
"milestone
#{
reference
}
"
)
expect
(
doc
.
text
).
to
eq
"milestone
#{
milestone
.
title
}
"
end
it
'includes default classes'
do
doc
=
reference_filter
(
"milestone
#{
reference
}
"
)
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'class'
)).
to
eq
'gfm gfm-milestone'
end
it
'includes a data-project attribute'
do
doc
=
reference_filter
(
"milestone
#{
reference
}
"
)
link
=
doc
.
css
(
'a'
).
first
expect
(
link
).
to
have_attribute
(
'data-project'
)
expect
(
link
.
attr
(
'data-project'
)).
to
eq
project
.
id
.
to_s
end
it
'includes a data-milestone attribute'
do
doc
=
reference_filter
(
"See
#{
reference
}
"
)
link
=
doc
.
css
(
'a'
).
first
expect
(
link
).
to
have_attribute
(
'data-milestone'
)
expect
(
link
.
attr
(
'data-milestone'
)).
to
eq
milestone
.
id
.
to_s
end
it
'adds to the results hash'
do
result
=
reference_pipeline_result
(
"milestone
#{
reference
}
"
)
expect
(
result
[
:references
][
:milestone
]).
to
eq
[
milestone
]
end
end
end
spec/support/markdown_feature.rb
View file @
989131c5
...
@@ -59,6 +59,10 @@ class MarkdownFeature
...
@@ -59,6 +59,10 @@ class MarkdownFeature
@label
||=
create
(
:label
,
name:
'awaiting feedback'
,
project:
project
)
@label
||=
create
(
:label
,
name:
'awaiting feedback'
,
project:
project
)
end
end
def
milestone
@milestone
||=
create
(
:milestone
,
project:
project
)
end
# Cross-references -----------------------------------------------------------
# Cross-references -----------------------------------------------------------
def
xproject
def
xproject
...
@@ -93,6 +97,10 @@ class MarkdownFeature
...
@@ -93,6 +97,10 @@ class MarkdownFeature
end
end
end
end
def
xmilestone
@xmilestone
||=
create
(
:milestone
,
project:
xproject
)
end
def
urls
def
urls
Gitlab
::
Application
.
routes
.
url_helpers
Gitlab
::
Application
.
routes
.
url_helpers
end
end
...
...
spec/support/matchers/markdown_matchers.rb
View file @
989131c5
...
@@ -130,6 +130,15 @@ module MarkdownMatchers
...
@@ -130,6 +130,15 @@ module MarkdownMatchers
end
end
end
end
# MilestoneReferenceFilter
matcher
:reference_milestones
do
set_default_markdown_messages
match
do
|
actual
|
expect
(
actual
).
to
have_selector
(
'a.gfm.gfm-milestone'
,
count:
3
)
end
end
# TaskListFilter
# TaskListFilter
matcher
:parse_task_lists
do
matcher
:parse_task_lists
do
set_default_markdown_messages
set_default_markdown_messages
...
...
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