From cf459faba9896a5439a1701b4545645c7363a1ff Mon Sep 17 00:00:00 2001 From: Denis Ah-Kang Date: Thu, 14 Jun 2018 17:02:59 +0400 Subject: [PATCH] CR: check CR with specberus and check approvals with GH API --- app.js | 2 +- lib/orchestrator.js | 35 ++++++++++++++++++++++ lib/specberus-wrapper.js | 5 +++- lib/transition-checker.js | 62 +++++++++++++++++++++++++++++++++++++++ package.json | 1 + 5 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 lib/transition-checker.js diff --git a/app.js b/app.js index aef95245..8f89b4fe 100644 --- a/app.js +++ b/app.js @@ -110,7 +110,7 @@ var processRequest = function (req, res, isTar) { requests[id]['version'] = meta.version; requests[id]['version-specberus'] = SpecberusWrapper.version; requests[id]['decision'] = decision; - var jobList = ['retrieve-resources', 'metadata', 'specberus', 'third-party-checker', 'publish', 'tr-install', 'update-tr-shortlink']; + var jobList = ['retrieve-resources', 'metadata', 'specberus', 'transition-checker', 'third-party-checker', 'publish', 'tr-install', 'update-tr-shortlink']; if (isTar) jobList.splice(2, 0, 'user-checker'); diff --git a/lib/orchestrator.js b/lib/orchestrator.js index 071253d0..acdab338 100644 --- a/lib/orchestrator.js +++ b/lib/orchestrator.js @@ -14,6 +14,7 @@ var SpecberusWrapper = require('./specberus-wrapper'); var ThirdPartyChecker = require('./third-party-resources-checker'); var TokenChecker = require('./token-checker'); var UserChecker = require('./user-checker'); +var TransitionChecker = require('./transition-checker'); // Configuration file require('../config.js'); @@ -325,6 +326,35 @@ Orchestrator.prototype.runSpecberus = function (httpLocation, }); }; +Orchestrator.prototype.runTransitionChecker = function (profile, latestVersion, previousVersion) { + return new Map({ + name: 'transition-checker', + promise: TransitionChecker.check(profile, latestVersion, previousVersion) + .then(function (errors) { + if (errors.isEmpty()) { + return new Map({ + status: 'ok', + history: 'The document passed transition checker.' + }); + } + else { + return new Map({ + status: 'failure', + errors: errors, + history: 'The document failed transition checker.' + }); + } + }).catch(function (error) { + return new Map({ + status: 'error', + errors: List.of(error.toString()), + history: 'An error occurred while running transition checker.' + }); + }) + }); +}; + + Orchestrator.prototype.runTokenChecker = function (latestVersion, url, token) { return new Map({ name: 'token-checker', @@ -475,6 +505,11 @@ Orchestrator.prototype.next = function (state) { state.get('metadata').get('profile'), state.get('metadata').get('rectrack')); } + else if (state.hasJobStarted('transition-checker')) { + step = this.runTransitionChecker(state.get('metadata').get('profile'), + state.get('metadata').get('latestVersion'), + state.get('metadata').get('previousVersion')); + } else if (state.hasJobStarted('token-checker')) { step = this.runTokenChecker( state.get('metadata').get('latestVersion'), diff --git a/lib/specberus-wrapper.js b/lib/specberus-wrapper.js index 8c5473f3..0f795828 100644 --- a/lib/specberus-wrapper.js +++ b/lib/specberus-wrapper.js @@ -30,8 +30,11 @@ SpecberusWrapper.validate = function (url, profile, isRecTrack) { else if (profile === 'WG-NOTE') { specberusProfile = require('specberus/lib/profiles/TR/WG-NOTE-Echidna'); } + else if (profile === 'CR') { + specberusProfile = require('specberus/lib/profiles/TR/CR-Echidna'); + } else { - return reject(new Error('Only WD and Notes are allowed!')); + return reject(new Error('Only WD, CR and Notes are allowed!')); } sink.on('end-all', function () { diff --git a/lib/transition-checker.js b/lib/transition-checker.js new file mode 100644 index 00000000..83a75e5f --- /dev/null +++ b/lib/transition-checker.js @@ -0,0 +1,62 @@ +'use strict'; + +var List = require('immutable').List; +var Octokat = require('octokat'); + +/** + * @exports lib/transition-checker + */ + +var TransitionChecker = {}; + +/** + * @returns {Promise.>} + */ + +TransitionChecker.check = function (profile, latestVersion, previousVersion) { + return new Promise(function (resolve, reject) { + var editorial = false; + var errors = new List(); + if (profile === 'WD' || profile === 'WG-NOTE') { + resolve(errors); + } + else if (profile === 'CR') { + if (previousVersion.includes("/WD-") || !editorial) { + var shortname = latestVersion.match(new RegExp(/.*\/([^/]+)\/$/))[1]; + var octo = new Octokat({ + token: "" // TODO: create token + }); + + var shortname = 'css-text-decor-3'; + var repo = octo.repos('w3c', 'transitions'); + var approvalText = "Please update the Re"; + + repo.issues.fetch({ + labels: 'Awaiting publication', + state: 'open', + per_page: 100 + }) + .then((content) => { + for (var issue of content.items) { + if (issue.title.endsWith(' ' + shortname)) { + repo.issues(issue.number).comments.fetch() + .then((comments) => { + for (var comment of comments.items) { + if (comment.body.startsWith(approvalText)) { + // TODO: comment.user.login has approved the transition + } + } + }); + } + } + }); + } + } + else { + return reject(new Error('Only WD, CR and Notes are allowed!')); + } + resolve(errors); + }); +}; + +module.exports = TransitionChecker; diff --git a/package.json b/package.json index a78be093..c002c911 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "moment": "2.22.2", "multer": "1.3.0", "node-uuid": "1.4.8", + "octokat": "0.10.0", "passport": "0.4.0", "passport-http": "0.3", "promise": "8.0.1",