Sha256: 5c3450e8be2544ad9b1bc8cfc019a0fadc1e177fd078a80f8d1de64d4d049829

Contents?: true

Size: 1.91 KB

Versions: 4

Compression:

Stored size: 1.91 KB

Contents

#!/usr/bin/env ruby
#
# Forked from:
# Henrik Nyh <http://henrik.nyh.se> 2009-09-10 under the MIT License.
#
#
# Install:
#
# cd your_project
# stick it in .git/hooks/commit-msg && chmod u+x .git/hooks/commit-msg
#
# Or store it centrally and symlink in your projects:
# TODO Replace ~./.githooks etc with the file location in the gem
#  ~/.githooks/commit-msg && chmod u+x ~/.githooks/commit-msg
# cd your_project
#  ~/.githooks/commit-msg .git/hooks

require 'rubygems'
require 'yaml'

# Custom method to check for installed redmine_stagecoach gem
def gem_available?(name)
   Gem::Specification.find_by_name(name)
rescue Gem::LoadError
   false
rescue
   Gem.available?(name)
end

if gem_available?('redmine_stagecoach') == false
  exit
else
  config = YAML::load(File.open(File.dirname(__FILE__) + '/../../.stagecoach~', 'r'))
end

# Find out what branch we are on
def branches
  `git branch`.split("\n")
end

def current_branch
  branches.each do |b|
    if b =~ /\*/
      return b[1..-1].strip
    end
  end
end


# And now the git hook stuff

FLAGS = [
  NOREF  = "noref",
  UP_NOREF = "Noref",
  CAPS_NOREF = "NOREF",
  CLOSE  = "close",
  UP_CLOSE= "Close",
  CAPS_CLOSE= "CLOSE"
]

NO_REFERENCE_FLAGS = [ NOREF, UP_NOREF, CAPS_NOREF  ]
CLOSING_FLAGS = [ CLOSE, UP_CLOSE, CAPS_CLOSE ]

begin
ticket_number = config[current_branch][:github_issue]
rescue
  exit
end
finish    = "Closes #%s" % ticket_number
reference = "#%s"   % ticket_number

message_file = ARGV[0]
message = File.read(message_file).strip
exit if message.include?("##{ticket_number}")
exit if message =~ /#\d+/

# Determine if any of the flags are included. Make a note of which and then remove it.
message.sub!(/(?:^|\s)#(#{Regexp.union(*FLAGS)})\b/, '')
flag = $1

message =
  case flag
  when *NO_REFERENCE_FLAGS
    message
  when *CLOSE
    [ message, finish ].join(" ")
  else
    [ message, reference ].join(" ")
  end

File.open(message_file, 'w') {|f| f.write message }

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
redmine_stagecoach-0.6.10 lib/githooks/commit-msg
redmine_stagecoach-0.6.9 lib/githooks/commit-msg
redmine_stagecoach-0.6.8 lib/githooks/commit-msg
redmine_stagecoach-0.6.7 lib/githooks/commit-msg