allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [1/2] allura git commit: [#8078] add a "meta" post when changing the status via the one-click merge button
Date Thu, 30 Jun 2016 21:46:18 GMT
Repository: allura
Updated Branches:
  refs/heads/db/8078 [created] 91a0f5628


[#8078] add a "meta" post when changing the status via the one-click merge button


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

Branch: refs/heads/db/8078
Commit: 9b0b332e07a559dc1f8bff8c41bde55611289963
Parents: bdf758d
Author: Dave Brondsema <dave@brondsema.net>
Authored: Thu Jun 30 17:38:37 2016 -0400
Committer: Dave Brondsema <dave@brondsema.net>
Committed: Thu Jun 30 17:38:37 2016 -0400

----------------------------------------------------------------------
 Allura/allura/controllers/repository.py | 8 +++-----
 Allura/allura/model/repository.py       | 6 ++++++
 Allura/allura/tasks/repo_tasks.py       | 1 +
 Allura/allura/tests/model/test_repo.py  | 1 +
 4 files changed, 11 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/9b0b332e/Allura/allura/controllers/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/repository.py b/Allura/allura/controllers/repository.py
index 93c89a5..39e3516 100644
--- a/Allura/allura/controllers/repository.py
+++ b/Allura/allura/controllers/repository.py
@@ -361,7 +361,6 @@ class MergeRequestController(object):
     mr_dispose_form = SCMMergeRequestDisposeWidget()
 
     def __init__(self, num):
-        self.tmpl = g.jinja2_env.get_template('allura:templates/repo/merge_request_changed.html')
         self.req = M.MergeRequest.query.get(
             app_config_id=c.app.config._id,
             request_number=int(num))
@@ -453,8 +452,8 @@ class MergeRequestController(object):
         with self.req.push_downstream_context():
             self.req.downstream['commit_id'] = c.app.repo.commit(kw['source_branch'])._id
 
-        message = self.tmpl.render(changes=changes)
-        self.req.discussion_thread.add_post(text=message, is_meta=True)
+        if changes:
+            self.req.add_meta_post(changes=changes)
         redirect(self.req.url())
 
     @expose()
@@ -463,8 +462,7 @@ class MergeRequestController(object):
     def save(self, status=None, **kw):
         if status and self.req.status != status and \
            (has_access(self.req, 'write') or (self.req.creator == c.user and status == 'rejected')):
-            message = self.tmpl.render(changes={'Status': [self.req.status, status]})
-            self.req.discussion_thread.add_post(text=message, is_meta=True)
+            self.req.add_meta_post(changes={'Status': [self.req.status, status]})
             self.req.status = status
         redirect('.')
 

http://git-wip-us.apache.org/repos/asf/allura/blob/9b0b332e/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index 9edbd58..1109216 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -914,6 +914,12 @@ class MergeRequest(VersionedArtifact, ActivityObject):
             return task.state
         return None
 
+    def add_meta_post(self, changes):
+        tmpl = g.jinja2_env.get_template('allura:templates/repo/merge_request_changed.html')
+        message = tmpl.render(changes=changes)
+        self.discussion_thread.add_post(text=message, is_meta=True)
+
+
 
 # Basic commit information
 # One of these for each commit in the physical repo on disk. The _id is the

http://git-wip-us.apache.org/repos/asf/allura/blob/9b0b332e/Allura/allura/tasks/repo_tasks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tasks/repo_tasks.py b/Allura/allura/tasks/repo_tasks.py
index 9ea9fd0..7b39a8a 100644
--- a/Allura/allura/tasks/repo_tasks.py
+++ b/Allura/allura/tasks/repo_tasks.py
@@ -161,6 +161,7 @@ def merge(merge_request_id):
     from allura import model as M
     mr = M.MergeRequest.query.get(_id=merge_request_id)
     mr.app.repo.merge(mr)
+    mr.add_meta_post(changes={'Status': [mr.status, 'merged']})
     mr.status = 'merged'
     session(mr).flush(mr)
 

http://git-wip-us.apache.org/repos/asf/allura/blob/9b0b332e/Allura/allura/tests/model/test_repo.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/model/test_repo.py b/Allura/allura/tests/model/test_repo.py
index 9b364aa..82a8123 100644
--- a/Allura/allura/tests/model/test_repo.py
+++ b/Allura/allura/tests/model/test_repo.py
@@ -695,6 +695,7 @@ class TestMergeRequest(object):
         self.mr.app = mock.Mock(forkable=True)
         self.mr.app.repo.commit.return_value = mock.Mock(_id='09876')
         self.mr.merge_allowed = mock.Mock(return_value=True)
+        self.mr.discussion_thread = mock.Mock()
 
     def test_can_merge_cache_key(self):
         key = self.mr.can_merge_cache_key()


Mime
View raw message