Skip to content

Commit aa74f68

Browse files
authored
Merge pull request #809 from prahal/fix-hooks
Fix hooks
2 parents a8b661d + 714bd88 commit aa74f68

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

Diff for: contrib/hooks/post-receive/lib/git_multimail.py

+20-10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#! /usr/bin/env python
1+
#! /usr/bin/env python3
22

3-
__version__ = '1.5.0'
3+
__version__ = '1.6.0'
44

5-
# Copyright (c) 2015-2016 Matthieu Moy and others
5+
# Copyright (c) 2015-2022 Matthieu Moy and others
66
# Copyright (c) 2012-2014 Michael Haggerty and others
77
# Derived from contrib/hooks/post-receive-email, which is
88
# Copyright (c) 2007 Andy Parkins
@@ -95,7 +95,7 @@ def bytes_to_str(s, errors='strict'):
9595
unicode = str
9696

9797
def write_str(f, msg):
98-
# Try outputing with the default encoding. If it fails,
98+
# Try outputting with the default encoding. If it fails,
9999
# try UTF-8.
100100
try:
101101
f.buffer.write(msg.encode(sys.getdefaultencoding()))
@@ -2129,7 +2129,7 @@ def call(klass, server, timeout):
21292129
# equivalent to
21302130
# self.smtp.ehlo()
21312131
# self.smtp.starttls()
2132-
# with acces to the ssl layer
2132+
# with access to the ssl layer
21332133
self.smtp.ehlo()
21342134
if not self.smtp.has_extn("starttls"):
21352135
raise smtplib.SMTPException("STARTTLS extension not supported by server")
@@ -2148,13 +2148,13 @@ def call(klass, server, timeout):
21482148
cert_reqs=ssl.CERT_NONE
21492149
)
21502150
self.environment.get_logger().error(
2151-
'*** Warning, the server certificat is not verified (smtp) ***\n'
2151+
'*** Warning, the server certificate is not verified (smtp) ***\n'
21522152
'*** set the option smtpCACerts ***\n'
21532153
)
21542154
if not hasattr(self.smtp.sock, "read"):
21552155
# using httplib.FakeSocket with Python 2.5.x or earlier
21562156
self.smtp.sock.read = self.smtp.sock.recv
2157-
self.smtp.file = smtplib.SSLFakeFile(self.smtp.sock)
2157+
self.smtp.file = self.smtp.sock.makefile('rb')
21582158
self.smtp.helo_resp = None
21592159
self.smtp.ehlo_resp = None
21602160
self.smtp.esmtp_features = {}
@@ -2194,7 +2194,7 @@ def send(self, lines, to_addrs):
21942194
# turn comma-separated list into Python list if needed.
21952195
if is_string(to_addrs):
21962196
to_addrs = [email for (name, email) in getaddresses([to_addrs])]
2197-
self.smtp.sendmail(self.envelopesender, to_addrs, msg)
2197+
self.smtp.sendmail(self.envelopesender, to_addrs, msg.encode('utf8'))
21982198
except socket.timeout:
21992199
self.environment.get_logger().error(
22002200
'*** Error sending email ***\n'
@@ -2955,10 +2955,20 @@ class ComputeFQDNEnvironmentMixin(FQDNEnvironmentMixin):
29552955

29562956
def __init__(self, **kw):
29572957
super(ComputeFQDNEnvironmentMixin, self).__init__(
2958-
fqdn=socket.getfqdn(),
2958+
fqdn=self.get_fqdn(),
29592959
**kw
29602960
)
29612961

2962+
def get_fqdn(self):
2963+
fqdn = socket.getfqdn()
2964+
# Sometimes, socket.getfqdn() returns localhost or
2965+
# localhost.localhost, which isn't very helpful. In this case,
2966+
# fall-back to socket.gethostname() which may return an actual
2967+
# hostname.
2968+
if fqdn == 'localhost' or fqdn == 'localhost.localdomain':
2969+
fqdn = socket.gethostname()
2970+
return fqdn
2971+
29622972

29632973
class PusherDomainEnvironmentMixin(ConfigEnvironmentMixin):
29642974
"""Deduce pusher_email from pusher by appending an emaildomain."""
@@ -3189,7 +3199,7 @@ def __init__(self, **kw):
31893199
self.COMPUTED_KEYS += ['projectdesc']
31903200

31913201
def get_projectdesc(self):
3192-
"""Return a one-line descripition of the project."""
3202+
"""Return a one-line description of the project."""
31933203

31943204
git_dir = get_git_dir()
31953205
try:

Diff for: contrib/hooks/post-receive/mail_notifications.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! /usr/bin/env python
1+
#! /usr/bin/env python3
22

33
import sys
44
import os

0 commit comments

Comments
 (0)