allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [04/50] git commit: [#6301] ticket:536 Show description changes as diff
Date Tue, 25 Mar 2014 14:27:02 GMT
[#6301] ticket:536 Show description changes as diff


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

Branch: refs/heads/db/5995
Commit: 714cf8709033d43c9ce689383db529d092a07f05
Parents: 8deb965
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Wed Mar 5 16:07:59 2014 +0200
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Wed Mar 5 15:51:21 2014 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/repository.py         |  2 +-
 Allura/allura/lib/helpers.py                    | 10 +++++++++
 .../templates/repo/merge_request_changed.html   | 13 +++++++++++-
 .../tests/functional/test_controllers.py        | 22 +++++++++++++++-----
 4 files changed, 40 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/714cf870/Allura/allura/controllers/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/repository.py b/Allura/allura/controllers/repository.py
index 4be5213..ad8a974 100644
--- a/Allura/allura/controllers/repository.py
+++ b/Allura/allura/controllers/repository.py
@@ -419,7 +419,7 @@ class MergeRequestController(object):
             self.req.source_branch = kw['source_branch']
 
         if self.req.description != kw['description']:
-            changes['Description'] = [self.req.description, kw['description']]
+            changes['Description'] = h.unidiff(self.req.description, kw['description'])
             self.req.description = kw['description']
         with self.req.push_downstream_context():
             self.req.downstream['commit_id'] = c.app.repo.commit(kw['source_branch'])._id

http://git-wip-us.apache.org/repos/asf/allura/blob/714cf870/Allura/allura/lib/helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py
index 83992aa..d109917 100644
--- a/Allura/allura/lib/helpers.py
+++ b/Allura/allura/lib/helpers.py
@@ -1180,3 +1180,13 @@ def map_jinja_filter(ctx, seq, filter_name, *a, **kw):
     """
     filter_ = get_filter(ctx, filter_name)
     return [filter_(value, *a, **kw) for value in seq]
+
+
+def unidiff(old, new):
+    """Returns unified diff between `one` and `two`."""
+    return '\n'.join(difflib.unified_diff(
+        a=old.splitlines(),
+        b=new.splitlines(),
+        fromfile='old',
+        tofile='new',
+        lineterm=''))

http://git-wip-us.apache.org/repos/asf/allura/blob/714cf870/Allura/allura/templates/repo/merge_request_changed.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/repo/merge_request_changed.html b/Allura/allura/templates/repo/merge_request_changed.html
index 1c278e6..dd4059c 100644
--- a/Allura/allura/templates/repo/merge_request_changed.html
+++ b/Allura/allura/templates/repo/merge_request_changed.html
@@ -17,5 +17,16 @@
        under the License.
 -#}
 {% for field, values in changes.iteritems() %}
+{% if field == 'Description': %}
+- **{{ field }}**:
+
+Diff:
+
+~~~~
+{{ values }}
+~~~~
+
+{% else %}
 - **{{ field }}**: {{ values[0] }} --> {{ values[1] }}
-{% endfor %}
\ No newline at end of file
+{% endif %}
+{% endfor %}

http://git-wip-us.apache.org/repos/asf/allura/blob/714cf870/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 90230b5..d7bc19f 100644
--- a/ForgeGit/forgegit/tests/functional/test_controllers.py
+++ b/ForgeGit/forgegit/tests/functional/test_controllers.py
@@ -631,15 +631,27 @@ class TestFork(_TestCase):
         assert '[5c4724]' not in r
         assert '<p>changed description</p' in r
         assert 'Merge Request #1: changed summary (open)' in r
-        assert '''<li>
+        changes = r.html.findAll('div', attrs={'class': 'markdown_content'})[-1]
+        assert unicode(changes) == """
+<div class="markdown_content"><ul>
+<li>
 <p><strong>Source branch</strong>: zz --&gt; master</p>
 </li>
 <li>
-<p><strong>Description</strong>: description --&gt; changed description</p>
+<p><strong>Description</strong>:</p>
 </li>
-<li>
-<p><strong>Summary</strong>: summary --&gt; changed summary</p>
-</li>''' in r
+</ul>
+<p>Diff:</p>
+<div class="codehilite"><pre><span class="gd">--- old</span>
+<span class="gi">+++ new</span>
+<span class="gu">@@ -1 +1 @@</span>
+<span class="gd">-description</span>
+<span class="gi">+changed description</span>
+</pre></div>
+<ul>
+<li><strong>Summary</strong>: summary --&gt; changed summary</li>
+</ul></div>
+""".strip()
 
         r = self.app.get('/p/test/src-git/merge-requests')
         assert '<a href="1/">changed summary</a>' in r


Mime
View raw message