##// END OF EJS Templates
Adds support for cross project Redmine links (#7409)....
Jean-Philippe Lang -
r4638:777ccf1328c9
parent child
Show More
@@ -588,16 +588,25 module ApplicationHelper
588 # source:some/file#L120 -> Link to line 120 of the file
588 # source:some/file#L120 -> Link to line 120 of the file
589 # source:some/file@52#L120 -> Link to line 120 of the file's revision 52
589 # source:some/file@52#L120 -> Link to line 120 of the file's revision 52
590 # export:some/file -> Force the download of the file
590 # export:some/file -> Force the download of the file
591 # Forum messages:
591 # Forum messages:
592 # message#1218 -> Link to message with id 1218
592 # message#1218 -> Link to message with id 1218
593 #
594 # Links can refer other objects from other projects, using project identifier:
595 # identifier:r52
596 # identifier:document:"Some document"
597 # identifier:version:1.0.0
598 # identifier:source:some/file
593 def parse_redmine_links(text, project, obj, attr, only_path, options)
599 def parse_redmine_links(text, project, obj, attr, only_path, options)
594 text.gsub!(%r{([\s\(,\-\[\>]|^)(!)?(attachment|document|version|commit|source|export|message|project)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|\]|<|$)}) do |m|
600 text.gsub!(%r{([\s\(,\-\[\>]|^)(!)?(([a-z0-9\-]+):)?(attachment|document|version|commit|source|export|message|project)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|\]|<|$)}) do |m|
595 leading, esc, prefix, sep, identifier = $1, $2, $3, $5 || $7, $6 || $8
601 leading, esc, project_prefix, project_identifier, prefix, sep, identifier = $1, $2, $3, $4, $5, $7 || $9, $8 || $10
596 link = nil
602 link = nil
603 if project_identifier
604 project = Project.visible.find_by_identifier(project_identifier)
605 end
597 if esc.nil?
606 if esc.nil?
598 if prefix.nil? && sep == 'r'
607 if prefix.nil? && sep == 'r'
599 if project && (changeset = project.changesets.find_by_revision(identifier))
608 if project && (changeset = project.changesets.find_by_revision(identifier))
600 link = link_to("r#{identifier}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision},
609 link = link_to("#{project_prefix}r#{identifier}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision},
601 :class => 'changeset',
610 :class => 'changeset',
602 :title => truncate_single_line(changeset.comments, :length => 100))
611 :title => truncate_single_line(changeset.comments, :length => 100))
603 end
612 end
@@ -651,7 +660,7 module ApplicationHelper
651 end
660 end
652 when 'commit'
661 when 'commit'
653 if project && (changeset = project.changesets.find(:first, :conditions => ["scmid LIKE ?", "#{name}%"]))
662 if project && (changeset = project.changesets.find(:first, :conditions => ["scmid LIKE ?", "#{name}%"]))
654 link = link_to h("#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.identifier},
663 link = link_to h("#{project_prefix}#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.identifier},
655 :class => 'changeset',
664 :class => 'changeset',
656 :title => truncate_single_line(changeset.comments, :length => 100)
665 :title => truncate_single_line(changeset.comments, :length => 100)
657 end
666 end
@@ -659,7 +668,7 module ApplicationHelper
659 if project && project.repository
668 if project && project.repository
660 name =~ %r{^[/\\]*(.*?)(@([0-9a-f]+))?(#(L\d+))?$}
669 name =~ %r{^[/\\]*(.*?)(@([0-9a-f]+))?(#(L\d+))?$}
661 path, rev, anchor = $1, $3, $5
670 path, rev, anchor = $1, $3, $5
662 link = link_to h("#{prefix}:#{name}"), {:controller => 'repositories', :action => 'entry', :id => project,
671 link = link_to h("#{project_prefix}#{prefix}:#{name}"), {:controller => 'repositories', :action => 'entry', :id => project,
663 :path => to_path_param(path),
672 :path => to_path_param(path),
664 :rev => rev,
673 :rev => rev,
665 :anchor => anchor,
674 :anchor => anchor,
@@ -679,7 +688,7 module ApplicationHelper
679 end
688 end
680 end
689 end
681 end
690 end
682 leading + (link || "#{prefix}#{sep}#{identifier}")
691 leading + (link || "#{project_prefix}#{prefix}#{sep}#{identifier}")
683 end
692 end
684 end
693 end
685
694
@@ -46,7 +46,9
46 <ul>
46 <ul>
47 <li>Link to an issue: <strong>#124</strong> (displays <del><a href="#" class="issue" title="bulk edit doesn't change the category or fixed version properties (Closed)">#124</a></del>, link is striked-through if the issue is closed)</li>
47 <li>Link to an issue: <strong>#124</strong> (displays <del><a href="#" class="issue" title="bulk edit doesn't change the category or fixed version properties (Closed)">#124</a></del>, link is striked-through if the issue is closed)</li>
48 <li>Link to a changeset: <strong>r758</strong> (displays <a href="#" class="changeset" title="Search engine now only searches objects the user is allowed to view.">r758</a>)</li>
48 <li>Link to a changeset: <strong>r758</strong> (displays <a href="#" class="changeset" title="Search engine now only searches objects the user is allowed to view.">r758</a>)</li>
49 <li>Link to a changeset with a non-numeric hash: <strong>commit:c6f4d0fd</strong> (displays c6f4d0fd). Added in <a href="#" class="changeset" title="Merged Git support branch (r1200 to r1226).">r1236</a>.</li>
49 <li>Link to a changeset with a non-numeric hash: <strong>commit:c6f4d0fd</strong> (displays <a href="#" class="changeset">c6f4d0fd</a>).</li>
50 <li>Link to a changeset of another project: <strong>sandbox:r758</strong> (displays <a href="#" class="changeset" title="Search engine now only searches objects the user is allowed to view.">sanbox:r758</a>)</li>
51 <li>Link to a changeset with a non-numeric hash: <strong>sandbox:c6f4d0fd</strong> (displays <a href="#" class="changeset">sandbox:c6f4d0fd</a>).</li>
50 </ul>
52 </ul>
51
53
52 <p>Wiki links:</p>
54 <p>Wiki links:</p>
@@ -74,7 +76,7
74 <li><strong>document#17</strong> (link to document with id 17)</li>
76 <li><strong>document#17</strong> (link to document with id 17)</li>
75 <li><strong>document:Greetings</strong> (link to the document with title "Greetings")</li>
77 <li><strong>document:Greetings</strong> (link to the document with title "Greetings")</li>
76 <li><strong>document:"Some document"</strong> (double quotes can be used when document title contains spaces)</li>
78 <li><strong>document:"Some document"</strong> (double quotes can be used when document title contains spaces)</li>
77 <li><strong>document:some_project:"Some document"</strong> (link to a document with title "Some document" in other project "some_project")
79 <li><strong>sandbox:document:"Some document"</strong> (link to a document with title "Some document" in other project "sandbox")</li>
78 </ul></li>
80 </ul></li>
79 </ul>
81 </ul>
80
82
@@ -84,6 +86,7
84 <li><strong>version#3</strong> (link to version with id 3)</li>
86 <li><strong>version#3</strong> (link to version with id 3)</li>
85 <li><strong>version:1.0.0</strong> (link to version named "1.0.0")</li>
87 <li><strong>version:1.0.0</strong> (link to version named "1.0.0")</li>
86 <li><strong>version:"1.0 beta 2"</strong></li>
88 <li><strong>version:"1.0 beta 2"</strong></li>
89 <li><strong>sandbox:version:1.0.0</strong> (link to version "1.0.0" in the project "sandbox")</li>
87 </ul></li>
90 </ul></li>
88 </ul>
91 </ul>
89
92
@@ -103,7 +106,9
103 <li><strong>source:some/file#L120</strong> (link to line 120 of the file)</li>
106 <li><strong>source:some/file#L120</strong> (link to line 120 of the file)</li>
104 <li><strong>source:some/file@52#L120</strong> (link to line 120 of the file's revision 52)</li>
107 <li><strong>source:some/file@52#L120</strong> (link to line 120 of the file's revision 52)</li>
105 <li><strong>source:"some file@52#L120"</strong> (use double quotes when the URL contains spaces</li>
108 <li><strong>source:"some file@52#L120"</strong> (use double quotes when the URL contains spaces</li>
106 <li><strong>export:some/file</strong> (force the download of the file)</li>
109 <li><strong>export:some/file</strong> (force the download of the file)</li>
110 <li><strong>sandbox:source:some/file</strong> (link to the file located at /some/file in the repository of the project "sandbox")</li>
111 <li><strong>sandbox:export:some/file</strong> (force the download of the file)</li>
107 </ul></li>
112 </ul></li>
108 </ul>
113 </ul>
109
114
@@ -224,6 +224,35 RAW
224 @project = Project.find(1)
224 @project = Project.find(1)
225 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" }
225 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" }
226 end
226 end
227
228 def test_cross_project_redmine_links
229 source_link = link_to('ecookbook:source:/some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']},
230 :class => 'source')
231
232 changeset_link = link_to('ecookbook:r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2},
233 :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3')
234
235 to_test = {
236 # documents
237 'document:"Test document"' => 'document:"Test document"',
238 'ecookbook:document:"Test document"' => '<a href="/documents/1" class="document">Test document</a>',
239 'invalid:document:"Test document"' => 'invalid:document:"Test document"',
240 # versions
241 'version:"1.0"' => 'version:"1.0"',
242 'ecookbook:version:"1.0"' => '<a href="/versions/show/2" class="version">1.0</a>',
243 'invalid:version:"1.0"' => 'invalid:version:"1.0"',
244 # changeset
245 'r2' => 'r2',
246 'ecookbook:r2' => changeset_link,
247 'invalid:r2' => 'invalid:r2',
248 # source
249 'source:/some/file' => 'source:/some/file',
250 'ecookbook:source:/some/file' => source_link,
251 'invalid:source:/some/file' => 'invalid:source:/some/file',
252 }
253 @project = Project.find(3)
254 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" }
255 end
227
256
228 def test_redmine_links_git_commit
257 def test_redmine_links_git_commit
229 changeset_link = link_to('abcd',
258 changeset_link = link_to('abcd',
General Comments 0
You need to be logged in to leave comments. Login now