hgmo: prune some keys from the returned JSON (bug 1248850); r?dminor draft
authorGregory Szorc <gps@mozilla.com>
Tue, 16 Feb 2016 19:58:55 -0800
changeset 7264 512557dc794505cd89300fcc712bd6d3f27ec28d
parent 7263 09148d3c7d5a3ace7dacdd2de4cb1c1f9678128f
push id641
push usergszorc@mozilla.com
push dateWed, 17 Feb 2016 03:59:02 +0000
reviewersdminor
bugs1248850
hgmo: prune some keys from the returned JSON (bug 1248850); r?dminor This is a very hacky way to avoid a templating issue due to changelogtag missing. Fixing the underlying issue requires handling special return values from Mercurial's internal templating API and I have little desire to do that because those APIs are fragile. It is easier to just remove the output that calls into them to avoid the problem. MozReview-Commit-ID: BmcB5LnfJkj
hgext/hgmo/__init__.py
hgext/hgmo/tests/helpers.sh
hgext/hgmo/tests/test-automationrelevant.t
--- a/hgext/hgmo/__init__.py
+++ b/hgext/hgmo/__init__.py
@@ -371,16 +371,21 @@ def automationrelevancewebcommand(web, r
         entry = webutil.changelistentry(web, ctx, tmpl)
         # Some items in changelistentry are generators, which json.dumps()
         # can't handle. So we expand them.
         for k, v in entry.items():
             # "files" is a generator that attempts to call a template.
             # Don't even bother and just repopulate it.
             if k == 'files':
                 entry['files'] = sorted(ctx.files())
+            # These aren't interesting to us, so prune them. The
+            # original impetus for this was because "changelogtag"
+            # isn't part of the json template and adding it is non-trivial.
+            elif k in ('bookmarks', 'branches', 'changelogtag', 'child', 'inbranch', 'tags'):
+                del entry[k]
             elif isinstance(v, types.GeneratorType):
                 entry[k] = list(v)
 
         csets.append(entry)
 
     req.respond(HTTP_OK, 'application/json')
     return json.dumps({'changesets': csets}, indent=2, sort_keys=True)
 
--- a/hgext/hgmo/tests/helpers.sh
+++ b/hgext/hgmo/tests/helpers.sh
@@ -5,14 +5,14 @@ startserver() {
 [extensions]
 hgmo = $TESTDIR/hgext/hgmo
 
 [web]
 push_ssl = False
 allow_push = *
 EOF
 
-  hg serve -d -p $HGPORT --pid-file hg.pid --hgmo
+  hg serve -d -p $HGPORT --pid-file hg.pid --hgmo -E error.log
   cat hg.pid >> $DAEMON_PIDS
   cd ..
 }
 
 alias http=$TESTDIR/testing/http-request.py
--- a/hgext/hgmo/tests/test-automationrelevant.t
+++ b/hgext/hgmo/tests/test-automationrelevant.t
@@ -107,128 +107,176 @@ Previous push base to draft should add i
   1 push 1 commit 1
   2 push 1 commit 2
   3 push 2 commit 1
   4 push 2 commit 2
   5 push 2 commit 3
 
 web command for exposing automation relevance works
 
-  $ http http://localhost:$HGPORT/json-automationrelevance/3 --header content-type
+  $ http http://localhost:$HGPORT/json-automationrelevance/tip --header content-type
   200
   content-type: application/json
   
   {
     "changesets": [
       {
         "author": "test", 
         "backsoutnodes": [], 
-        "bookmarks": [], 
-        "branches": [], 
         "bugs": [], 
-        "changelogtag": [], 
-        "child": [], 
         "date": [
           0.0, 
           0
         ], 
         "desc": "push 1 commit 1", 
         "extra": {
           "branch": "default"
         }, 
         "files": [
           "foo"
         ], 
-        "inbranch": [], 
         "node": "0a971221ac36075c184743cba0490681eadca983", 
         "parent": [], 
         "pushdate": [
           \d+,  (re)
           0
         ], 
         "pushhead": "cb5c79007e91b09a4ba7ebe9210311491d09e96e", 
         "pushid": 2, 
         "pushnodes": [
           "0a971221ac36075c184743cba0490681eadca983", 
           "cb5c79007e91b09a4ba7ebe9210311491d09e96e"
         ], 
         "pushuser": "testuser", 
         "rev": 1, 
-        "reviewers": [], 
-        "tags": []
+        "reviewers": []
       }, 
       {
         "author": "test", 
         "backsoutnodes": [], 
-        "bookmarks": [], 
-        "branches": [], 
         "bugs": [], 
-        "changelogtag": [], 
-        "child": [], 
         "date": [
           0.0, 
           0
         ], 
         "desc": "push 1 commit 2", 
         "extra": {
           "branch": "default"
         }, 
         "files": [
           "foo"
         ], 
-        "inbranch": [], 
         "node": "cb5c79007e91b09a4ba7ebe9210311491d09e96e", 
         "parent": [], 
         "pushdate": [
           \d+,  (re)
           0
         ], 
         "pushhead": "cb5c79007e91b09a4ba7ebe9210311491d09e96e", 
         "pushid": 2, 
         "pushnodes": [
           "0a971221ac36075c184743cba0490681eadca983", 
           "cb5c79007e91b09a4ba7ebe9210311491d09e96e"
         ], 
         "pushuser": "testuser", 
         "rev": 2, 
-        "reviewers": [], 
-        "tags": []
+        "reviewers": []
       }, 
       {
         "author": "test", 
         "backsoutnodes": [], 
-        "bookmarks": [], 
-        "branches": [], 
         "bugs": [], 
-        "changelogtag": [], 
-        "child": [], 
         "date": [
           0.0, 
           0
         ], 
         "desc": "push 2 commit 1", 
         "extra": {
           "branch": "default"
         }, 
         "files": [
           "foo"
         ], 
-        "inbranch": [], 
         "node": "13855aae8fb3291c663ff46a8510c0e3fa673a4c", 
         "parent": [], 
         "pushdate": [
           \d+,  (re)
           0
         ], 
         "pushhead": "5d04c4fd236c19e241d1587e120b39840344eee8", 
         "pushid": 3, 
         "pushnodes": [
           "13855aae8fb3291c663ff46a8510c0e3fa673a4c", 
           "66a66c6c6ae312ec88240754300468a6cea8f71d", 
           "5d04c4fd236c19e241d1587e120b39840344eee8"
         ], 
         "pushuser": "testuser", 
         "rev": 3, 
-        "reviewers": [], 
-        "tags": []
+        "reviewers": []
+      }, 
+      {
+        "author": "test", 
+        "backsoutnodes": [], 
+        "bugs": [], 
+        "date": [
+          0.0, 
+          0
+        ], 
+        "desc": "push 2 commit 2", 
+        "extra": {
+          "branch": "default"
+        }, 
+        "files": [
+          "foo"
+        ], 
+        "node": "66a66c6c6ae312ec88240754300468a6cea8f71d", 
+        "parent": [], 
+        "pushdate": [
+          \d+,  (re)
+          0
+        ], 
+        "pushhead": "5d04c4fd236c19e241d1587e120b39840344eee8", 
+        "pushid": 3, 
+        "pushnodes": [
+          "13855aae8fb3291c663ff46a8510c0e3fa673a4c", 
+          "66a66c6c6ae312ec88240754300468a6cea8f71d", 
+          "5d04c4fd236c19e241d1587e120b39840344eee8"
+        ], 
+        "pushuser": "testuser", 
+        "rev": 4, 
+        "reviewers": []
+      }, 
+      {
+        "author": "test", 
+        "backsoutnodes": [], 
+        "bugs": [], 
+        "date": [
+          0.0, 
+          0
+        ], 
+        "desc": "push 2 commit 3", 
+        "extra": {
+          "branch": "default"
+        }, 
+        "files": [
+          "foo"
+        ], 
+        "node": "5d04c4fd236c19e241d1587e120b39840344eee8", 
+        "parent": [], 
+        "pushdate": [
+          \d+,  (re)
+          0
+        ], 
+        "pushhead": "5d04c4fd236c19e241d1587e120b39840344eee8", 
+        "pushid": 3, 
+        "pushnodes": [
+          "13855aae8fb3291c663ff46a8510c0e3fa673a4c", 
+          "66a66c6c6ae312ec88240754300468a6cea8f71d", 
+          "5d04c4fd236c19e241d1587e120b39840344eee8"
+        ], 
+        "pushuser": "testuser", 
+        "rev": 5, 
+        "reviewers": []
       }
     ]
   }
+
+  $ cat error.log