Skip to content

Commit

Permalink
CR: check CR with specberus and check approvals with GH API
Browse files Browse the repository at this point in the history
  • Loading branch information
deniak committed Jun 14, 2018
1 parent 0340947 commit cf459fa
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
35 changes: 35 additions & 0 deletions lib/orchestrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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'),
Expand Down
5 changes: 4 additions & 1 deletion lib/specberus-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
62 changes: 62 additions & 0 deletions lib/transition-checker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
'use strict';

var List = require('immutable').List;
var Octokat = require('octokat');

/**
* @exports lib/transition-checker
*/

var TransitionChecker = {};

/**
* @returns {Promise.<List.<String>>}
*/

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;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit cf459fa

Please sign in to comment.