allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject allura git commit: [#7825] Added "new commits" email template.
Date Fri, 12 Jun 2015 18:18:57 GMT
Repository: allura
Updated Branches:
  refs/heads/master b2a1b10d5 -> 51fc93b47


[#7825] Added "new commits" email template.


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/51fc93b4
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/51fc93b4
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/51fc93b4

Branch: refs/heads/master
Commit: 51fc93b4758757eb69ec9e10be415c4c27b19701
Parents: b2a1b10
Author: Heith Seewald <hseewald@slashdotmedia.com>
Authored: Tue May 26 20:36:50 2015 -0400
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Fri Jun 12 18:18:41 2015 +0000

----------------------------------------------------------------------
 Allura/allura/model/repo_refresh.py             | 48 ++++++++++++--------
 Allura/allura/model/repository.py               |  2 +-
 Allura/allura/templates/mail/commits.md         | 24 ++++++++++
 .../tests/functional/test_controllers.py        |  4 +-
 .../forgegit/tests/model/test_repository.py     | 10 ++--
 .../forgesvn/tests/model/test_repository.py     | 12 +++--
 6 files changed, 68 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/51fc93b4/Allura/allura/model/repo_refresh.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repo_refresh.py b/Allura/allura/model/repo_refresh.py
index 1711bc3..fca220f 100644
--- a/Allura/allura/model/repo_refresh.py
+++ b/Allura/allura/model/repo_refresh.py
@@ -360,10 +360,18 @@ def unknown_commit_ids(all_commit_ids):
 
 
 def send_notifications(repo, commit_ids):
-    '''Create appropriate notification and feed objects for a refresh'''
+    """Create appropriate notification and feed objects for a refresh
+
+    :param repo: A repository artifact instance.
+    :type repo: Repository
+
+    :param commit_ids: A list of commit hash strings.
+    :type commit_ids: list
+    """
     from allura.model import Feed, Notification
     commit_msgs = []
     base_url = tg.config['base_url']
+    last_branch = []
     for oids in utils.chunked_iter(commit_ids, QSIZE):
         chunk = list(oids)
         index = dict(
@@ -382,26 +390,30 @@ def send_notifications(repo, commit_ids):
                 author_name=ci.authored.name,
                 link=href,
                 unique_id=href)
-            branches = repo.symbolics_for_commit(ci)[0]
-            commit_msgs.append('%s: %s by %s %s%s' % (
-                ",".join(b for b in branches),
-                summary, ci.authored.name, base_url, ci.url()))
+
+            summary = g.markdown_commit.convert(ci.message) if ci.message else ""
+
+            current_branch = repo.symbolics_for_commit(ci)[0]
+            if last_branch == current_branch:
+                branches = []
+            else:
+                branches = current_branch
+                last_branch = branches
+
+            commit_msgs.append(dict(
+                author=ci.authored.name,
+                date=ci.authored.date.strftime("%m/%d/%Y %H:%M"),
+                summary=summary,
+                branches=branches,
+                commit_url=base_url + href))
+
     if commit_msgs:
         if len(commit_msgs) > 1:
-            subject = '%d new commits to %s %s' % (
-                len(commit_msgs), repo.app.project.name, repo.app.config.options.mount_label)
-            text = '\n\n'.join(commit_msgs)
+            subject = u"{} new commits to {}".format(len(commit_msgs), repo.app.config.options.mount_label)
         else:
-            subject = '{0} - {1}: {2}'.format(
-                repo.shorthand_for_commit(ci._id),
-                ci.authored.name,
-                summary)
-            branches = repo.symbolics_for_commit(ci)[0]
-            text_branches = ('%s: ' % ",".join(b for b in branches)
-                             if branches else '')
-            text = "%s%s %s%s" % (text_branches,
-                                  ci.message,
-                                  base_url, ci.url())
+            subject = u'New commit by {}'.format(commit_msgs[0]['author'])
+        template = g.jinja2_env.get_template("allura:templates/mail/commits.md")
+        text = u"\n\n-----".join([template.render(d) for d in commit_msgs])
 
         Notification.post(
             artifact=repo,

http://git-wip-us.apache.org/repos/asf/allura/blob/51fc93b4/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index ec623a3..022343f 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -578,7 +578,7 @@ class Repository(Artifact, ActivityObject):
         result.update(
             name_s=self.name,
             type_s=self.type_s,
-            title='Repository %s %s' % (self.project.name, self.name))
+            title=u'{} {} repository'.format(self.project.name, self.app.tool_label))
         return result
 
     @property

http://git-wip-us.apache.org/repos/asf/allura/blob/51fc93b4/Allura/allura/templates/mail/commits.md
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/mail/commits.md b/Allura/allura/templates/mail/commits.md
new file mode 100644
index 0000000..7d4e4b1
--- /dev/null
+++ b/Allura/allura/templates/mail/commits.md
@@ -0,0 +1,24 @@
+{# <!---
+       Licensed to the Apache Software Foundation (ASF) under one
+       or more contributor license agreements.  See the NOTICE file
+       distributed with this work for additional information
+       regarding copyright ownership.  The ASF licenses this file
+       to you under the Apache License, Version 2.0 (the
+       "License"); you may not use this file except in compliance
+       with the License.  You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+       Unless required by applicable law or agreed to in writing,
+       software distributed under the License is distributed on an
+       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+       KIND, either express or implied.  See the License for the
+       specific language governing permissions and limitations
+       under the License.
+--> #}
+{% if branches %}## Branch: {% for b in branches %} {{ b }}  {% endfor%}{% endif %}
+
+{{summary}}
+
+By {{ author }} on {{ date }}
+[**View Changes**]({{ commit_url }})

http://git-wip-us.apache.org/repos/asf/allura/blob/51fc93b4/ForgeGit/forgegit/tests/functional/test_controllers.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/functional/test_controllers.py b/ForgeGit/forgegit/tests/functional/test_controllers.py
index 1312188..917f765 100644
--- a/ForgeGit/forgegit/tests/functional/test_controllers.py
+++ b/ForgeGit/forgegit/tests/functional/test_controllers.py
@@ -264,9 +264,7 @@ class TestRootController(_TestCase):
         assert '<table class="side-by-side-diff">' in r
 
     def test_refresh(self):
-        notification = M.Notification.query.find(
-            dict(subject='[test:src-git] 5 new commits to Test Project Git')
-        ).first()
+        notification = M.Notification.query.find({'subject': '[test:src-git] 5 new commits
to Git'}).first()
         assert notification
         domain = '.'.join(
             reversed(c.app.url[1:-1].split('/'))).replace('_', '-')

http://git-wip-us.apache.org/repos/asf/allura/blob/51fc93b4/ForgeGit/forgegit/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/model/test_repository.py b/ForgeGit/forgegit/tests/model/test_repository.py
index 936fbee..349efe6 100644
--- a/ForgeGit/forgegit/tests/model/test_repository.py
+++ b/ForgeGit/forgegit/tests/model/test_repository.py
@@ -29,7 +29,7 @@ from pylons import tmpl_context as c, app_globals as g
 import tg
 from ming.base import Object
 from ming.orm import ThreadLocalORMSession, session
-from nose.tools import assert_equal
+from nose.tools import assert_equal, assert_in
 from testfixtures import TempDirectory
 from datadiff.tools import assert_equals
 
@@ -376,15 +376,15 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
         send_notifications(
             self.repo, ['1e146e67985dcd71c74de79613719bef7bddca4a', ])
         ThreadLocalORMSession.flush_all()
-        n = M.Notification.query.find(
-            dict(subject='[test:src-git] [1e146e] - Rick Copeland: Change README')).first()
+
+        n = M.Notification.query.find({'subject': u'[test:src-git] New commit by Rick Copeland'}).first()
         assert n
-        assert 'master: ' in n.text, n.text
+        assert_in('Change README', n.text)
         send_notifications(
             self.repo, ['1e146e67985dcd71c74de79613719bef7bddca4a', 'df30427c488aeab84b2352bdf88a3b19223f9d7a'])
         ThreadLocalORMSession.flush_all()
         assert M.Notification.query.find(
-            dict(subject='[test:src-git] 2 new commits to Test Project Git')).first()
+            dict(subject=u'[test:src-git] 2 new commits to Git')).first()
 
     def test_tarball(self):
         tmpdir = tg.config['scm.repos.tarball.root']

http://git-wip-us.apache.org/repos/asf/allura/blob/51fc93b4/ForgeSVN/forgesvn/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/tests/model/test_repository.py b/ForgeSVN/forgesvn/tests/model/test_repository.py
index 744d30a..79beb52 100644
--- a/ForgeSVN/forgesvn/tests/model/test_repository.py
+++ b/ForgeSVN/forgesvn/tests/model/test_repository.py
@@ -27,7 +27,7 @@ from zipfile import ZipFile
 from collections import defaultdict
 from pylons import tmpl_context as c, app_globals as g
 import mock
-from nose.tools import assert_equal
+from nose.tools import assert_equal, assert_in
 from datadiff.tools import assert_equals
 import tg
 import ming
@@ -693,10 +693,10 @@ class TestSVNRev(unittest.TestCase):
         ThreadLocalORMSession.flush_all()
         send_notifications(self.repo, [self.repo.rev_to_commit_id(1)])
         ThreadLocalORMSession.flush_all()
-        n = M.Notification.query.find(
-            dict(subject='[test:src] [r1] - rick446: Create readme')).first()
+        n = M.Notification.query.find({u'subject': u'[test:src] New commit by rick446'}).first()
         assert n
-        assert_equal(n.text, 'Create readme http://localhost:8080/p/test/src/1/')
+        assert_in(u'By rick446', n.text)
+        assert_in(u'Create readme', n.text)
 
 
 class _Test(unittest.TestCase):
@@ -869,6 +869,7 @@ class TestRepo(_TestWithRepo):
             M.repository.CommitDoc(dict(
                 authored=dict(
                     name=committer_name,
+                    date=datetime(2010, 10, 8, 15, 32, 48, 0),
                     email=committer_email),
                 _id=oid)).m.insert()
         self.repo._impl.refresh_commit_info = refresh_commit_info
@@ -880,7 +881,8 @@ class TestRepo(_TestWithRepo):
         notifications = M.Notification.query.find().all()
         for n in notifications:
             if '100 new commits' in n.subject:
-                assert "master,branch:  by %s http://localhost:8080/ci/foo99" % committer_name
in n.text
+                assert_in(u'By Test Committer on 10/08/2010 15:32', n.text)
+                assert_in(u'http://localhost:8080/ci/foo99/', n.text)
                 break
         else:
             assert False, 'Did not find notification'


Mime
View raw message