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
iv
gitlab-ce
Commits
a6defd15
Commit
a6defd15
authored
Apr 15, 2015
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add results to reference filters
parent
85082de7
Changes
14
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
129 additions
and
18 deletions
+129
-18
lib/gitlab/markdown/commit_range_reference_filter.rb
lib/gitlab/markdown/commit_range_reference_filter.rb
+2
-0
lib/gitlab/markdown/commit_reference_filter.rb
lib/gitlab/markdown/commit_reference_filter.rb
+2
-0
lib/gitlab/markdown/issue_reference_filter.rb
lib/gitlab/markdown/issue_reference_filter.rb
+3
-0
lib/gitlab/markdown/label_reference_filter.rb
lib/gitlab/markdown/label_reference_filter.rb
+4
-2
lib/gitlab/markdown/merge_request_reference_filter.rb
lib/gitlab/markdown/merge_request_reference_filter.rb
+2
-0
lib/gitlab/markdown/snippet_reference_filter.rb
lib/gitlab/markdown/snippet_reference_filter.rb
+2
-0
lib/gitlab/markdown/user_reference_filter.rb
lib/gitlab/markdown/user_reference_filter.rb
+7
-0
spec/lib/gitlab/markdown/commit_range_reference_filter_spec.rb
...lib/gitlab/markdown/commit_range_reference_filter_spec.rb
+10
-0
spec/lib/gitlab/markdown/commit_reference_filter_spec.rb
spec/lib/gitlab/markdown/commit_reference_filter_spec.rb
+10
-0
spec/lib/gitlab/markdown/issue_reference_filter_spec.rb
spec/lib/gitlab/markdown/issue_reference_filter_spec.rb
+11
-1
spec/lib/gitlab/markdown/label_reference_filter_spec.rb
spec/lib/gitlab/markdown/label_reference_filter_spec.rb
+5
-0
spec/lib/gitlab/markdown/merge_request_reference_filter_spec.rb
...ib/gitlab/markdown/merge_request_reference_filter_spec.rb
+10
-0
spec/lib/gitlab/markdown/snippet_reference_filter_spec.rb
spec/lib/gitlab/markdown/snippet_reference_filter_spec.rb
+10
-0
spec/lib/gitlab/markdown/user_reference_filter_spec.rb
spec/lib/gitlab/markdown/user_reference_filter_spec.rb
+51
-15
No files found.
lib/gitlab/markdown/commit_range_reference_filter.rb
View file @
a6defd15
...
...
@@ -59,6 +59,8 @@ module Gitlab
from_id
,
to_id
=
split_commit_range
(
commit_range
)
if
valid_range?
(
project
,
from_id
,
to_id
)
push_result
(
:commit_range
,
[
commit
(
from_id
),
commit
(
to_id
)])
url
=
url_for_commit_range
(
project
,
from_id
,
to_id
)
title
=
"Commits
#{
from_id
}
through
#{
to_id
}
"
...
...
lib/gitlab/markdown/commit_reference_filter.rb
View file @
a6defd15
...
...
@@ -48,6 +48,8 @@ module Gitlab
project
=
self
.
project_from_ref
(
project_ref
)
if
commit
=
commit_from_ref
(
project
,
commit_ref
)
push_result
(
:commit
,
commit
)
url
=
url_for_commit
(
project
,
commit
)
title
=
escape_once
(
commit
.
link_title
)
...
...
lib/gitlab/markdown/issue_reference_filter.rb
View file @
a6defd15
...
...
@@ -48,6 +48,9 @@ module Gitlab
project
=
self
.
project_from_ref
(
project_ref
)
if
project
&&
project
.
issue_exists?
(
issue
)
# FIXME (rspeicher): Law of Demeter
push_result
(
:issue
,
project
.
issues
.
where
(
iid:
issue
).
first
)
url
=
url_for_issue
(
issue
,
project
,
only_path:
context
[
:only_path
])
title
=
escape_once
(
"Issue:
#{
title_for_issue
(
issue
,
project
)
}
"
)
...
...
lib/gitlab/markdown/label_reference_filter.rb
View file @
a6defd15
...
...
@@ -52,11 +52,13 @@ module Gitlab
params
=
label_params
(
id
,
name
)
if
label
=
project
.
labels
.
find_by
(
params
)
url
=
url_for_label
(
project
,
label
)
push_result
(
:label
,
label
)
url
=
url_for_label
(
project
,
label
)
klass
=
reference_class
(
:label
)
%(<a href="#{url}" class="#{klass}">#{render_colored_label(label)}</a>)
%(<a href="#{url}"
class="#{klass}">#{render_colored_label(label)}</a>)
else
match
end
...
...
lib/gitlab/markdown/merge_request_reference_filter.rb
View file @
a6defd15
...
...
@@ -48,6 +48,8 @@ module Gitlab
project
=
self
.
project_from_ref
(
project_ref
)
if
project
&&
merge_request
=
project
.
merge_requests
.
find_by
(
iid:
id
)
push_result
(
:merge_request
,
merge_request
)
title
=
escape_once
(
"Merge Request:
#{
merge_request
.
title
}
"
)
klass
=
reference_class
(
:merge_request
)
...
...
lib/gitlab/markdown/snippet_reference_filter.rb
View file @
a6defd15
...
...
@@ -48,6 +48,8 @@ module Gitlab
project
=
self
.
project_from_ref
(
project_ref
)
if
project
&&
snippet
=
project
.
snippets
.
find_by
(
id:
id
)
push_result
(
:snippet
,
snippet
)
title
=
escape_once
(
"Snippet:
#{
snippet
.
title
}
"
)
klass
=
reference_class
(
:snippet
)
...
...
lib/gitlab/markdown/user_reference_filter.rb
View file @
a6defd15
...
...
@@ -44,18 +44,25 @@ module Gitlab
klass
=
reference_class
(
:project_member
)
if
user
==
'all'
# FIXME (rspeicher): Law of Demeter
push_result
(
:user
,
project
.
team
.
members
.
flatten
)
url
=
link_to_all
(
project
)
%(<a href="#{url}" class="#{klass}">@#{user}</a>)
elsif
namespace
=
Namespace
.
find_by
(
path:
user
)
if
namespace
.
is_a?
(
Group
)
if
user_can_reference_group?
(
namespace
)
push_result
(
:user
,
namespace
.
users
)
url
=
group_url
(
user
,
only_path:
context
[
:only_path
])
%(<a href="#{url}" class="#{klass}">@#{user}</a>)
else
match
end
else
push_result
(
:user
,
namespace
.
owner
)
url
=
user_url
(
user
,
only_path:
context
[
:only_path
])
%(<a href="#{url}" class="#{klass}">@#{user}</a>)
end
...
...
spec/lib/gitlab/markdown/commit_range_reference_filter_spec.rb
View file @
a6defd15
...
...
@@ -81,6 +81,11 @@ module Gitlab::Markdown
expect
(
link
).
not_to
match
%r(https?://)
expect
(
link
).
to
eq
urls
.
namespace_project_compare_url
(
project
.
namespace
,
project
,
from:
commit1
.
id
,
to:
commit2
.
id
,
only_path:
true
)
end
it
'adds to the results hash'
do
result
=
pipeline_result
(
"See
#{
reference
}
"
)
expect
(
result
[
:references
][
:commit_range
]).
not_to
be_empty
end
end
context
'cross-project reference'
do
...
...
@@ -112,6 +117,11 @@ module Gitlab::Markdown
exp
=
act
=
"Fixed
#{
project2
.
path_with_namespace
}
#
#{
commit1
.
id
}
...
#{
commit2
.
id
.
reverse
}
"
expect
(
filter
(
act
).
to_html
).
to
eq
exp
end
it
'adds to the results hash'
do
result
=
pipeline_result
(
"See
#{
reference
}
"
)
expect
(
result
[
:references
][
:commit_range
]).
not_to
be_empty
end
end
context
'when user cannot access reference'
do
...
...
spec/lib/gitlab/markdown/commit_reference_filter_spec.rb
View file @
a6defd15
...
...
@@ -75,6 +75,11 @@ module Gitlab::Markdown
expect
(
link
).
not_to
match
%r(https?://)
expect
(
link
).
to
eq
urls
.
namespace_project_commit_url
(
project
.
namespace
,
project
,
reference
,
only_path:
true
)
end
it
'adds to the results hash'
do
result
=
pipeline_result
(
"See
#{
reference
}
"
)
expect
(
result
[
:references
][
:commit
]).
not_to
be_empty
end
end
context
'cross-project reference'
do
...
...
@@ -102,6 +107,11 @@ module Gitlab::Markdown
exp
=
act
=
"Committed
#{
project2
.
path_with_namespace
}
#
#{
commit
.
id
.
reverse
}
"
expect
(
filter
(
act
).
to_html
).
to
eq
exp
end
it
'adds to the results hash'
do
result
=
pipeline_result
(
"See
#{
reference
}
"
)
expect
(
result
[
:references
][
:commit
]).
not_to
be_empty
end
end
context
'when user cannot access reference'
do
...
...
spec/lib/gitlab/markdown/issue_reference_filter_spec.rb
View file @
a6defd15
...
...
@@ -34,7 +34,7 @@ module Gitlab::Markdown
end
it
'links to a valid reference'
do
doc
=
filter
(
"
See
#{
reference
}
"
)
doc
=
filter
(
"
Fixed
#{
reference
}
"
)
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)).
to
eq
helper
.
url_for_issue
(
issue
.
iid
,
project
)
...
...
@@ -81,6 +81,11 @@ module Gitlab::Markdown
expect
(
link
).
not_to
match
%r(https?://)
expect
(
link
).
to
eq
helper
.
url_for_issue
(
issue
.
iid
,
project
,
only_path:
true
)
end
it
'adds to the results hash'
do
result
=
pipeline_result
(
"Fixed
#{
reference
}
"
)
expect
(
result
[
:references
][
:issue
]).
to
eq
[
issue
]
end
end
context
'cross-project reference'
do
...
...
@@ -117,6 +122,11 @@ module Gitlab::Markdown
expect
(
filter
(
act
).
to_html
).
to
eq
exp
end
it
'adds to the results hash'
do
result
=
pipeline_result
(
"Fixed
#{
reference
}
"
)
expect
(
result
[
:references
][
:issue
]).
to
eq
[
issue
]
end
end
context
'when user cannot access reference'
do
...
...
spec/lib/gitlab/markdown/label_reference_filter_spec.rb
View file @
a6defd15
...
...
@@ -39,6 +39,11 @@ module Gitlab::Markdown
expect
(
link
).
to
eq
urls
.
namespace_project_issues_url
(
project
.
namespace
,
project
,
label_name:
label
.
name
,
only_path:
true
)
end
it
'adds to the results hash'
do
result
=
pipeline_result
(
"Label
#{
reference
}
"
)
expect
(
result
[
:references
][
:label
]).
to
eq
[
label
]
end
describe
'label span element'
do
it
'includes default classes'
do
doc
=
filter
(
"Label
#{
reference
}
"
)
...
...
spec/lib/gitlab/markdown/merge_request_reference_filter_spec.rb
View file @
a6defd15
...
...
@@ -69,6 +69,11 @@ module Gitlab::Markdown
expect
(
link
).
not_to
match
%r(https?://)
expect
(
link
).
to
eq
urls
.
namespace_project_merge_request_url
(
project
.
namespace
,
project
,
merge
,
only_path:
true
)
end
it
'adds to the results hash'
do
result
=
pipeline_result
(
"Merge
#{
reference
}
"
)
expect
(
result
[
:references
][
:merge_request
]).
to
eq
[
merge
]
end
end
context
'cross-project reference'
do
...
...
@@ -98,6 +103,11 @@ module Gitlab::Markdown
expect
(
filter
(
act
).
to_html
).
to
eq
exp
end
it
'adds to the results hash'
do
result
=
pipeline_result
(
"Merge
#{
reference
}
"
)
expect
(
result
[
:references
][
:merge_request
]).
to
eq
[
merge
]
end
end
context
'when user cannot access reference'
do
...
...
spec/lib/gitlab/markdown/snippet_reference_filter_spec.rb
View file @
a6defd15
...
...
@@ -68,6 +68,11 @@ module Gitlab::Markdown
expect
(
link
).
not_to
match
%r(https?://)
expect
(
link
).
to
eq
urls
.
namespace_project_snippet_url
(
project
.
namespace
,
project
,
snippet
,
only_path:
true
)
end
it
'adds to the results hash'
do
result
=
pipeline_result
(
"Snippet
#{
reference
}
"
)
expect
(
result
[
:references
][
:snippet
]).
to
eq
[
snippet
]
end
end
context
'cross-project reference'
do
...
...
@@ -96,6 +101,11 @@ module Gitlab::Markdown
expect
(
filter
(
act
).
to_html
).
to
eq
exp
end
it
'adds to the results hash'
do
result
=
pipeline_result
(
"Snippet
#{
reference
}
"
)
expect
(
result
[
:references
][
:snippet
]).
to
eq
[
snippet
]
end
end
context
'when user cannot access reference'
do
...
...
spec/lib/gitlab/markdown/user_reference_filter_spec.rb
View file @
a6defd15
...
...
@@ -24,9 +24,29 @@ module Gitlab::Markdown
end
end
context
'mentioning @all'
do
before
do
project
.
team
<<
[
project
.
creator
,
:developer
]
end
it
'supports a special @all mention'
do
doc
=
filter
(
"Hey @all"
)
expect
(
doc
.
css
(
'a'
).
length
).
to
eq
1
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'href'
))
.
to
eq
urls
.
namespace_project_url
(
project
.
namespace
,
project
)
end
it
'adds to the results hash'
do
result
=
pipeline_result
(
'Hey @all'
)
expect
(
result
[
:references
][
:user
]).
to
eq
[[
project
.
creator
]]
end
end
context
'mentioning a user'
do
let
(
:reference
)
{
"@
#{
user
.
username
}
"
}
it
'links to a User'
do
doc
=
filter
(
"Hey
@
#{
user
.
usernam
e
}
"
)
doc
=
filter
(
"Hey
#{
referenc
e
}
"
)
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)).
to
eq
urls
.
user_url
(
user
)
end
...
...
@@ -45,22 +65,45 @@ module Gitlab::Markdown
doc
=
filter
(
"Hey @
#{
user
.
username
}
"
)
expect
(
doc
.
css
(
'a'
).
length
).
to
eq
1
end
it
'adds to the results hash'
do
result
=
pipeline_result
(
"Hey
#{
reference
}
"
)
expect
(
result
[
:references
][
:user
]).
to
eq
[
user
]
end
end
context
'mentioning a group'
do
let
(
:group
)
{
create
(
:group
)
}
let
(
:user
)
{
create
(
:user
)
}
it
'links to a Group that the current user can read'
do
let
(
:reference
)
{
"@
#{
group
.
name
}
"
}
context
'that the current user can read'
do
before
do
group
.
add_user
(
user
,
Gitlab
::
Access
::
DEVELOPER
)
end
doc
=
filter
(
"Hey @
#{
group
.
name
}
"
,
current_user:
user
)
it
'links to the Group'
do
doc
=
filter
(
"Hey
#{
reference
}
"
,
current_user:
user
)
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)).
to
eq
urls
.
group_url
(
group
)
end
it
'ignores references to a Group that the current user cannot read'
do
doc
=
filter
(
"Hey @
#{
group
.
name
}
"
,
current_user:
user
)
expect
(
doc
.
to_html
).
to
eq
"Hey @
#{
group
.
name
}
"
it
'adds to the results hash'
do
result
=
pipeline_result
(
"Hey
#{
reference
}
"
,
current_user:
user
)
expect
(
result
[
:references
][
:user
]).
to
eq
[
group
.
users
]
end
end
context
'that the current user cannot read'
do
it
'ignores references to the Group'
do
doc
=
filter
(
"Hey
#{
reference
}
"
,
current_user:
user
)
expect
(
doc
.
to_html
).
to
eq
"Hey
#{
reference
}
"
end
it
'does not add to the results hash'
do
result
=
pipeline_result
(
"Hey
#{
reference
}
"
,
current_user:
user
)
expect
(
result
[
:references
][
:user
]).
to
eq
[]
end
end
end
...
...
@@ -70,13 +113,6 @@ module Gitlab::Markdown
expect
(
doc
.
to_html
).
to
match
(
/\(<a.+>@
#{
user
.
username
}
<\/a>\.\)/
)
end
it
'supports a special @all mention'
do
doc
=
filter
(
"Hey @all"
)
expect
(
doc
.
css
(
'a'
).
length
).
to
eq
1
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'href'
))
.
to
eq
urls
.
namespace_project_url
(
project
.
namespace
,
project
)
end
it
'includes default classes'
do
doc
=
filter
(
"Hey @
#{
user
.
username
}
"
)
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'class'
)).
to
eq
'gfm gfm-project_member'
...
...
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