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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
9c046fea
Commit
9c046fea
authored
May 26, 2014
by
skv
Committed by
GitLab
May 26, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
links to issues on main dashboard
parent
ef933ae6
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
110 additions
and
78 deletions
+110
-78
app/helpers/gitlab_markdown_helper.rb
app/helpers/gitlab_markdown_helper.rb
+1
-1
app/helpers/issues_helper.rb
app/helpers/issues_helper.rb
+43
-39
app/views/events/_commit.html.haml
app/views/events/_commit.html.haml
+1
-1
lib/gitlab/markdown.rb
lib/gitlab/markdown.rb
+62
-35
lib/gitlab/reference_extractor.rb
lib/gitlab/reference_extractor.rb
+1
-1
spec/helpers/gitlab_markdown_helper_spec.rb
spec/helpers/gitlab_markdown_helper_spec.rb
+2
-1
No files found.
app/helpers/gitlab_markdown_helper.rb
View file @
9c046fea
...
@@ -19,7 +19,7 @@ module GitlabMarkdownHelper
...
@@ -19,7 +19,7 @@ module GitlabMarkdownHelper
escape_once
(
body
)
escape_once
(
body
)
end
end
gfm_body
=
gfm
(
escaped_body
,
html_options
)
gfm_body
=
gfm
(
escaped_body
,
@project
,
html_options
)
gfm_body
.
gsub!
(
%r{<a.*?>.*?</a>}m
)
do
|
match
|
gfm_body
.
gsub!
(
%r{<a.*?>.*?</a>}m
)
do
|
match
|
"</a>
#{
match
}#{
link_to
(
""
,
url
,
html_options
)[
0
..-
5
]
}
"
# "</a>".length +1
"</a>
#{
match
}#{
link_to
(
""
,
url
,
html_options
)[
0
..-
5
]
}
"
# "</a>".length +1
...
...
app/helpers/issues_helper.rb
View file @
9c046fea
...
@@ -13,76 +13,80 @@ module IssuesHelper
...
@@ -13,76 +13,80 @@ module IssuesHelper
OpenStruct
.
new
(
id:
0
,
title:
'None (backlog)'
,
name:
'Unassigned'
)
OpenStruct
.
new
(
id:
0
,
title:
'None (backlog)'
,
name:
'Unassigned'
)
end
end
def
url_for_project_issues
def
url_for_project_issues
(
project
=
@project
)
return
""
if
@
project
.
nil?
return
''
if
project
.
nil?
if
@
project
.
used_default_issues_tracker?
||
!
external_issues_tracker_enabled?
if
project
.
used_default_issues_tracker?
||
!
external_issues_tracker_enabled?
project_issues_path
(
@
project
)
project_issues_path
(
project
)
else
else
url
=
Gitlab
.
config
.
issues_tracker
[
@project
.
issues_tracker
][
"project_url"
]
url
=
Gitlab
.
config
.
issues_tracker
[
project
.
issues_tracker
][
'project_url'
]
url
.
gsub
(
':project_id'
,
@project
.
id
.
to_s
)
url
.
gsub
(
':project_id'
,
project
.
id
.
to_s
).
.
gsub
(
':issues_tracker_id'
,
@
project
.
issues_tracker_id
.
to_s
)
gsub
(
':issues_tracker_id'
,
project
.
issues_tracker_id
.
to_s
)
end
end
end
end
def
url_for_new_issue
def
url_for_new_issue
(
project
=
@project
)
return
""
if
@
project
.
nil?
return
''
if
project
.
nil?
if
@
project
.
used_default_issues_tracker?
||
!
external_issues_tracker_enabled?
if
project
.
used_default_issues_tracker?
||
!
external_issues_tracker_enabled?
url
=
new_project_issue_path
project_id:
@
project
url
=
new_project_issue_path
project_id:
project
else
else
url
=
Gitlab
.
config
.
issues_tracker
[
@project
.
issues_tracker
][
"new_issue_url"
]
issues_tracker
=
Gitlab
.
config
.
issues_tracker
[
project
.
issues_tracker
]
url
.
gsub
(
':project_id'
,
@project
.
id
.
to_s
)
url
=
issues_tracker
[
'new_issue_url'
]
.
gsub
(
':issues_tracker_id'
,
@project
.
issues_tracker_id
.
to_s
)
url
.
gsub
(
':project_id'
,
project
.
id
.
to_s
).
gsub
(
':issues_tracker_id'
,
project
.
issues_tracker_id
.
to_s
)
end
end
end
end
def
url_for_issue
(
issue_iid
)
def
url_for_issue
(
issue_iid
,
project
=
@project
)
return
""
if
@
project
.
nil?
return
''
if
project
.
nil?
if
@
project
.
used_default_issues_tracker?
||
!
external_issues_tracker_enabled?
if
project
.
used_default_issues_tracker?
||
!
external_issues_tracker_enabled?
url
=
project_issue_url
project_id:
@
project
,
id:
issue_iid
url
=
project_issue_url
project_id:
project
,
id:
issue_iid
else
else
url
=
Gitlab
.
config
.
issues_tracker
[
@project
.
issues_tracker
][
"issues_url"
]
url
=
Gitlab
.
config
.
issues_tracker
[
project
.
issues_tracker
][
'issues_url'
]
url
.
gsub
(
':id'
,
issue_iid
.
to_s
)
url
.
gsub
(
':id'
,
issue_iid
.
to_s
)
.
.
gsub
(
':project_id'
,
@project
.
id
.
to_s
)
gsub
(
':project_id'
,
project
.
id
.
to_s
).
.
gsub
(
':issues_tracker_id'
,
@
project
.
issues_tracker_id
.
to_s
)
gsub
(
':issues_tracker_id'
,
project
.
issues_tracker_id
.
to_s
)
end
end
end
end
def
title_for_issue
(
issue_iid
)
def
title_for_issue
(
issue_iid
,
project
=
@project
)
return
""
if
@
project
.
nil?
return
''
if
project
.
nil?
if
@project
.
used_default_issues_tracker?
&&
issue
=
@project
.
issues
.
where
(
iid:
issue_iid
).
first
if
project
.
used_default_issues_tracker?
issue
.
title
issue
=
project
.
issues
.
where
(
iid:
issue_iid
).
first
else
return
issue
.
title
if
issue
""
end
end
''
end
end
# Checks if issues_tracker setting exists in gitlab.yml
# Checks if issues_tracker setting exists in gitlab.yml
def
external_issues_tracker_enabled?
def
external_issues_tracker_enabled?
if
Gitlab
.
config
.
issues_tracker
&&
Gitlab
.
config
.
issues_tracker
.
values
.
any?
Gitlab
.
config
.
issues_tracker
&&
Gitlab
.
config
.
issues_tracker
.
values
.
any?
true
else
false
end
end
end
def
bulk_update_milestone_options
def
bulk_update_milestone_options
options_for_select
([
"None (backlog)"
])
+
options_from_collection_for_select
(
project_active_milestones
,
"id"
,
"title"
,
params
[
:milestone_id
])
options_for_select
([
'None (backlog)'
])
+
options_from_collection_for_select
(
project_active_milestones
,
'id'
,
'title'
,
params
[
:milestone_id
])
end
end
def
bulk_update_assignee_options
def
bulk_update_assignee_options
(
project
=
@project
)
options_for_select
([
"None (unassigned)"
])
+
options_from_collection_for_select
(
@project
.
team
.
members
,
"id"
,
"name"
,
params
[
:assignee_id
])
options_for_select
([
'None (unassigned)'
])
+
options_from_collection_for_select
(
project
.
team
.
members
,
'id'
,
'name'
,
params
[
:assignee_id
])
end
end
def
assignee_options
object
def
assignee_options
(
object
,
project
=
@project
)
options_from_collection_for_select
(
@project
.
team
.
members
.
sort_by
(
&
:name
),
'id'
,
'name'
,
object
.
assignee_id
)
options_from_collection_for_select
(
project
.
team
.
members
.
sort_by
(
&
:name
),
'id'
,
'name'
,
object
.
assignee_id
)
end
end
def
milestone_options
object
def
milestone_options
object
options_from_collection_for_select
(
object
.
project
.
milestones
.
active
,
'id'
,
'title'
,
object
.
milestone_id
)
options_from_collection_for_select
(
object
.
project
.
milestones
.
active
,
'id'
,
'title'
,
object
.
milestone_id
)
end
end
def
issue_box_class
(
item
)
def
issue_box_class
(
item
)
...
...
app/views/events/_commit.html.haml
View file @
9c046fea
...
@@ -2,4 +2,4 @@
...
@@ -2,4 +2,4 @@
.commit-row-title
.commit-row-title
=
link_to
commit
[
:id
][
0
..
8
],
project_commit_path
(
project
,
commit
[
:id
]),
class:
"commit_short_id"
,
alt:
''
=
link_to
commit
[
:id
][
0
..
8
],
project_commit_path
(
project
,
commit
[
:id
]),
class:
"commit_short_id"
,
alt:
''
=
gfm
event_commit_title
(
commit
[
:message
])
=
gfm
event_commit_title
(
commit
[
:message
])
,
project
lib/gitlab/markdown.rb
View file @
9c046fea
...
@@ -33,10 +33,9 @@ module Gitlab
...
@@ -33,10 +33,9 @@ module Gitlab
# Public: Parse the provided text with GitLab-Flavored Markdown
# Public: Parse the provided text with GitLab-Flavored Markdown
#
#
# text - the source text
# text - the source text
# project - extra options for the reference links as given to link_to
# html_options - extra options for the reference links as given to link_to
# html_options - extra options for the reference links as given to link_to
#
def
gfm
(
text
,
project
=
@project
,
html_options
=
{})
# Note: reference links will only be generated if @project is set
def
gfm
(
text
,
html_options
=
{})
return
text
if
text
.
nil?
return
text
if
text
.
nil?
# Duplicate the string so we don't alter the original, then call to_str
# Duplicate the string so we don't alter the original, then call to_str
...
@@ -56,14 +55,19 @@ module Gitlab
...
@@ -56,14 +55,19 @@ module Gitlab
# TODO: add popups with additional information
# TODO: add popups with additional information
text
=
parse
(
text
)
text
=
parse
(
text
,
project
)
# Insert pre block extractions
# Insert pre block extractions
text
.
gsub!
(
/\{gfm-extraction-(\h{32})\}/
)
do
text
.
gsub!
(
/\{gfm-extraction-(\h{32})\}/
)
do
insert_piece
(
$1
)
insert_piece
(
$1
)
end
end
sanitize
text
.
html_safe
,
attributes:
ActionView
::
Base
.
sanitized_allowed_attributes
+
%w(id class)
,
tags:
ActionView
::
Base
.
sanitized_allowed_tags
+
%w(table tr td th)
allowed_attributes
=
ActionView
::
Base
.
sanitized_allowed_attributes
allowed_tags
=
ActionView
::
Base
.
sanitized_allowed_tags
sanitize
text
.
html_safe
,
attributes:
allowed_attributes
+
%w(id class)
,
tags:
allowed_tags
+
%w(table tr td th)
end
end
private
private
...
@@ -84,11 +88,9 @@ module Gitlab
...
@@ -84,11 +88,9 @@ module Gitlab
#
#
# text - Text to parse
# text - Text to parse
#
#
# Note: reference links will only be generated if @project is set
#
# Returns parsed text
# Returns parsed text
def
parse
(
text
)
def
parse
(
text
,
project
=
@project
)
parse_references
(
text
)
if
@
project
parse_references
(
text
,
project
)
if
project
parse_emoji
(
text
)
parse_emoji
(
text
)
text
text
...
@@ -110,7 +112,7 @@ module Gitlab
...
@@ -110,7 +112,7 @@ module Gitlab
TYPES
=
[
:user
,
:issue
,
:merge_request
,
:snippet
,
:commit
].
freeze
TYPES
=
[
:user
,
:issue
,
:merge_request
,
:snippet
,
:commit
].
freeze
def
parse_references
(
text
)
def
parse_references
(
text
,
project
=
@project
)
# parse reference links
# parse reference links
text
.
gsub!
(
REFERENCE_PATTERN
)
do
|
match
|
text
.
gsub!
(
REFERENCE_PATTERN
)
do
|
match
|
prefix
=
$~
[
:prefix
]
prefix
=
$~
[
:prefix
]
...
@@ -123,7 +125,7 @@ module Gitlab
...
@@ -123,7 +125,7 @@ module Gitlab
# Avoid HTML entities
# Avoid HTML entities
if
prefix
&&
suffix
&&
prefix
[
0
]
==
'&'
&&
suffix
[
-
1
]
==
';'
if
prefix
&&
suffix
&&
prefix
[
0
]
==
'&'
&&
suffix
[
-
1
]
==
';'
match
match
elsif
ref_link
=
reference_link
(
type
,
identifier
)
elsif
ref_link
=
reference_link
(
type
,
identifier
,
project
)
"
#{
prefix
}#{
ref_link
}#{
suffix
}
"
"
#{
prefix
}#{
ref_link
}#{
suffix
}
"
else
else
match
match
...
@@ -153,7 +155,7 @@ module Gitlab
...
@@ -153,7 +155,7 @@ module Gitlab
#
#
# Returns boolean
# Returns boolean
def
valid_emoji?
(
emoji
)
def
valid_emoji?
(
emoji
)
Emoji
.
find_by_name
emoji
Emoji
.
find_by_name
(
emoji
)
end
end
# Private: Dispatches to a dedicated processing method based on reference
# Private: Dispatches to a dedicated processing method based on reference
...
@@ -162,52 +164,77 @@ module Gitlab
...
@@ -162,52 +164,77 @@ module Gitlab
# identifier - Object identifier (Issue ID, SHA hash, etc.)
# identifier - Object identifier (Issue ID, SHA hash, etc.)
#
#
# Returns string rendered by the processing method
# Returns string rendered by the processing method
def
reference_link
(
type
,
identifier
)
def
reference_link
(
type
,
identifier
,
project
=
@project
)
send
(
"reference_
#{
type
}
"
,
identifier
)
send
(
"reference_
#{
type
}
"
,
identifier
,
project
)
end
end
def
reference_user
(
identifier
)
def
reference_user
(
identifier
,
project
=
@project
)
if
user
=
User
.
find_by_username
(
identifier
)
if
user
=
User
.
find_by
(
username:
identifier
)
link_to
(
"@
#{
identifier
}
"
,
user_url
(
identifier
),
html_options
.
merge
(
class:
"gfm gfm-team_member
#{
html_options
[
:class
]
}
"
))
options
=
html_options
.
merge
(
class:
"gfm gfm-team_member
#{
html_options
[
:class
]
}
"
)
link_to
(
"@
#{
identifier
}
"
,
user_url
(
identifier
),
options
)
end
end
end
end
def
reference_issue
(
identifier
)
def
reference_issue
(
identifier
,
project
=
@project
)
if
@
project
.
used_default_issues_tracker?
||
!
external_issues_tracker_enabled?
if
project
.
used_default_issues_tracker?
||
!
external_issues_tracker_enabled?
if
@
project
.
issue_exists?
identifier
if
project
.
issue_exists?
identifier
url
=
url_for_issue
(
identifier
)
url
=
url_for_issue
(
identifier
,
project
)
title
=
title_for_issue
(
identifier
)
title
=
title_for_issue
(
identifier
)
options
=
html_options
.
merge
(
title:
"Issue:
#{
title
}
"
,
class:
"gfm gfm-issue
#{
html_options
[
:class
]
}
"
)
link_to
(
"#
#{
identifier
}
"
,
url
,
html_options
.
merge
(
title:
"Issue:
#{
title
}
"
,
class:
"gfm gfm-issue
#{
html_options
[
:class
]
}
"
)
)
link_to
(
"#
#{
identifier
}
"
,
url
,
options
)
end
end
els
e
els
if
project
.
issues_tracker
==
'jira'
reference_jira_issue
(
identifier
)
if
@project
.
issues_tracker
==
"jira"
reference_jira_issue
(
identifier
,
project
)
end
end
end
end
def
reference_merge_request
(
identifier
)
def
reference_merge_request
(
identifier
,
project
=
@project
)
if
merge_request
=
@project
.
merge_requests
.
where
(
iid:
identifier
).
first
if
merge_request
=
project
.
merge_requests
.
find_by
(
iid:
identifier
)
link_to
(
"!
#{
identifier
}
"
,
project_merge_request_url
(
@project
,
merge_request
),
html_options
.
merge
(
title:
"Merge Request:
#{
merge_request
.
title
}
"
,
class:
"gfm gfm-merge_request
#{
html_options
[
:class
]
}
"
))
options
=
html_options
.
merge
(
title:
"Merge Request:
#{
merge_request
.
title
}
"
,
class:
"gfm gfm-merge_request
#{
html_options
[
:class
]
}
"
)
url
=
project_merge_request_url
(
project
,
merge_request
)
link_to
(
"!
#{
identifier
}
"
,
url
,
options
)
end
end
end
end
def
reference_snippet
(
identifier
)
def
reference_snippet
(
identifier
,
project
=
@project
)
if
snippet
=
@project
.
snippets
.
where
(
id:
identifier
).
first
if
snippet
=
project
.
snippets
.
find_by
(
id:
identifier
)
link_to
(
"$
#{
identifier
}
"
,
project_snippet_url
(
@project
,
snippet
),
html_options
.
merge
(
title:
"Snippet:
#{
snippet
.
title
}
"
,
class:
"gfm gfm-snippet
#{
html_options
[
:class
]
}
"
))
options
=
html_options
.
merge
(
title:
"Snippet:
#{
snippet
.
title
}
"
,
class:
"gfm gfm-snippet
#{
html_options
[
:class
]
}
"
)
link_to
(
"$
#{
identifier
}
"
,
project_snippet_url
(
project
,
snippet
),
options
)
end
end
end
end
def
reference_commit
(
identifier
)
def
reference_commit
(
identifier
,
project
=
@project
)
if
@project
.
valid_repo?
&&
commit
=
@project
.
repository
.
commit
(
identifier
)
if
project
.
valid_repo?
&&
commit
=
project
.
repository
.
commit
(
identifier
)
link_to
(
identifier
,
project_commit_url
(
@project
,
commit
),
html_options
.
merge
(
title:
commit
.
link_title
,
class:
"gfm gfm-commit
#{
html_options
[
:class
]
}
"
))
options
=
html_options
.
merge
(
title:
commit
.
link_title
,
class:
"gfm gfm-commit
#{
html_options
[
:class
]
}
"
)
link_to
(
identifier
,
project_commit_url
(
project
,
commit
),
options
)
end
end
end
end
def
reference_jira_issue
(
identifier
)
def
reference_jira_issue
(
identifier
,
project
=
@project
)
url
=
url_for_issue
(
identifier
)
url
=
url_for_issue
(
identifier
)
title
=
Gitlab
.
config
.
issues_tracker
[
@project
.
issues_tracker
][
"title"
]
title
=
Gitlab
.
config
.
issues_tracker
[
@project
.
issues_tracker
][
"title"
]
link_to
(
"
#{
identifier
}
"
,
url
,
html_options
.
merge
(
title:
"Issue in
#{
title
}
"
,
class:
"gfm gfm-issue
#{
html_options
[
:class
]
}
"
))
options
=
html_options
.
merge
(
title:
"Issue in
#{
title
}
"
,
class:
"gfm gfm-issue
#{
html_options
[
:class
]
}
"
)
link_to
(
"
#{
identifier
}
"
,
url
,
options
)
end
end
end
end
end
end
lib/gitlab/reference_extractor.rb
View file @
9c046fea
...
@@ -51,7 +51,7 @@ module Gitlab
...
@@ -51,7 +51,7 @@ module Gitlab
private
private
def
reference_link
type
,
identifier
def
reference_link
(
type
,
identifier
,
project
)
# Append identifier to the appropriate collection.
# Append identifier to the appropriate collection.
send
(
"
#{
type
}
s"
)
<<
identifier
send
(
"
#{
type
}
s"
)
<<
identifier
end
end
...
...
spec/helpers/gitlab_markdown_helper_spec.rb
View file @
9c046fea
...
@@ -41,7 +41,8 @@ describe GitlabMarkdownHelper do
...
@@ -41,7 +41,8 @@ describe GitlabMarkdownHelper do
end
end
it
"should forward HTML options to links"
do
it
"should forward HTML options to links"
do
gfm
(
"Fixed in
#{
commit
.
id
}
"
,
class:
"foo"
).
should
have_selector
(
"a.gfm.foo"
)
gfm
(
"Fixed in
#{
commit
.
id
}
"
,
@project
,
class:
'foo'
).
should
have_selector
(
'a.gfm.foo'
)
end
end
describe
"referencing a commit"
do
describe
"referencing a commit"
do
...
...
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