Anonymous avatar Anonymous committed bd04c6b Draft

Fix the hooks for the hg.p.o migration

Comments (0)

Files changed (3)

             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):
         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
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.