allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [2/5] allura git commit: [#8157] Max commit notification size, so it can't be enormous (e.g. imported repos). Move a test.
Date Thu, 06 Jul 2017 19:31:43 GMT
[#8157] Max commit notification size, so it can't be enormous (e.g. imported repos).  Move
a test.


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

Branch: refs/heads/db/8157
Commit: 4f4cad09925c6141f56a0c0fc7451b0aac2f1288
Parents: 0ef3c32
Author: Dave Brondsema <dave@brondsema.net>
Authored: Fri Jun 30 16:52:10 2017 -0400
Committer: Dave Brondsema <dave@brondsema.net>
Committed: Thu Jul 6 13:59:27 2017 -0400

----------------------------------------------------------------------
 Allura/allura/model/repo_refresh.py             |  4 ++-
 Allura/allura/templates/mail/commits.md         |  9 ++++--
 .../tests/functional/test_controllers.py        | 14 ---------
 .../forgegit/tests/model/test_repository.py     | 31 +++++++++++++++++++-
 4 files changed, 40 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/4f4cad09/Allura/allura/model/repo_refresh.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repo_refresh.py b/Allura/allura/model/repo_refresh.py
index 9fd3073..327865c 100644
--- a/Allura/allura/model/repo_refresh.py
+++ b/Allura/allura/model/repo_refresh.py
@@ -24,6 +24,7 @@ import bson
 
 import tg
 import jinja2
+from paste.deploy.converters import asint
 from pylons import tmpl_context as c, app_globals as g
 
 from ming.base import Object
@@ -428,7 +429,8 @@ def send_notifications(repo, commit_ids):
             commit = commit_msgs[0]
             subject = u'New commit {} by {}'.format(commit['shorthand_id'], commit['author'])
         text = g.jinja2_env.get_template("allura:templates/mail/commits.md").render(
-            commit_msgs=commit_msgs
+            commit_msgs=commit_msgs,
+            max_num_commits=asint(tg.config.get('scm.notify.max_commits', 100)),
         )
 
         Notification.post(

http://git-wip-us.apache.org/repos/asf/allura/blob/4f4cad09/Allura/allura/templates/mail/commits.md
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/mail/commits.md b/Allura/allura/templates/mail/commits.md
index 4cf99e0..d4a1a96 100644
--- a/Allura/allura/templates/mail/commits.md
+++ b/Allura/allura/templates/mail/commits.md
@@ -16,7 +16,7 @@
        specific language governing permissions and limitations
        under the License.
 --> #}
-{%- for cm in commit_msgs %}
+{%- for cm in commit_msgs[:max_num_commits] %}
 {%- if cm.branches and cm.branches != last_branch|default %}
 ## Branch: {% for b in cm.branches %}{{ b }}  {% endfor%}
 {% endif %}
@@ -28,4 +28,9 @@ By {{ cm.author }} on {{ cm.date }}
 [**View Changes**]({{ cm.commit_url }})
 
 {% if not loop.last %}-----{% endif %}
-{% endfor %}
\ No newline at end of file
+{% endfor -%}
+{%- if commit_msgs|length > max_num_commits -%}
+-----
+
+And {{ commit_msgs|length - max_num_commits }} more commits.
+{% endif %}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/allura/blob/4f4cad09/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 7b142aa..0bcec92 100644
--- a/ForgeGit/forgegit/tests/functional/test_controllers.py
+++ b/ForgeGit/forgegit/tests/functional/test_controllers.py
@@ -303,20 +303,6 @@ class TestRootController(_TestCase):
         assert fn + '&amp;diformat=regular">Switch to unified view</a>' in r
         assert '<table class="side-by-side-diff">' in r
 
-    def test_refresh(self):
-        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('_', '-')
-        common_suffix = tg.config['forgemail.domain']
-        email = 'noreply@%s%s' % (domain, common_suffix)
-        assert_in(email, notification['reply_to_address'])
-
-        commit1_loc = notification.text.find('Initial commit')
-        assert commit1_loc != -1
-        commit2_loc = notification.text.find('Remove file')
-        assert commit2_loc != -1
-        assert_less(commit1_loc, commit2_loc)
-
     def test_file_force_display(self):
         ci = self._get_ci()
         resp = self.app.get(ci + 'tree/README?force=True')

http://git-wip-us.apache.org/repos/asf/allura/blob/4f4cad09/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 002c41a..8dbf931 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, assert_in
+from nose.tools import assert_equal, assert_in, assert_less
 from testfixtures import TempDirectory
 from datadiff.tools import assert_equals
 
@@ -372,6 +372,21 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
         self.assertEqual(new_tree.blob_ids, orig_tree.blob_ids)
         self.assertEqual(new_tree.other_ids, orig_tree.other_ids)
 
+    def test_refresh(self):
+        # test results of things that ran during setUp
+        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('_', '-')
+        common_suffix = tg.config['forgemail.domain']
+        email = 'noreply@%s%s' % (domain, common_suffix)
+        assert_in(email, notification['reply_to_address'])
+
+        commit1_loc = notification.text.find('Initial commit')
+        assert commit1_loc != -1
+        commit2_loc = notification.text.find('Remove file')
+        assert commit2_loc != -1
+        assert_less(commit1_loc, commit2_loc)
+
     def test_notification_email(self):
         send_notifications(
             self.repo, ['1e146e67985dcd71c74de79613719bef7bddca4a', ])
@@ -405,6 +420,20 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
         assert n.text.find('Add README') < n.text.find('Change README'), n.text
         assert n.text.find('Change README') < n.text.find('## Branch: zz') < n.text.find('Not
repo root'), n.text
 
+    @mock.patch.dict(tg.config, {'scm.notify.max_commits': '3'})
+    def test_notification_email_max_commits(self):
+        send_notifications(self.repo, ['9a7df788cf800241e3bb5a849c8870f2f8259d98',
+                                       '6a45885ae7347f1cac5103b0050cc1be6a1496c8',
+                                       'df30427c488aeab84b2352bdf88a3b19223f9d7a',
+                                       '1e146e67985dcd71c74de79613719bef7bddca4a',
+                                       ])
+        ThreadLocalORMSession.flush_all()
+        n = M.Notification.query.find(
+            dict(subject=u'[test:src-git] 4 new commits to Git')).first()
+        assert n
+        assert n.text.startswith('\n## Branch: master'), n.text
+        assert n.text.endswith('And 1 more commits.\n'), n.text
+
     def test_tarball(self):
         tmpdir = tg.config['scm.repos.tarball.root']
         if os.path.isfile(os.path.join(tmpdir, "git/t/te/test/testgit.git/test-src-git-HEAD.zip")):


Mime
View raw message