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
Jérome Perrin
gitlab-ce
Commits
85db534a
Commit
85db534a
authored
Dec 07, 2012
by
Ariejan de Vroom
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2208 from jouve/username2
Allow proper use of @username in Git(lab|hub) Flavored Markdown.
parents
945fe846
045b4c8f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
37 deletions
+34
-37
lib/gitlab/markdown.rb
lib/gitlab/markdown.rb
+20
-23
spec/helpers/gitlab_markdown_helper_spec.rb
spec/helpers/gitlab_markdown_helper_spec.rb
+8
-8
spec/requests/gitlab_flavored_markdown_spec.rb
spec/requests/gitlab_flavored_markdown_spec.rb
+6
-6
No files found.
lib/gitlab/markdown.rb
View file @
85db534a
...
...
@@ -26,15 +26,19 @@ module Gitlab
# => "<img alt=\":trollface:\" class=\"emoji\" src=\"/images/trollface.png" title=\":trollface:\" />
module
Markdown
REFERENCE_PATTERN
=
%r{
(
\W
)? # Prefix (1)
( # Reference (2)
@([
\w\.
_]+) # User name (3)
|[#!$](
\d
+) # Issue/MR/Snippet ID (4)
|([
\h
]{6,40}) # Commit ID (5)
(?<prefix>
\W
)? # Prefix
( # Reference
@(?<user>[a-zA-Z][a-zA-Z0-9_
\-\.
]*) # User name
|
\#
(?<issue>
\d
+) # Issue ID
|!(?<merge_request>
\d
+) # MR ID
|
\$
(?<snippet>
\d
+) # Snippet ID
|(?<commit>[
\h
]{6,40}) # Commit ID
)
(
\W
)? # Suffix (6)
(
?<suffix>
\W
)? # Suffix
}x
.
freeze
TYPES
=
[
:user
,
:issue
,
:merge_request
,
:snippet
,
:commit
].
freeze
EMOJI_PATTERN
=
%r{(:(
\S
+):)}
.
freeze
attr_reader
:html_options
...
...
@@ -95,16 +99,16 @@ module Gitlab
def
parse_references
(
text
)
# parse reference links
text
.
gsub!
(
REFERENCE_PATTERN
)
do
|
match
|
prefix
=
$
1
||
''
reference
=
$2
identifier
=
$3
||
$4
||
$5
suffix
=
$6
||
''
prefix
=
$
~
[
:prefix
]
suffix
=
$~
[
:suffix
]
type
=
TYPES
.
select
{
|
t
|
!
$~
[
t
].
nil?
}.
first
identifier
=
$~
[
type
]
# Avoid HTML entities
if
prefix
.
ends_with?
(
'&'
)
||
suffix
.
starts_with?
(
';'
)
if
prefix
&&
suffix
&&
prefix
[
0
]
==
'&'
&&
suffix
[
-
1
]
==
';'
match
elsif
ref_link
=
reference_link
(
referenc
e
,
identifier
)
prefix
+
ref_link
+
suffix
elsif
ref_link
=
reference_link
(
typ
e
,
identifier
)
"
#{
prefix
}#{
ref_link
}#{
suffix
}
"
else
match
end
...
...
@@ -137,19 +141,12 @@ module Gitlab
# identifier - Object identifier (Issue ID, SHA hash, etc.)
#
# Returns string rendered by the processing method
def
reference_link
(
reference
,
identifier
)
case
reference
when
/^@/
then
reference_user
(
identifier
)
when
/^#/
then
reference_issue
(
identifier
)
when
/^!/
then
reference_merge_request
(
identifier
)
when
/^\$/
then
reference_snippet
(
identifier
)
when
/^\h/
then
reference_commit
(
identifier
)
end
def
reference_link
(
type
,
identifier
)
send
(
"reference_
#{
type
}
"
,
identifier
)
end
def
reference_user
(
identifier
)
if
user
=
@project
.
users
.
where
(
name:
identifier
).
first
member
=
@project
.
users_projects
.
where
(
user_id:
user
).
first
if
member
=
@project
.
users_projects
.
joins
(
:user
).
where
(
users:
{
username:
identifier
}).
first
link_to
(
"@
#{
identifier
}
"
,
project_team_member_path
(
@project
,
member
),
html_options
.
merge
(
class:
"gfm gfm-team_member
#{
html_options
[
:class
]
}
"
))
if
member
end
end
...
...
spec/helpers/gitlab_markdown_helper_spec.rb
View file @
85db534a
...
...
@@ -3,7 +3,7 @@ require "spec_helper"
describe
GitlabMarkdownHelper
do
let!
(
:project
)
{
create
(
:project
)
}
let
(
:user
)
{
create
(
:user
,
name:
'gfm'
)
}
let
(
:user
)
{
create
(
:user
,
user
name:
'gfm'
)
}
let
(
:commit
)
{
CommitDecorator
.
decorate
(
project
.
commit
)
}
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:merge_request
)
{
create
(
:merge_request
,
project:
project
)
}
...
...
@@ -81,7 +81,7 @@ describe GitlabMarkdownHelper do
end
describe
"referencing a team member"
do
let
(
:actual
)
{
"@
#{
user
.
name
}
you are right."
}
let
(
:actual
)
{
"@
#{
user
.
user
name
}
you are right."
}
let
(
:expected
)
{
project_team_member_path
(
project
,
member
)
}
before
do
...
...
@@ -103,18 +103,18 @@ describe GitlabMarkdownHelper do
end
it
"should link with adjacent text"
do
actual
=
"Mail the admin (@
gfm
)"
actual
=
"Mail the admin (@
#{
user
.
username
}
)"
gfm
(
actual
).
should
match
(
expected
)
end
it
"should keep whitespace intact"
do
actual
=
"Yes, @
#{
user
.
name
}
is right."
expected
=
/Yes, <a.+>@
#{
user
.
name
}
<\/a> is right/
actual
=
"Yes, @
#{
user
.
user
name
}
is right."
expected
=
/Yes, <a.+>@
#{
user
.
user
name
}
<\/a> is right/
gfm
(
actual
).
should
match
(
expected
)
end
it
"should not link with an invalid id"
do
actual
=
expected
=
"@
#{
user
.
name
.
reverse
}
you are right."
actual
=
expected
=
"@
#{
user
.
user
name
.
reverse
}
you are right."
gfm
(
actual
).
should
==
expected
end
...
...
@@ -316,10 +316,10 @@ describe GitlabMarkdownHelper do
it
"should handle references in lists"
do
project
.
users
<<
user
actual
=
"
\n
* dark: #
#{
issue
.
id
}
\n
* light by @
#{
member
.
user
_
name
}
"
actual
=
"
\n
* dark: #
#{
issue
.
id
}
\n
* light by @
#{
member
.
user
.
user
name
}
"
markdown
(
actual
).
should
match
(
%r{<li>dark: <a.+>#
#{
issue
.
id
}
</a></li>}
)
markdown
(
actual
).
should
match
(
%r{<li>light by <a.+>@
#{
member
.
user
_
name
}
</a></li>}
)
markdown
(
actual
).
should
match
(
%r{<li>light by <a.+>@
#{
member
.
user
.
user
name
}
</a></li>}
)
end
it
"should handle references in <em>"
do
...
...
spec/requests/gitlab_flavored_markdown_spec.rb
View file @
85db534a
...
...
@@ -19,7 +19,7 @@ describe "Gitlab Flavored Markdown" do
@test_file
=
"gfm_test_file"
i
.
add
(
@test_file
,
"foo
\n
bar
\n
"
)
# add commit with gfm
i
.
commit
(
"fix #
#{
issue
.
id
}
\n\n
ask @
#{
fred
.
name
}
for details"
,
head:
@branch_name
)
i
.
commit
(
"fix #
#{
issue
.
id
}
\n\n
ask @
#{
fred
.
user
name
}
for details"
,
head:
@branch_name
)
# add test tag
@tag_name
=
"gfm-test-tag"
...
...
@@ -56,7 +56,7 @@ describe "Gitlab Flavored Markdown" do
it
"should render description in commits#show"
do
visit
project_commit_path
(
project
,
commit
)
page
.
should
have_link
(
"@
#{
fred
.
name
}
"
)
page
.
should
have_link
(
"@
#{
fred
.
user
name
}
"
)
end
it
"should render title in refs#tree"
,
js:
true
do
...
...
@@ -93,7 +93,7 @@ describe "Gitlab Flavored Markdown" do
assignee:
@user
,
project:
project
,
title:
"fix #
#{
@other_issue
.
id
}
"
,
description:
"ask @
#{
fred
.
name
}
for details"
)
description:
"ask @
#{
fred
.
user
name
}
for details"
)
end
it
"should render subject in issues#index"
do
...
...
@@ -111,7 +111,7 @@ describe "Gitlab Flavored Markdown" do
it
"should render details in issues#show"
do
visit
project_issue_path
(
project
,
@issue
)
page
.
should
have_link
(
"@
#{
fred
.
name
}
"
)
page
.
should
have_link
(
"@
#{
fred
.
user
name
}
"
)
end
end
...
...
@@ -142,7 +142,7 @@ describe "Gitlab Flavored Markdown" do
@milestone
=
create
(
:milestone
,
project:
project
,
title:
"fix #
#{
issue
.
id
}
"
,
description:
"ask @
#{
fred
.
name
}
for details"
)
description:
"ask @
#{
fred
.
user
name
}
for details"
)
end
it
"should render title in milestones#index"
do
...
...
@@ -160,7 +160,7 @@ describe "Gitlab Flavored Markdown" do
it
"should render description in milestones#show"
do
visit
project_milestone_path
(
project
,
@milestone
)
page
.
should
have_link
(
"@
#{
fred
.
name
}
"
)
page
.
should
have_link
(
"@
#{
fred
.
user
name
}
"
)
end
end
...
...
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