Arlolra has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/164378

Change subject: Add prfun and use Promises on _version route
......................................................................

Add prfun and use Promises on _version route

Change-Id: I57e5971a33420c1aa16c75fd333bbc0264ddc568
---
M api/routes.js
M package.json
2 files changed, 7 insertions(+), 18 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid 
refs/changes/78/164378/1

diff --git a/api/routes.js b/api/routes.js
index f2c9ddb..93cd890 100644
--- a/api/routes.js
+++ b/api/routes.js
@@ -1,6 +1,7 @@
 "use strict";
 
 require('es6-shim');
+require('prfun');
 
 var path = require('path'),
        fs = require('fs'),
@@ -431,23 +432,6 @@
        res.end("User-agent: *\nDisallow: /\n");
 };
 
-function gitVersion( cb ) {
-       fs.exists( path.join( __dirname, '/../.git' ), function ( exists ) {
-               if ( !exists ) {
-                       cb();
-                       return;
-               }
-               childProc.exec(
-                       'git rev-parse HEAD',
-                       function ( error, stdout, stderr ) {
-                               if ( !error ) {
-                                       versionCache.sha = stdout.slice(0, -1);
-                               }
-                               cb();
-               });
-       });
-}
-
 // Return Parsoid version based on package.json + git sha1 if available
 var versionCache;
 routes.version = function( req, res ) {
@@ -458,7 +442,11 @@
                name: pkg.name,
                version: pkg.version
        };
-       gitVersion(function() {
+       Promise.promisify(
+               childProc.exec, false, childProc
+       )( 'git rev-parse HEAD' ).then(function( stdout ) {
+               versionCache.sha = stdout.slice(0, -1);
+       }).finally(function() {
                res.json( versionCache );
        });
 };
diff --git a/package.json b/package.json
index 76ac850..9e86d8c 100644
--- a/package.json
+++ b/package.json
@@ -15,6 +15,7 @@
                "html5": "~1.0.5",
                "html5-entities": "~1.0.0",
                "pegjs": "git+https://github.com/arlolra/pegjs#startOffset";,
+               "prfun": "~1.0.1",
                "request": "~2.40.0",
                "simplediff": "~0.1.1",
                "yargs": "~1.3.1"

-- 
To view, visit https://gerrit.wikimedia.org/r/164378
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I57e5971a33420c1aa16c75fd333bbc0264ddc568
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Arlolra <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to