allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [1/5] allura git commit: [#8157] Fix locations of branch names in commit notifications (regression from [#8144])
Date Thu, 06 Jul 2017 19:31:42 GMT
Repository: allura
Updated Branches:
  refs/heads/db/8157 [created] 925f9a6f6


[#8157] Fix locations of branch names in commit notifications (regression from [#8144])


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

Branch: refs/heads/db/8157
Commit: 0ef3c3222b51e985a07475a96b83ffc77a9393d3
Parents: 71ee853
Author: Dave Brondsema <dave@brondsema.net>
Authored: Fri Jun 30 16:20:43 2017 -0400
Committer: Dave Brondsema <dave@brondsema.net>
Committed: Thu Jul 6 13:57:16 2017 -0400

----------------------------------------------------------------------
 Allura/allura/model/repo_refresh.py             | 25 ++++++++++----------
 Allura/allura/templates/mail/commits.md         | 15 ++++++++----
 .../forgegit/tests/model/test_repository.py     | 25 +++++++++++++++++---
 3 files changed, 46 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/0ef3c322/Allura/allura/model/repo_refresh.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repo_refresh.py b/Allura/allura/model/repo_refresh.py
index a7c2c00..9fd3073 100644
--- a/Allura/allura/model/repo_refresh.py
+++ b/Allura/allura/model/repo_refresh.py
@@ -378,7 +378,7 @@ def send_notifications(repo, commit_ids):
     :param repo: A repository artifact instance.
     :type repo: Repository
 
-    :param commit_ids: A list of commit hash strings.
+    :param commit_ids: A list of commit hash strings, oldest to newest
     :type commit_ids: list
     """
     from allura.model import Feed, Notification
@@ -405,30 +405,31 @@ def send_notifications(repo, commit_ids):
                 unique_id=href)
 
             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
-
+            current_branch = repo.symbolics_for_commit(ci)[0]  # only the head of a branch
will have this
             commit_msgs.append(dict(
                 author=ci.authored.name,
                 date=ci.authored.date.strftime("%m/%d/%Y %H:%M"),
                 summary=summary,
-                branches=branches,
+                branches=current_branch,
                 commit_url=base_url + href,
                 shorthand_id=ci.shorthand_id()))
 
+    # fill out the branch info for all the other commits
+    prev_branch = None
+    for c_msg in reversed(commit_msgs):
+        if not c_msg['branches']:
+            c_msg['branches'] = prev_branch
+        prev_branch = c_msg['branches']
+
     if commit_msgs:
         if len(commit_msgs) > 1:
             subject = u"{} new commits to {}".format(len(commit_msgs), repo.app.config.options.mount_label)
         else:
             commit = commit_msgs[0]
             subject = u'New commit {} by {}'.format(commit['shorthand_id'], commit['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])
+        text = g.jinja2_env.get_template("allura:templates/mail/commits.md").render(
+            commit_msgs=commit_msgs
+        )
 
         Notification.post(
             artifact=repo,

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

http://git-wip-us.apache.org/repos/asf/allura/blob/0ef3c322/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 97e343a..002c41a 100644
--- a/ForgeGit/forgegit/tests/model/test_repository.py
+++ b/ForgeGit/forgegit/tests/model/test_repository.py
@@ -380,11 +380,30 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
         n = M.Notification.query.find({'subject': u'[test:src-git] New commit [1e146e] by
Rick Copeland'}).first()
         assert n
         assert_in('Change README', n.text)
-        send_notifications(
-            self.repo, ['1e146e67985dcd71c74de79613719bef7bddca4a', 'df30427c488aeab84b2352bdf88a3b19223f9d7a'])
+
+    def test_notification_email_multiple_commits(self):
+        send_notifications(self.repo, ['df30427c488aeab84b2352bdf88a3b19223f9d7a',
+                                       '1e146e67985dcd71c74de79613719bef7bddca4a',
+                                       ])
         ThreadLocalORMSession.flush_all()
-        assert M.Notification.query.find(
+        n = M.Notification.query.find(
             dict(subject=u'[test:src-git] 2 new commits to Git')).first()
+        assert n
+        assert n.text.startswith('\n## Branch: master'), n.text
+        assert n.text.find('Add README') < n.text.find('Change README'), n.text
+
+    def test_notification_email_multiple_branches(self):
+        send_notifications(self.repo, ['df30427c488aeab84b2352bdf88a3b19223f9d7a',
+                                       '1e146e67985dcd71c74de79613719bef7bddca4a',
+                                       '5c47243c8e424136fd5cdd18cd94d34c66d1955c',
+                                       ])
+        ThreadLocalORMSession.flush_all()
+        n = M.Notification.query.find(
+            dict(subject=u'[test:src-git] 3 new commits to Git')).first()
+        assert n
+        assert n.text.startswith('\n## Branch: master'), n.text
+        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
 
     def test_tarball(self):
         tmpdir = tg.config['scm.repos.tarball.root']


Mime
View raw message