From 8afb76a177d37af9cef72af2116c632e25f1d3b2 Mon Sep 17 00:00:00 2001 From: Denis Ah-Kang Date: Thu, 21 Jun 2018 12:03:41 +0400 Subject: [PATCH] check if the document was already published before looking for the approval + rely on github teams for directors and comm --- app.js | 3 +++ config.js.example | 2 ++ lib/orchestrator.js | 10 +++++++--- lib/transition-checker.js | 39 +++++++++++++++++++++++++++------------ 4 files changed, 39 insertions(+), 15 deletions(-) diff --git a/app.js b/app.js index 8f89b4fe..f293197f 100644 --- a/app.js +++ b/app.js @@ -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'])); @@ -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) @@ -132,6 +134,7 @@ var processRequest = function (req, res, isTar) { url, tar, token, + editorial, user, tempLocation, httpLocation, diff --git a/config.js.example b/config.js.example index b82b591b..e7f2c848 100644 --- a/config.js.example +++ b/config.js.example @@ -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'; diff --git a/lib/orchestrator.js b/lib/orchestrator.js index acdab338..ad122669 100644 --- a/lib/orchestrator.js +++ b/lib/orchestrator.js @@ -53,6 +53,7 @@ function updateTrShortlink(uri) { var Orchestrator = function (url, tar, token, + isEditorial, user, tempLoc, httpLoc, @@ -60,6 +61,7 @@ var Orchestrator = function (url, this.url = url; this.tar = tar; this.token = token; + this.isEditorial = isEditorial; this.user = user; this.tempLocation = tempLoc; this.httpLocation = httpLoc; @@ -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({ @@ -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( diff --git a/lib/transition-checker.js b/lib/transition-checker.js index 5aad580a..cb2873d0 100644 --- a/lib/transition-checker.js +++ b/lib/transition-checker.js @@ -13,29 +13,30 @@ var TransitionChecker = {}; * @returns {Promise.>} */ -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) { @@ -43,11 +44,25 @@ TransitionChecker.check = function (profile, latestVersion, previousVersion) { 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.")); } } });