Class: JiraReferenceCheckHook

Inherits:
RubyGitHooks::Hook show all
Defined in:
lib/ruby_git_hooks/jira_ref_check.rb

Overview

This hook checks that the commit message has one or more correctly-formatted Jira ticket references.

Constant Summary collapse

Hook =
RubyGitHooks::Hook
JIRA_TICKET_REGEXP =
/(?<=\W|^)[A-Z]{2,10}-\d{1,6}(?=\W|$)/

Constants inherited from RubyGitHooks::Hook

RubyGitHooks::Hook::HOOK_INFO, RubyGitHooks::Hook::HOOK_TYPE_SETUP

Instance Method Summary collapse

Methods inherited from RubyGitHooks::Hook

get_hooks_to_run, initial_setup, register, run, run_as_specific_githook, #setup, shell!

Constructor Details

#initialize(options = {}) ⇒ JiraReferenceCheckHook

Returns a new instance of JiraReferenceCheckHook.



13
14
15
# File 'lib/ruby_git_hooks/jira_ref_check.rb', line 13

def initialize(options = {})
  # not using options now, but leave this here for backwards compatibility
end

Instance Method Details

#checkObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ruby_git_hooks/jira_ref_check.rb', line 17

def check
  if !commit_message || commit_message.length == 0
    STDERR.puts "Commit message is missing or empty!"
    return false
  end

  jira_tickets = commit_message.scan(JIRA_TICKET_REGEXP).map(&:strip)
  if jira_tickets.length == 0
    STDERR.puts "Commit message must refer to a jira ticket"
    return false
  end

  return true
end