Rev 39: Draft support for mailing on push/pull. in http://bazaar.launchpad.net/~bzr/bzr-email/trunk
Robert Collins
robertc at robertcollins.net
Tue Dec 9 20:10:07 GMT 2008
At http://bazaar.launchpad.net/~bzr/bzr-email/trunk
------------------------------------------------------------
revno: 39
revision-id: robertc at robertcollins.net-20081209200915-nl9ny11q600uje79
parent: v.ladeuil+lp at free.fr-20081208170431-9rq3an9wuxkl809e
committer: Robert Collins <robertc at robertcollins.net>
branch nick: trunk
timestamp: Wed 2008-12-10 07:09:15 +1100
message:
Draft support for mailing on push/pull.
=== modified file '__init__.py'
--- a/__init__.py 2008-08-05 21:51:27 +0000
+++ b/__init__.py 2008-12-09 20:09:15 +0000
@@ -14,7 +14,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-"""Sending emails upon commit with information about the commit.
+"""Sending emails for commits and branch changes.
To have bzr send an email you need to configure an address to send mail
to for that branch. To do this set the configuration option ``post_commit_to``
@@ -27,6 +27,10 @@
to disable the feature) by setting the configuration option
'post_commit_difflimit' to the number of lines you wish it to be limited to.
+By default bzr-email only emails when a commit occurs, not when a push or
+pull operation occurs. To email on push or pull set post_commit_push_pull=True
+in the configuration.
+
If you are using a bzr release from before 0.15, you need to manually tell
bzr about the commit action, by setting
post_commit=bzrlib.plugins.email.post_commit in bazaar.conf or locations.conf.
@@ -87,11 +91,21 @@
local_branch=local).send_maybe()
+def branch_post_change_hook(params):
+ """This is the post_change_branch_tip hook."""
+ # (branch, old_revno, new_revno, old_revid, new_revid)
+ _emailer.EmailSender(params.branch, params.new_revid,
+ params.branch.get_config(), local_branch=None, op='change').send_maybe()
+
+
def install_hooks():
"""Install CommitSender to send after commits with bzr >= 0.15 """
install_named_hook = getattr(Branch.hooks, 'install_named_hook', None)
if install_named_hook is not None:
install_named_hook('post_commit', branch_commit_hook, 'bzr-email')
+ if 'post_change_branch_tip' in Branch.hooks:
+ install_named_hook('post_change_branch_tip',
+ branch_post_change_hook, 'bzr-email')
else:
Branch.hooks.install_hook('post_commit', branch_commit_hook)
if getattr(Branch.hooks, 'name_hook', None) is not None:
=== modified file 'emailer.py'
--- a/emailer.py 2008-09-25 10:19:27 +0000
+++ b/emailer.py 2008-12-09 20:09:15 +0000
@@ -30,7 +30,8 @@
_smtplib_implementation = SMTPConnection
- def __init__(self, branch, revision_id, config, local_branch=None):
+ def __init__(self, branch, revision_id, config, local_branch=None,
+ op='commit'):
self.config = config
self.branch = branch
self.repository = branch.repository
@@ -40,6 +41,7 @@
self._revision_id = revision_id
self.revision = None
self.revno = None
+ self.op = op
def _setup_revision_and_revno(self):
self.revision = self.repository.get_revision(self._revision_id)
@@ -230,6 +232,15 @@
self.diff_filename())
def should_send(self):
+ result = self.config.get_user_option('post_commit_difflimit')
+ post_commit_push_pull = self.config.get_user_option(
+ 'post_commit_push_pull') == 'True'
+ if post_commit_push_pull and self.op == 'commit':
+ # We will be called again with a push op, send the mail then.
+ return False
+ if not post_commit_push_pull and self.op != 'commit':
+ # Mailing on commit only, and this is a push/pull operation.
+ return False
return bool(self.to() and self.from_address())
def send_maybe(self):
=== modified file 'tests/testemail.py'
--- a/tests/testemail.py 2008-12-08 17:04:31 +0000
+++ b/tests/testemail.py 2008-12-09 20:09:15 +0000
@@ -49,6 +49,10 @@
"post_commit_sender=Sender <from at example.com>\n"
"post_commit_to=Sample <foo at example.com>, Other <baz at bar.com>\n")
+push_config=("[DEFAULT]\n"
+ "post_commit_to=demo at example.com\n"
+ "post_commit_push_pull=True\n")
+
with_url_config=("[DEFAULT]\n"
"post_commit_url=http://some.fake/url/\n"
"post_commit_to=demo at example.com\n"
More information about the bazaar-commits
mailing list