Skip to content

Commit

Permalink
Autolinks to issues in commit message (see #155)
Browse files Browse the repository at this point in the history
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.


Former-commit-id: 443e21e
  • Loading branch information
CedricGatay committed Dec 26, 2011
1 parent b6a9c13 commit a47374c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
19 changes: 19 additions & 0 deletions app/helpers/commits_helper.rb
Expand Up @@ -23,4 +23,23 @@ def more_commits_link
link_to "More", project_commits_path(@project, :offset => offset.to_i + limit.to_i, :limit => limit),
:remote => true, :class => "lite_button vm", :style => "text-align:center; width:930px; ", :id => "more-commits-link"
end

def commit_msg_with_link_to_issues
out = ""
@commit.safe_message.split(/(#[0-9]+)/m).each do |m|
if m =~ /(#([0-9]+))/m
begin
issue = Issue.find($2)
raise Exception('Issue not belonging to current project, not creating link !') unless issue.project_id == @project.id
out+=link_to($1, project_issue_path(@project, $2))
rescue
out+=$1
end
else
out+= m
end
end
out
end

end
3 changes: 1 addition & 2 deletions app/views/commits/show.html.haml
Expand Up @@ -18,8 +18,7 @@

%hr
%pre.commit_message
= preserve @commit.safe_message

= preserve get_commit_message_with_link_to_issues
.clear
%br

Expand Down

0 comments on commit a47374c

Please sign in to comment.