Feature #2715 ยป issue_note_link.patch
app/helpers/application_helper.rb (working copy) | ||
---|---|---|
574 | 574 |
# Examples: |
575 | 575 |
# Issues: |
576 | 576 |
# #52 -> Link to issue #52 |
577 |
# #52-2 -> Link to note 2 of issue #52 |
|
577 | 578 |
# Changesets: |
578 | 579 |
# r52 -> Link to revision 52 |
579 | 580 |
# commit:a85130f -> Link to scmid starting with a85130f |
... | ... | |
602 | 603 |
# identifier:version:1.0.0 |
603 | 604 |
# identifier:source:some/file |
604 | 605 |
def parse_redmine_links(text, project, obj, attr, only_path, options) |
605 |
text.gsub!(%r{([\s\(,\-\[\>]|^)(!)?(([a-z0-9\-]+):)?(attachment|document|version|commit|source|export|message|project)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|\]|<|$)}) do |m|
|
|
606 |
leading, esc, project_prefix, project_identifier, prefix, sep, identifier = $1, $2, $3, $4, $5, $7 || $9, $8 || $10
|
|
606 |
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|
|
|
607 |
leading, esc, project_prefix, project_identifier, prefix, sep, note_index, identifier = $1, $2, $3, $4, $5, $7 || $11, $10, $8 || $12
|
|
607 | 608 |
link = nil |
608 | 609 |
if project_identifier |
609 | 610 |
project = Project.visible.find_by_identifier(project_identifier) |
... | ... | |
621 | 622 |
case prefix |
622 | 623 |
when nil |
623 | 624 |
if issue = Issue.visible.find_by_id(oid, :include => :status) |
624 |
link = link_to("##{oid}", {:only_path => only_path, :controller => 'issues', :action => 'show', :id => oid}, |
|
625 |
note_anchor, nidx = nil, nil |
|
626 |
if note_index |
|
627 |
nidx = note_index.to_i |
|
628 |
note_anchor = "note-#{nidx}" if issue.journals.first( :order => "#{Journal.table_name}.created_on ASC", :offset => nidx - 1) |
|
629 |
end |
|
630 |
link = link_to("##{oid}#{nidx ? "-#{nidx}" : ''}", {:only_path => only_path, :controller => 'issues', :action => 'show', :id => oid, :anchor => note_anchor}, |
|
625 | 631 |
:class => issue.css_classes, |
626 | 632 |
:title => "#{truncate(issue.subject, :length => 100)} (#{issue.status.name})") |
627 | 633 |
end |
test/unit/helpers/application_helper_test.rb (working copy) | ||
---|---|---|
151 | 151 |
def test_redmine_links |
152 | 152 |
issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3}, |
153 | 153 |
:class => 'issue status-1 priority-1 overdue', :title => 'Error 281 when updating a recipe (New)') |
154 |
|
|
154 |
|
|
155 |
issue_note_link = link_to('#1-2', {:controller => 'issues', :action => 'show', :id => 1, :anchor => 'note-2'}, |
|
156 |
:class => 'issue status-1 priority-1', :title => 'Can\'t print recipes (New)') |
|
157 |
|
|
158 |
issue_with_non_existent_note_link = link_to('#1-6', {:controller => 'issues', :action => 'show', :id => 1}, |
|
159 |
:class => 'issue status-1 priority-1', :title => 'Can\'t print recipes (New)') |
|
160 |
|
|
155 | 161 |
changeset_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1}, |
156 | 162 |
:class => 'changeset', :title => 'My very first commit') |
157 | 163 |
changeset_link2 = link_to('r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2}, |
... | ... | |
169 | 175 |
|
170 | 176 |
source_url = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']} |
171 | 177 |
source_url_with_ext = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file.ext']} |
172 |
|
|
178 |
|
|
173 | 179 |
to_test = { |
174 |
# tickets |
|
180 |
# tickets and notes
|
|
175 | 181 |
'#3, [#3], (#3) and #3.' => "#{issue_link}, [#{issue_link}], (#{issue_link}) and #{issue_link}.", |
182 |
'#1-2, [#1-2], (#1-2) and #1-2.' => "#{issue_note_link}, [#{issue_note_link}], (#{issue_note_link}) and #{issue_note_link}.", |
|
183 |
'#1-6' => "#{issue_with_non_existent_note_link}", |
|
176 | 184 |
# changesets |
177 | 185 |
'r1' => changeset_link, |
178 | 186 |
'r1.' => "#{changeset_link}.", |