forked from sds/overcommit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthor_email.rb
More file actions
26 lines (23 loc) · 725 Bytes
/
Copy pathauthor_email.rb
File metadata and controls
26 lines (23 loc) · 725 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# frozen_string_literal: true
module Overcommit::Hook::PreCommit
# Checks the format of an author's email address.
class AuthorEmail < Base
def run
email =
if ENV.key?('GIT_AUTHOR_EMAIL')
ENV['GIT_AUTHOR_EMAIL']
else
result = execute(%w[git config --get user.email])
result.stdout.chomp
end
unless email.match?(/#{config['pattern']}/)
return :fail,
"Author has an invalid email address: '#{email}'\n" \
'Set your email with ' \
'`git config --global user.email your_email@example.com` ' \
'or via the GIT_AUTHOR_EMAIL environment variable'
end
:pass
end
end
end