Feature #2715 ยป issue_note_link.patch
| app/helpers/application_helper.rb (working copy) | ||
|---|---|---|
|
# Examples:
|
||
|
# Issues:
|
||
|
# #52 -> Link to issue #52
|
||
|
# #52-2 -> Link to note 2 of issue #52
|
||
|
# Changesets:
|
||
|
# r52 -> Link to revision 52
|
||
|
# commit:a85130f -> Link to scmid starting with a85130f
|
||
| ... | ... | |
|
# identifier:version:1.0.0
|
||
|
# identifier:source:some/file
|
||
|
def parse_redmine_links(text, project, obj, attr, only_path, options)
|
||
|
text.gsub!(%r{([\s\(,\-\[\>]|^)(!)?(([a-z0-9\-]+):)?(attachment|document|version|commit|source|export|message|project)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|\]|<|$)}) do |m|
|
||
|
leading, esc, project_prefix, project_identifier, prefix, sep, identifier = $1, $2, $3, $4, $5, $7 || $9, $8 || $10
|
||
|
text.gsub!(%r{([\s\(,\-\[\>]|^)(!)?(([a-z0-9\-]+):)?(attachment|document|version|commit|source|export|message|project)?((#|r)(\d+)(-(\d+))?|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|\]|<|$)}) do |m|
|
||
|
leading, esc, project_prefix, project_identifier, prefix, sep, note_index, identifier = $1, $2, $3, $4, $5, $7 || $11, $10, $8 || $12
|
||
|
link = nil
|
||
|
if project_identifier
|
||
|
project = Project.visible.find_by_identifier(project_identifier)
|
||
| ... | ... | |
|
case prefix
|
||
|
when nil
|
||
|
if issue = Issue.visible.find_by_id(oid, :include => :status)
|
||
|
link = link_to("##{oid}", {:only_path => only_path, :controller => 'issues', :action => 'show', :id => oid},
|
||
|
note_anchor, nidx = nil, nil
|
||
|
if note_index
|
||
|
nidx = note_index.to_i
|
||
|
note_anchor = "note-#{nidx}" if issue.journals.first( :order => "#{Journal.table_name}.created_on ASC", :offset => nidx - 1)
|
||
|
end
|
||
|
link = link_to("##{oid}#{nidx ? "-#{nidx}" : ''}", {:only_path => only_path, :controller => 'issues', :action => 'show', :id => oid, :anchor => note_anchor},
|
||
|
:class => issue.css_classes,
|
||
|
:title => "#{truncate(issue.subject, :length => 100)} (#{issue.status.name})")
|
||
|
end
|
||
| test/unit/helpers/application_helper_test.rb (working copy) | ||
|---|---|---|
|
def test_redmine_links
|
||
|
issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3},
|
||
|
:class => 'issue status-1 priority-1 overdue', :title => 'Error 281 when updating a recipe (New)')
|
||
|
|
||
|
|
||
|
issue_note_link = link_to('#1-2', {:controller => 'issues', :action => 'show', :id => 1, :anchor => 'note-2'},
|
||
|
:class => 'issue status-1 priority-1', :title => 'Can\'t print recipes (New)')
|
||
|
|
||
|
issue_with_non_existent_note_link = link_to('#1-6', {:controller => 'issues', :action => 'show', :id => 1},
|
||
|
:class => 'issue status-1 priority-1', :title => 'Can\'t print recipes (New)')
|
||
|
|
||
|
changeset_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1},
|
||
|
:class => 'changeset', :title => 'My very first commit')
|
||
|
changeset_link2 = link_to('r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2},
|
||
| ... | ... | |
|
|
||
|
source_url = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']}
|
||
|
source_url_with_ext = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file.ext']}
|
||
|
|
||
|
|
||
|
to_test = {
|
||
|
# tickets
|
||
|
# tickets and notes
|
||
|
'#3, [#3], (#3) and #3.' => "#{issue_link}, [#{issue_link}], (#{issue_link}) and #{issue_link}.",
|
||
|
'#1-2, [#1-2], (#1-2) and #1-2.' => "#{issue_note_link}, [#{issue_note_link}], (#{issue_note_link}) and #{issue_note_link}.",
|
||
|
'#1-6' => "#{issue_with_non_existent_note_link}",
|
||
|
# changesets
|
||
|
'r1' => changeset_link,
|
||
|
'r1.' => "#{changeset_link}.",
|
||