From 980eebc6c5cc0e5cf6033952888a3cc7b11e9e10 Mon Sep 17 00:00:00 2001 From: Jens Kraemer Date: Thu, 30 Aug 2018 12:37:55 +0800 Subject: [PATCH 1/3] adds ##123 extended issue linking syntax --- app/helpers/application_helper.rb | 21 +++++++++++++++------ test/helpers/application_helper_test.rb | 11 +++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 58b988454..546080386 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -830,6 +830,7 @@ module ApplicationHelper # Examples: # Issues: # #52 -> Link to issue #52 + # ##52 -> Link to issue #52, including the issue's subject # Changesets: # r52 -> Link to revision 52 # commit:a85130f -> Link to scmid starting with a85130f @@ -917,17 +918,25 @@ module ApplicationHelper :title => truncate_single_line_raw(changeset.comments, 100)) end end - elsif sep == '#' + elsif sep == '#' || sep == '##' oid = identifier.to_i case prefix when nil if oid.to_s == identifier && issue = Issue.visible.find_by_id(oid) anchor = comment_id ? "note-#{comment_id}" : nil - link = link_to("##{oid}#{comment_suffix}", - issue_url(issue, :only_path => only_path, :anchor => anchor), - :class => issue.css_classes, - :title => "#{issue.tracker.name}: #{issue.subject.truncate(100)} (#{issue.status.name})") + url = issue_url(issue, :only_path => only_path, :anchor => anchor) + link = if sep == '##' + link_to("#{issue.tracker.name} ##{oid}#{comment_suffix}", + url, + :class => issue.css_classes, + :title => "#{issue.tracker.name}: #{issue.subject.truncate(100)} (#{issue.status.name})") + ": #{issue.subject}" + else + link_to("##{oid}#{comment_suffix}", + url, + :class => issue.css_classes, + :title => "#{issue.tracker.name}: #{issue.subject.truncate(100)} (#{issue.status.name})") + end end when 'document' if document = Document.visible.find_by_id(oid) @@ -1038,7 +1047,7 @@ module ApplicationHelper (?attachment|document|version|forum|news|message|project|commit|source|export|user)? ( ( - (?\#)| + (?\#\#?)| ( (?(?[a-z0-9\-_]+)\|)? (?r) diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb index aa403be46..0a4c32077 100644 --- a/test/helpers/application_helper_test.rb +++ b/test/helpers/application_helper_test.rb @@ -290,10 +290,16 @@ RAW issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3}, :class => Issue.find(3).css_classes, :title => 'Bug: Error 281 when updating a recipe (New)') + ext_issue_link = link_to('Bug #3', {:controller => 'issues', :action => 'show', :id => 3}, + :class => Issue.find(3).css_classes, :title => 'Bug: Error 281 when updating a recipe (New)') + ": Error 281 when updating a recipe" note_link = link_to('#3-14', {:controller => 'issues', :action => 'show', :id => 3, :anchor => 'note-14'}, :class => Issue.find(3).css_classes, :title => 'Bug: Error 281 when updating a recipe (New)') + ext_note_link = link_to('Bug #3-14', {:controller => 'issues', :action => 'show', :id => 3, :anchor => 'note-14'}, + :class => Issue.find(3).css_classes, :title => 'Bug: Error 281 when updating a recipe (New)') + ": Error 281 when updating a recipe" note_link2 = link_to('#3#note-14', {:controller => 'issues', :action => 'show', :id => 3, :anchor => 'note-14'}, :class => Issue.find(3).css_classes, :title => 'Bug: Error 281 when updating a recipe (New)') + ext_note_link2 = link_to('Bug #3#note-14', {:controller => 'issues', :action => 'show', :id => 3, :anchor => 'note-14'}, + :class => Issue.find(3).css_classes, :title => 'Bug: Error 281 when updating a recipe (New)') + ": Error 281 when updating a recipe" revision_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :repository_id => 10, :rev => 1}, :class => 'changeset', :title => 'My very first commit do not escaping #<>&') @@ -338,6 +344,11 @@ RAW '#3#note-14' => note_link2, # should not ignore leading zero '#03' => '#03', + # tickets with more info + '##3, [##3], (##3) and ##3.' => "#{ext_issue_link}, [#{ext_issue_link}], (#{ext_issue_link}) and #{ext_issue_link}.", + '##3-14' => ext_note_link, + '##3#note-14' => ext_note_link2, + '##03' => '##03', # changesets 'r1' => revision_link, 'r1.' => "#{revision_link}.", -- 2.11.0