Commit 443e21ed92aee684ce7b6581ac30566787e091a8

Authored by Cedric Gatay
1 parent fbf412ea

Autolinks to issues in commit message (see #155)

It matches #[0-9]+ in commit messages.
For example
 * Fix for #12
 * Code review for #56
 * Test for #15, Review on #54, Fix for #42

 It only links to valid issues (existing and belonging to the current project)
 It does not add any link to the commit in the issue page, it only consists in parsing the commit message when displayed.

 This can be considere as a primary work for the issue #155 on gitlabhq/gitlabhq.
app/helpers/commits_helper.rb
... ... @@ -23,4 +23,23 @@ module CommitsHelper
23 23 link_to "More", project_commits_path(@project, :offset => offset.to_i + limit.to_i, :limit => limit),
24 24 :remote => true, :class => "lite_button vm", :style => "text-align:center; width:930px; ", :id => "more-commits-link"
25 25 end
  26 +
  27 + def commit_msg_with_link_to_issues
  28 + out = ""
  29 + @commit.safe_message.split(/(#[0-9]+)/m).each do |m|
  30 + if m =~ /(#([0-9]+))/m
  31 + begin
  32 + issue = Issue.find($2)
  33 + raise Exception('Issue not belonging to current project, not creating link !') unless issue.project_id == @project.id
  34 + out+=link_to($1, project_issue_path(@project, $2))
  35 + rescue
  36 + out+=$1
  37 + end
  38 + else
  39 + out+= m
  40 + end
  41 + end
  42 + out
  43 + end
  44 +
26 45 end
... ...
app/views/commits/show.html.haml
... ... @@ -18,8 +18,7 @@
18 18  
19 19 %hr
20 20 %pre.commit_message
21   - = preserve @commit.safe_message
22   -
  21 + = preserve get_commit_message_with_link_to_issues
23 22 .clear
24 23 %br
25 24  
... ...