Arlolra has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/336737 )

Change subject: Use sync-parserTests.js with other targets
......................................................................

Use sync-parserTests.js with other targets

Change-Id: Iaf019dc1f5507555abc55ab65289a5a071859cb6
---
M tests/parserTests.json
M tools/fetch-parserTests.txt.js
M tools/sync-parserTests.js
3 files changed, 31 insertions(+), 29 deletions(-)


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

diff --git a/tests/parserTests.json b/tests/parserTests.json
index dbd4089..425a52d 100644
--- a/tests/parserTests.json
+++ b/tests/parserTests.json
@@ -1,25 +1,13 @@
 {
        "parserTests.txt": {
-               "downloadUrl": {
-                       "host": "raw.githubusercontent.com",
-                       "path": 
"/wikimedia/mediawiki/COMMIT-SHA/tests/parser/parserTests.txt"
-               },
-               "historyUrl": {
-                       "host": "api.github.com",
-                       "path": 
"/repos/wikimedia/mediawiki/commits?path=tests/parser/parserTests.txt"
-               },
+               "repo": "/wikimedia/mediawiki/",
+               "path": "tests/parser/parserTests.txt",
                "expectedSHA1": "e356e32b279671d5c662aa4409d64425c14adb6f",
                "latestCommit": "4a07505402a56a32be23a570f4bd1fe33dd542a9"
        },
        "citeParserTests.txt": {
-               "downloadUrl": {
-                       "host": "raw.githubusercontent.com",
-                       "path": 
"/wikimedia/mediawiki-extensions-Cite/COMMIT-SHA/tests/parser/citeParserTests.txt"
-               },
-               "historyUrl": {
-                       "host": "api.github.com",
-                       "path": 
"/repos/wikimedia/mediawiki-extensions-Cite/commits?path=tests/parser/citeParserTests.txt"
-               },
+               "repo": "/wikimedia/mediawiki-extensions-Cite/",
+               "path": "tests/parser/citeParserTests.txt",
                "expectedSHA1": "1db0e82134bfc66c2b9ba1c899fc00de50f27bcc",
                "latestCommit": "440b3179086fe4e52bef28f293918381aa45ff1f"
        }
diff --git a/tools/fetch-parserTests.txt.js b/tools/fetch-parserTests.txt.js
index c675e0c..6fb47db 100755
--- a/tools/fetch-parserTests.txt.js
+++ b/tools/fetch-parserTests.txt.js
@@ -36,10 +36,11 @@
 var fetch = function(targetName, gitCommit, cb) {
        console.log('Fetching parserTests.txt from mediawiki/core');
        var file = testFiles[targetName];
-       var url = Object.assign({
+       var url = {
+               host: 'raw.githubusercontent.com',
+               path: file.repo + (gitCommit || file.latestCommit) + '/' + 
file.path,
                headers: { 'user-agent': 'wikimedia-parsoid' },
-       }, file.downloadUrl);
-       url.path = url.path.replace(/COMMIT-SHA/, gitCommit || 
file.latestCommit);
+       };
        https.get(url, function(result) {
                var targetPath = path.join(testDir, targetName);
                var out = fs.createWriteStream(targetPath);
@@ -80,9 +81,11 @@
        var file = testFiles[targetName];
 
        // fetch the history page
-       var url = Object.assign({
+       var url = {
+               host: 'api.github.com',
+               path: '/repos' + file.repo + 'commits?path=' + file.path,
                headers: { 'user-agent': 'wikimedia-parsoid' },
-       }, file.historyUrl);
+       };
        https.get(url, function(result) {
                var res = '';
                result.setEncoding('utf8');
diff --git a/tools/sync-parserTests.js b/tools/sync-parserTests.js
index 955b5da..30cd090 100755
--- a/tools/sync-parserTests.js
+++ b/tools/sync-parserTests.js
@@ -39,7 +39,11 @@
 var path = require('path');
 var fs = require('fs');
 
-var fetcher = require(path.join(__dirname, 
'../tests/parserTests.json'))['parserTests.txt'];
+var testDir = path.join(__dirname, '../tests/');
+var testFilesPath = path.join(testDir, 'parserTests.json');
+var testFiles = require(testFilesPath);
+
+var DEFAULT_TARGET = 'parserTests.txt';
 
 var strip = function(s) {
        return s.replace(/(^\s+)|(\s+$)/g, '');
@@ -47,12 +51,12 @@
 
 (function() {
        // Option parsing and helpful messages.
-       var usage = 'Usage: $0 <mediawiki checkout path> <branch name>';
+       var usage = 'Usage: $0 <mediawiki checkout path> <branch name> 
<target>';
        var opts = yargs.usage(usage, {
                'help': { description: 'Show this message' },
        });
        var argv = opts.argv;
-       if (argv.help || argv._.length !== 2) {
+       if (argv.help || argv._.length < 2 || argv._.length > 3) {
                opts.showHelp();
                var morehelp = fs.readFileSync(__filename, 'utf8');
                morehelp = strip(morehelp.split(/== USAGE ==/, 2)[1]);
@@ -63,7 +67,15 @@
        // Ok, let's do this thing!
        var mwpath = path.resolve(argv._[0]);
        var branch = argv._[1];
-       var oldhash = fetcher.latestCommit;
+       var targetName = argv._[2] || DEFAULT_TARGET;
+
+       if (!testFiles.hasOwnProperty(targetName)) {
+               console.warn(targetName + ' not defined in parserTests.json');
+               return;
+       }
+
+       var file = testFiles[targetName];
+       var oldhash = file.latestCommit;
 
        var mwexec = function(cmd) {
                return function(callback) {
@@ -79,9 +91,8 @@
        };
 
        var q = [];
-       var PARSERTESTS = 'parserTests.txt';
-       var pPARSERTESTS = path.join(__dirname, '..', 'tests', PARSERTESTS);
-       var mwPARSERTESTS = path.join(mwpath, 'tests', 'parser', PARSERTESTS);
+       var pPARSERTESTS = path.join(__dirname, '..', 'tests', targetName);
+       var mwPARSERTESTS = path.join(mwpath, file.path);
 
        // Fetch current Parsoid git hash.
        var phash;
@@ -128,7 +139,7 @@
 
        // Make a new mediawiki/core commit with an appropriate message.
        q.push(function(callback) {
-               var commitmsg = 'Sync up with Parsoid parserTests.';
+               var commitmsg = 'Sync up with Parsoid ' + targetName;
                commitmsg += '\n\nThis now aligns with Parsoid commit ' + phash;
                mwexec(['git', 'commit', '-m', commitmsg, 
mwPARSERTESTS])(callback);
        });

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iaf019dc1f5507555abc55ab65289a5a071859cb6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Arlolra <abrea...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to