Rev 3: convert the switch basics to an email plugin in file:///home/jelmer/bzr-email/cmd/
Jelmer Vernooij
jelmer at samba.org
Wed Jul 4 01:01:17 BST 2007
At file:///home/jelmer/bzr-email/cmd/
------------------------------------------------------------
revno: 3
revision-id: robertc at robertcollins.net-20051021011541-527de0923c69f274
parent: robertc at robertcollins.net-20051018115959-cdae22c32cf30fe8
committer: Robert Collins <robertc at robertcollins.net>
timestamp: Fri 2005-10-21 11:15:41 +1000
message:
convert the switch basics to an email plugin
renamed:
tests/testpublish.py => tests/testemail.py testpublish.py-20051018071212-e3a53d78c05e0e0a
modified:
README README-20051018071212-c081f89570802202
__init__.py __init__.py-20051018071212-f1765ec4521cab0b
tests/__init__.py __init__.py-20051018071212-465bf3f697dddbda
tests/testemail.py testpublish.py-20051018071212-e3a53d78c05e0e0a
=== renamed file 'tests/testpublish.py' => 'tests/testemail.py'
--- a/tests/testpublish.py 2005-10-18 11:59:59 +0000
+++ b/tests/testemail.py 2005-10-21 01:15:41 +0000
@@ -20,8 +20,8 @@
from bzrlib.branch import Branch
import bzrlib.config as config
-from bzrlib.selftest import TestCase, TestCaseInTempDir
-from bzrlib.selftest.testconfig import FakeBranch
+from bzrlib.selftest import TestCaseInTempDir
+from bzrlib.plugins.email import post_commit, EmailSender
def test_suite():
@@ -29,40 +29,33 @@
sample_config=("[DEFAULT]\n"
- "publishing_root=rsync://example.com/home/archives\n"
- "publishing_product=demo\n")
-
-
-sample_version_config=(sample_config +
- "publishing_version=0\n")
-
-
-class TestTest(TestCaseInTempDir):
-
- def test_get_publishing_root(self):
- my_config = self.get_config()
- self.assertEqual("rsync://example.com/home/archives",
- my_config.get_user_option("publishing_root"))
-
- def test_get_publising_product(self):
- my_config = self.get_config()
- self.assertEqual("demo",
- my_config.get_user_option("publishing_product"))
-
-# def test_get_publishing_version(self):
-# my_config = self.get_config()
-# self.assertEqual(None,
-# my_config.get_user_option("publishing_version"))
-#
-# def test_get_present_publishing_version(self):
-# my_config = self.get_config(sample_version_config)
-# self.assertEqual('0',
-# my_config.get_user_option("publishing_version"))
-
- def get_config(self, text=sample_config):
- branch = FakeBranch()
- my_config = config.BranchConfig(branch)
+ "post_commit_to=demo at example.com\n"
+ "post_commit_sender=Sample <foo at example.com>\n")
+
+
+class TestGetTo(TestCaseInTempDir):
+
+ def test_to(self):
+ sender = self.get_sender()
+ self.assertEqual('demo at example.com', sender.to())
+
+ def test_from(self):
+ sender = self.get_sender()
+ self.assertEqual('Sample <foo at example.com>', sender.from_address())
+
+ def test_should_send(self):
+ sender = self.get_sender()
+ self.assertEqual(True, sender.should_send())
+
+ def test_should_not_send(self):
+ sender = self.get_sender("")
+ self.assertEqual(False, sender.should_send())
+
+ def get_sender(self, text=sample_config):
+ self.branch = Branch.initialize('.')
+ self.branch.commit('foo bar baz', rev_id='A', allow_pointless=True)
+ my_config = config.BranchConfig(self.branch)
config_file = StringIO(text)
(my_config._get_location_config().
_get_global_config()._get_parser(config_file))
- return my_config
+ return EmailSender(self.branch, 'A', my_config)
=== modified file 'README'
--- a/README 2005-10-18 07:39:12 +0000
+++ b/README 2005-10-21 01:15:41 +0000
@@ -1,8 +1,9 @@
-This is a plugin to implement 'switch' for bzr.
-Switch needs to:
- * Be able to determine the path a branch should be pushed to.
- (bzr publish)
- * Trigger a push if a branch is out of date. (uses bzrtools).
- * Be able to pull down a new branches revisions. (uses standard pull).
- * Be able to replace the revision history of this branch with
- working_tree.pull(that_branch, clobber=True)
+This is a plugin to implement post commmit emails for bzr.
+This should eventually automatically activate if an email
+address is set, and should allow format specifiers too.
+
+Until then, it is activated by setting
+post_commit=bzrlib.plugins.email.post_commit in bazaar.conf or branches.conf.
+
+The address to sent to is read from 'post_commit_to' and the address to send
+from from 'post_commit_sender'.
=== modified file '__init__.py'
--- a/__init__.py 2005-10-18 07:39:12 +0000
+++ b/__init__.py 2005-10-21 01:15:41 +0000
@@ -15,10 +15,36 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+import bzrlib.config as config
+
+
+class EmailSender(object):
+ """An email message sender."""
+
+ def __init__(self, branch, revision_id, config):
+ self.config = config
+
+ def to(self):
+ """What is the address the mail should go to."""
+ return self.config.get_user_option('post_commit_to')
+
+ def from_address(self):
+ """What address should I send from."""
+ return self.config.get_user_option('post_commit_sender')
+
+ def should_send(self):
+ return self.to() is not None and self.from_address() is not None
+
+
+def post_commit(branch, revision_id):
+ EmailSender(branch, revision_id, config.BranchConfig(branch)).send()
+
+
def test_suite():
from unittest import TestSuite
- import bzrlib.plugins.switch.tests
+ import bzrlib.plugins.email.tests
result = TestSuite()
- result.addTest(bzrlib.plugins.switch.tests.test_suite())
+ result.addTest(bzrlib.plugins.email.tests.test_suite())
return result
=== modified file 'tests/__init__.py'
--- a/tests/__init__.py 2005-10-18 07:39:12 +0000
+++ b/tests/__init__.py 2005-10-21 01:15:41 +0000
@@ -19,7 +19,7 @@
def test_suite():
result = TestSuite()
- import bzrlib.plugins.switch.tests.testpublish as testpublish
- result.addTest(testpublish.test_suite())
+ import bzrlib.plugins.email.tests.testemail as testemail
+ result.addTest(testemail.test_suite())
return result
More information about the bazaar-commits
mailing list