You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by he...@apache.org on 2015/05/27 02:47:32 UTC

[2/2] allura git commit: [#7825] Added "new commits" email template.

[#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/a7fd9527
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/a7fd9527
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/a7fd9527

Branch: refs/heads/hs/7825
Commit: a7fd952727b7062465983e505116b7261056beb4
Parents: 1accce5
Author: Heith Seewald <hs...@slashdotmedia.com>
Authored: Wed May 27 00:45:09 2015 +0000
Committer: Heith Seewald <hs...@slashdotmedia.com>
Committed: Wed May 27 00:46:00 2015 +0000

----------------------------------------------------------------------
 Allura/allura/model/repo_refresh.py     | 54 +++++++++++++++++++---------
 Allura/allura/templates/mail/commits.md | 36 +++++++++++++++++++
 2 files changed, 73 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/a7fd9527/Allura/allura/model/repo_refresh.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repo_refresh.py b/Allura/allura/model/repo_refresh.py
index 1711bc3..3fb4f76 100644
--- a/Allura/allura/model/repo_refresh.py
+++ b/Allura/allura/model/repo_refresh.py
@@ -360,8 +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
+    from allura import model as M
+    import forgesvn
+
     commit_msgs = []
     base_url = tg.config['base_url']
     for oids in utils.chunked_iter(commit_ids, QSIZE):
@@ -383,25 +393,35 @@ def send_notifications(repo, commit_ids):
                 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()))
+            commit_info = get_commit_info(ci)
+
+            if isinstance(repo, forgesvn.model.Repository):
+                _user = M.User.by_username(commit_info['author'])
+            else:
+                _user = M.User.by_email_address(commit_info['author_email'])
+
+            if not _user:
+                _user = M.User.anonymous()
+
+            commit_info.update(
+                author_gravatar=_user.icon_url(),
+                text_branches=branches,
+                project=repo.app.project.shortname,
+                label=repo.app.config.options.mount_label,
+                commit_url=base_url + href,
+                short_date=ci.authored.date.strftime('%c')
+            )
+            commit_msgs.append(commit_info)
+            if not commit_info['author_url']:
+                commit_info['author_url'] = u"{}/u/{}".format(base_url, commit_info['author'])
     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/a7fd9527/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..8a0d934
--- /dev/null
+++ b/Allura/allura/templates/mail/commits.md
@@ -0,0 +1,36 @@
+{# <!---
+       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.
+--> #}
+
+-----------
+
+[![{{ author }}][2]][1]
+[New commit to **{{ project }}:{{ label }}**][3]
+ by [{{ author }}][1] on {{ short_date }}.
+**Summary**: ```{{ summary }}```
+{% if text_branches %}**Branch:** {% for b in text_branches %} *{{ b }}* {% endfor%}{% endif %}
+#### [**View Changes**][3]
+
+  [1]: {{ author_url }}
+  [2]: {{author_gravatar}} ({{ author }})
+  [3]: {{ commit_url }}
+
+
+
+  
+  
\ No newline at end of file