Conduit: Create simple mercurial server extension which returns JSON from custom endpoint (Bug 1346949). r?mars draft
authorDavid Walsh <dwalsh@mozilla.com>
Tue, 14 Mar 2017 12:39:43 -0500
changeset 368 8353b7b453d3ee1be25aa791ced1f2f411dce4e8
parent 367 37050a9e2f0223827a416ed1aadb5f89e283214a
push id158
push userbmo:dwalsh@mozilla.com
push dateTue, 14 Mar 2017 17:53:49 +0000
reviewersmars
bugs1346949
Conduit: Create simple mercurial server extension which returns JSON from custom endpoint (Bug 1346949). r?mars MozReview-Commit-ID: 4cp6pFQaqD9
staginghgserver/docker-compose.yml
staginghgserver/docker/hgweb.conf
staginghgserver/extensions/conduit.py
--- a/staginghgserver/docker-compose.yml
+++ b/staginghgserver/docker-compose.yml
@@ -7,16 +7,17 @@ services:
   hgserver:
     build:
       context: ./docker
       dockerfile: ./Dockerfile
     ports:
       - "8080:8080"
     volumes:
       - data-volume:/repos
+      - ./extensions:/hgext
       - ./docker/hgweb.conf:/etc/hg/hgweb.conf
     environment:
       - HG_RELEASE=4.1
       - HG_WEB_CONF=/etc/hg/hgweb.conf
     depends_on:
       - hgrepoinit
 
   hgrepoinit:
--- a/staginghgserver/docker/hgweb.conf
+++ b/staginghgserver/docker/hgweb.conf
@@ -1,6 +1,9 @@
 [paths]
 testrepo = /repos/testrepo
 
 [web]
 allow_push = *
 push_ssl = false
+
+[extensions]
+conduit = /hgext/conduit.py
new file mode 100644
--- /dev/null
+++ b/staginghgserver/extensions/conduit.py
@@ -0,0 +1,22 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import json
+
+from mercurial.hgweb import webcommands
+from mercurial.hgweb.common import HTTP_OK
+
+
+def extsetup(ui):
+    """Standard extension setup routine"""
+    print('Hello from the conduit mercurial extension!')
+
+    setattr(webcommands, 'commitindex', extensioncommand)
+    webcommands.__all__.append('commitindex')
+
+
+def extensioncommand(web, req, tmpl):
+    """Simply dumps a sample JSON to prove the endpoint works"""
+    req.respond(HTTP_OK, 'application/json')
+    return json.dumps({'message': 'Hello from the Conduit extension!'})