Commits

Antoine Pitrou  committed bd04c6b Draft

Fix the hooks for the hg.p.o migration

  • Participants
  • Parent commits 885b48e

Comments (0)

Files changed (3)

File hgbuildbot.py

             elif isinstance(v, str):
                 change[k] = v.decode('utf8', 'replace')
         d.addCallback(send, change)
-    d.addCallbacks(s.printSuccess, s.printFailure)
-    d.addBoth(s.stop)
+
+    def printSuccess(res):
+        print "change(s) sent successfully"
+
+    def printFailure(why):
+        print "change(s) NOT sent, something went wrong:"
+        print why
+
+    d.addCallbacks(printSuccess, printFailure)
+    d.addBoth(lambda _: reactor.stop())
 
 
 def hook(ui, repo, hooktype, node=None, source=None, **kwargs):

File hgroundup.py

         repourl = posixpath.join(ui.config('web', 'baseurl'), 'rev/')
     fromaddr = ui.config('hgroundup', 'fromaddr')
     toaddr = ui.config('hgroundup', 'toaddr')
-    mailrelay = ui.config('hgroundup', 'mailrelay', default='127.0.0.1')
+    mailrelay = ui.config('hgroundup', 'mailrelay', default='')
+    if not mailrelay:
+        mailrelay = ui.config('smtp', 'host', default='')
     for var in ('repourl', 'fromaddr', 'toaddr'):
         if not locals()[var]:
             raise RuntimeError(
 Mercurial hook to send an email for each changeset to a specified address.
 
 For use as an "incoming" hook.
+
+To set the SMTP server to something other than localhost, add a [smtp]
+section to your hgrc:
+
+[smtp]
+host = mail.python.org
+port = 25
+
 """
 
 from email.header import Header
 CSET_URL = BASE + '%s/rev/%s'
 
 
-def send(sub, sender, to, body):
+def send(smtp, sub, sender, to, body):
     msg = MIMEMultipart()
     msg['Subject'] = Header(sub, 'utf8')
     msg['To'] = to
     msg['From'] = sender
     msg.attach(MIMEText(body, _subtype='plain', _charset='utf8'))
-    smtp = smtplib.SMTP()
-    smtp.connect()
     smtp.sendmail(sender, to, msg.as_string())
-    smtp.close()
 
 def strip_bin_diffs(chunks):
     stripped = []
 
     subj = prefixes + desc
 
-    send(subj, sender, to, '\n'.join(body) + '\n')
+    host = ui.config('smtp', 'host', '')
+    port = int(ui.config('smtp', 'port', 0))
+    smtp = smtplib.SMTP(host, port)
+    send(smtp, subj, sender, to, '\n'.join(body) + '\n')
+    smtp.close()
+
     ui.status('notified %s of incoming changeset %s\n' % (to, ctx))
     return False