Skip to content

Commit

Permalink
check if the document was already published before looking for the ap…
Browse files Browse the repository at this point in the history
…proval + rely on github teams for directors and comm
  • Loading branch information
deniak committed Jun 21, 2018
1 parent 4653d0e commit 8afb76a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 15 deletions.
3 changes: 3 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ var processRequest = function (req, res, isTar) {
var decision = req.body ? req.body.decision : null;
var url = (!isTar && req.body) ? req.body.url : null;
var token = (!isTar && req.body) ? req.body.token : null;
var editorial = req.body ? req.body.editorial : false;
var tar = (isTar) ? req.file : null;
var user = req.user ? req.user : null;
var dryRun = Boolean(req.body && req.body['dry-run'] && /^true$/i.test(req.body['dry-run']));
Expand All @@ -110,6 +111,7 @@ var processRequest = function (req, res, isTar) {
requests[id]['version'] = meta.version;
requests[id]['version-specberus'] = SpecberusWrapper.version;
requests[id]['decision'] = decision;
requests[id]['editorial'] = editorial;
var jobList = ['retrieve-resources', 'metadata', 'specberus', 'transition-checker', 'third-party-checker', 'publish', 'tr-install', 'update-tr-shortlink'];

if (isTar)
Expand All @@ -132,6 +134,7 @@ var processRequest = function (req, res, isTar) {
url,
tar,
token,
editorial,
user,
tempLocation,
httpLocation,
Expand Down
2 changes: 2 additions & 0 deletions config.js.example
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ global.LDAP_SEARCH_BASE = 'ou=user,dc=example,dc=org';
// LDAP_BIND_DN must contain the placeholder {{username}}
global.LDAP_BIND_DN = 'uid={{username}},ou=user,dc=example,dc=org';
global.GH_TOKEN = '123foobar';
global.GH_DIRECTOR_TEAM_ID = '2797096';
global.GH_COMM_TEAM_ID = '2794457';
10 changes: 7 additions & 3 deletions lib/orchestrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ function updateTrShortlink(uri) {
var Orchestrator = function (url,
tar,
token,
isEditorial,
user,
tempLoc,
httpLoc,
resultLoc) {
this.url = url;
this.tar = tar;
this.token = token;
this.isEditorial = isEditorial;
this.user = user;
this.tempLocation = tempLoc;
this.httpLocation = httpLoc;
Expand Down Expand Up @@ -326,10 +328,10 @@ Orchestrator.prototype.runSpecberus = function (httpLocation,
});
};

Orchestrator.prototype.runTransitionChecker = function (profile, latestVersion, previousVersion) {
Orchestrator.prototype.runTransitionChecker = function (profile, latestVersion, previousVersion, isEditorial, isUpdate) {
return new Map({
name: 'transition-checker',
promise: TransitionChecker.check(profile, latestVersion, previousVersion)
promise: TransitionChecker.check(profile, latestVersion, previousVersion, isEditorial, isUpdate)
.then(function (errors) {
if (errors.isEmpty()) {
return new Map({
Expand Down Expand Up @@ -508,7 +510,9 @@ Orchestrator.prototype.next = function (state) {
else if (state.hasJobStarted('transition-checker')) {
step = this.runTransitionChecker(state.get('metadata').get('profile'),
state.get('metadata').get('latestVersion'),
state.get('metadata').get('previousVersion'));
state.get('metadata').get('previousVersion'),
this.isEditorial,
state.get('metadata').get('updated'));
}
else if (state.hasJobStarted('token-checker')) {
step = this.runTokenChecker(
Expand Down
39 changes: 27 additions & 12 deletions lib/transition-checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,56 @@ var TransitionChecker = {};
* @returns {Promise.<List.<String>>}
*/

TransitionChecker.check = function (profile, latestVersion, previousVersion) {
TransitionChecker.check = function (profile, latestVersion, previousVersion, isEditorial, isUpdate) {
return new Promise(function (resolve, reject) {
var editorial = false;
var errors = new List();
if (profile === 'WD' || profile === 'WG-NOTE') {
if (profile === 'WD' || profile === 'WG-NOTE' || isUpdate) {
resolve(errors);
}
else if (profile === 'CR') {
if (previousVersion.includes("/WD-") || !editorial) {
var shortname = latestVersion.match(new RegExp(/.*\/([^/]+)\/$/))[1];
if (previousVersion.includes("/WD-") || !isEditorial) {
var octo = new Octokat({
token: global.GH_TOKEN;
token: global.GH_TOKEN
});

var shortname = 'css-text-decor-3';
var repo = octo.repos('w3c', 'transitions');
var approvalText = "Please update the Re";

var shortname = latestVersion.match(new RegExp(/.*\/([^/]+)\/$/))[1];
var directorApproval = "Transition approved.";
var commApproval = "Draft transition approved."
var directorApprovalFound = false;
var commApprovalFound = false;

repo.issues.fetch(
{
labels: 'Awaiting publication',
state: 'open',
per_page: 100
per_page: 100 // TODO: get all the issues, not just the first 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
if (comment.body.startsWith(directorApproval)) {
// director's approval
octo.teams(global.GH_DIRECTOR_TEAM_ID).members(comment.user.login).fetch((err, res) => {
if (!err) directorApprovalFound = true;
});
} else if (comment.body.startsWith(commApproval)) {
// comm's approval
octo.teams(global.GH_COMM_TEAM_ID).members(comment.user.login).fetch((err, res) => {
if (!err) commApprovalFound = true;
});
}
}
if (!directorApprovalFound) errors.push("Director's approval not found".);
if (!commApprovalFound) errors.push("Communication team's approval not found.");
resolve(errors);
});
} else {
// issue not found
reject(new Error("Issue not found on the github repository w3c/transitions."));
}
}
});
Expand Down

0 comments on commit 8afb76a

Please sign in to comment.