Conduit: Create simple mercurial server extension which returns JSON from custom endpoint (
Bug 1346949). r?mars
MozReview-Commit-ID: 4cp6pFQaqD9
--- 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!'})