Skip to content

Instantly share code, notes, and snippets.

@okamototk
Created April 1, 2012 10:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save okamototk/09e40d057b1565cdafab to your computer and use it in GitHub Desktop.
Save okamototk/09e40d057b1565cdafab to your computer and use it in GitHub Desktop.
Redmine branch-ticket relation(like hoge-123 branch relate to ticket 123).
--- lib/redmine/scm/adapters/git_adapter.rb.bak 2012-03-31 14:54:25.278934780 +0900
+++ lib/redmine/scm/adapters/git_adapter.rb 2012-04-01 10:52:29.141915492 +0900
@@ -187,6 +187,27 @@
nil
end
+ def commit_branch(commit)
+ latest_line = ''
+ cmd_brargs = %w|branch --contains|
+ cmd_brargs << commit
+ scm_cmd *cmd_brargs do |io|
+ io.each_line do |line|
+ latest_line = line
+ logger.info("line: #{line}")
+ if (line =~ /\* (\w+-([0-9]+))$/) && ($2 != nil)
+ logger.info("detect branch: #{$2}")
+ return $2
+ end
+ end
+ end
+ if (latest_line =~ /\ (\w+-([0-9]+))$/) && ($2 != nil)
+ logger.info("detect branch: #{$2}")
+ return $2
+ end
+ nil
+ end
+
def revisions(path, identifier_from, identifier_to, options={})
revs = Revisions.new
cmd_args = %w|log --no-color --encoding=UTF-8 --raw --date=iso --pretty=fuller --parents|
@@ -266,6 +287,11 @@
end
if changeset[:commit]
+ cb = commit_branch(changeset[:commit])
+ if cb
+ changeset[:description] = changeset[:description] << "(refs #" << cb << ")"
+ logger.info("description: #{changeset[:description].to_s}")
+ end
revision = Revision.new({
:identifier => changeset[:commit],
:scmid => changeset[:commit],
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment