module Causes::GitHook
  class CheckCommitAuthor < HookSpecificCheck
    include HookRegistry

    def run_check
      name = `git config --get user.name`.strip
      unless name.split(' ').count >= 2
        return :bad, "Author must have at least first and last name; " <<
                     "was: '#{name}'.\n Set your name with " <<
                     "`git config --global user.name 'Your Name'`"
      end

      email = `git config --get user.email`.strip
      unless email =~ /@causes\.com$/
        return :bad, "Author must use a causes.com address; was '#{email}'.\n" <<
                     "Set user with `git config --global user.email YOUR_EMAIL@causes.com`"
      end

      :good
    end
  end
end

Enforce git author name and email
Enforce git author name and email

When developing on our dev boxes, especially as a new hire it's possible
to accidentally commit some code using your personal email address.

This hook prevents this problem by checking to make sure all email
addresses end with '@causes.com'.

This also ensures that you provide your full name, e.g. John Doe instead
of just John (I don't think we'll be hiring any mononymous people
anytime soon).

Change-Id: Ibe612a3ca4e08176b4e6d30d3f171d16bec0b2a9
Reviewed-on: https://gerrit.causes.com/17329
Tested-by: Shane da Silva <6f6e68d1df92f30cb4b3ce35260ddf94a402f33d@causes.com>
Reviewed-by: Aiden Scandella <1faf1e8390cdac9204f160c35828cc423b7acd7b@causes.com>
