Feature #3346

Support for cross-project revision links

Added by James Wells over 8 years ago. Updated over 5 years ago.

Status:ClosedStart date:2009-05-12
Priority:NormalDue date:
Assignee:-% Done:

100%

Category:Text formatting
Target version:-
Resolution:Duplicate

Description

It may sometimes be useful to be able to reference a specific repository revision in one project from another project, for example if an issue is partially addressed by a change in a sub-project. Whereas a revision link can be done with !r1234, a cross-project link could be done with r:project:1234.

The following patch shows how this could be done with relatively little change (although I haven't done much testing as to whether or not it breaks any other linking):

  Index: app/helpers/application_helper.rb
  ===================================================================
  --- app/helpers/application_helper.rb   (revision 2717)
  +++ app/helpers/application_helper.rb   (working copy)
  @@ -385,15 +385,25 @@
       #     export:some/file -> Force the download of the file
       #  Forum messages:
       #     message#1218 -> Link to message with id 1218
  -    text = text.gsub(%r{([\s\(,\-\>]|^)(!)?(attachment|document|version|commit|source|export|message)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|\s|<|$)}) do |m|
  -      leading, esc, prefix, sep, oid = $1, $2, $3, $5 || $7, $6 || $8
  +    text = text.gsub(%r{([\s\(,\-\>]|^)(!)?(attachment|document|version|commit|source|export|message)?((#|r)(\:[^\:\s]+\:)?(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|\s|<|$)}) do |m|
  +      leading, esc, prefix, sep, revproj, oid = $1, $2, $3, $5 || $8, $6, $7 || $9
         link = nil
         if esc.nil?
           if prefix.nil? && sep == 'r'
  -          if project && (changeset = project.changesets.find_by_revision(oid))
  -            link = link_to("r#{oid}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => oid},
  +          if revproj.nil?
  +            if project && (changeset = project.changesets.find_by_revision(oid))
  +               link = link_to("r#{oid}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => oid},
  +                                       :class => 'changeset',
  +                                       :title => truncate_single_line(changeset.comments, 100))
  +            end
  +          else
  +            revproj.gsub!(/\:/,'')
  +            link_project = Project.find_by_name(revproj) || Project.find_by_identifier(revproj)
  +            if link_project && (changeset = link_project.changesets.find_by_revision(oid))
  +              link = link_to("r:#{revproj}:#{oid}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => link_project, :rev => oid},
                                         :class => 'changeset',
                                         :title => truncate_single_line(changeset.comments, 100))
  +            end
             end
           elsif sep == '#'
             oid = oid.to_i

3346.diff Magnifier (2.26 KB) James Wells, 2009-05-12 22:14

cross-project_revision_and_commit_links_v1.diff Magnifier - Support for cross-project revision and commit links v1 (4.17 KB) Babar O'Cap, 2009-08-18 12:39

cross-project_revision_and_commit_links_v2.diff Magnifier - Support for cross-project revision and commit links v2 (6.68 KB) Babar O'Cap, 2009-08-18 17:22

cross-project_revision_and_commit_links_v2.1.diff Magnifier - Patch v2.1 - accidentally revert r2833 in v2 (6.34 KB) Babar O'Cap, 2009-08-18 18:08

cross-project_revision_and_commit_links_v3.diff Magnifier - Patch v3 - Fix link_to_if_authorized and link_to_remote_if_authorized helpers because it breaks contextual links (5.3 KB) Babar O'Cap, 2009-08-20 09:26

cross-project_revision_and_commit_links_v4.diff Magnifier - Patch v4 - Adding unit tests and wiki syntax help - compatible with r2845 (12.1 KB) Babar O'Cap, 2009-08-20 12:31

cross-project_revision_and_commit_links_v5.diff Magnifier - Patch v5 - New wiki syntax, compatible with r2847 (11.9 KB) Babar O'Cap, 2009-08-26 10:27


Related issues

Related to Redmine - Defect #3087: Revision referring to issues across all projects Closed 2009-03-31
Related to Redmine - Feature #779: Multiple SCM per project Closed 2008-03-04
Related to Redmine - Feature #4052: Cross-project redmine links with alternate link text for ... New 2009-10-19
Duplicated by Redmine - Feature #3216: Reference to a revision from an other project Closed 2009-04-21
Duplicates Redmine - Feature #7409: Cross project Redmine links Closed 2011-01-22

History

#1 Updated by James Wells over 8 years ago

Also attached the diff as a file.

#2 Updated by Babar O'Cap about 8 years ago

Thanks James Wells.
I've updated your patch to be compatible with r2833 and fix some bugs on project name with spaces (eg: r:My Project name:52).
It's also support cross-project commit links (eg: commit:project:a85130f)

Can we merge this patch with the trunk ?

Maybe I'll be updating others Redmine links to support cross-project links.

#3 Updated by Babar O'Cap about 8 years ago

Here a bugs and security fix of my patch

#5 Updated by Mischa The Evil about 8 years ago

Thanks for your patches Babar. It seems a useful feature to me...

#6 Updated by Babar O'Cap about 8 years ago

#7 Updated by Babar O'Cap about 8 years ago

#8 Updated by Babar O'Cap about 8 years ago

Know bugs : project name and identifier must have at least 3 characters.
I'll rework the regular expression to avoid this problem.

#9 Updated by Babar O'Cap about 8 years ago

New wiki syntax, more intuitive :
project:r52 -> Link to revision 52 of an other project, using project name or identifier
project:commit:a85130f -> Link to scmid starting with a85130f of an other project, using project name or identifier

If your project name contains spaces, use quotation marks :
"My Project":r52
"My Project":commit:a85130f

Now a project name can have at least 1 character.

#10 Updated by James Wells about 8 years ago

Thanks for all the additional work on this, very much appreciated. Let me know if there is anything I can do to help.

#11 Updated by William Baum almost 8 years ago

James and Babar, that you so much for this.

I really needed cross project source: and export: links, and I also wanted alternate link text instead of "source:/whatever/this/that/file.doc" links, so I have extended your project: syntax to source: and export: links and added the alternate text functionality. I also fixed the source: and export: links so they work properly in email notifications.

I have posted this in Feature #4052.

It seemed enough different to warrant a new Feature, but it's clearly derivative of your work in this issue.

--Bill

#12 Updated by Babar O'Cap almost 8 years ago

  • % Done changed from 80 to 100

#13 Updated by Balázs Pozsár over 7 years ago

Was this patch merged upstream?

#14 Updated by Babar O'Cap over 7 years ago

Balázs Pozsár wrote:

Was this patch merged upstream?

I don't think so, see issues #4052 to have an updated patch.

#15 Updated by Gilles Cornu about 6 years ago

+1. it would be nice that reference commit keywords (like refs, fixes,...) also supports cross-project/SCM.

#16 Updated by Anthony Topper almost 6 years ago

+1. I would love to see this in the next version.

#17 Updated by Jean-Philippe Lang over 5 years ago

  • Status changed from New to Closed
  • Resolution set to Duplicate

Actually this feature was added in 1.2.0. See #7409.

Also available in: Atom PDF