From 17bbd47fcb58f7e62a87bc8e0b07c809cd26c563 Mon Sep 17 00:00:00 2001 From: Mike McNeil Date: Thu, 17 Feb 2022 04:40:46 -0600 Subject: [PATCH] support reopening PRs and add verbose logs (#4257) --- .../api/controllers/webhooks/receive-from-github.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/website/api/controllers/webhooks/receive-from-github.js b/website/api/controllers/webhooks/receive-from-github.js index 7e6582da2f..b109611d52 100644 --- a/website/api/controllers/webhooks/receive-from-github.js +++ b/website/api/controllers/webhooks/receive-from-github.js @@ -183,10 +183,9 @@ module.exports = { if (action === 'edited' && pr.state !== 'open') {// PR edited ‡ // This is an edit to an already-closed pull request. // (Do nothing.) - } else if (action === 'reopened') {// PR reopened ‡ - // This is a closed pull request, being reopened. - // (Do nothing.) - } else {// PR opened ‡ + } else {// Either: + // PR opened ‡ (Newly opened.) + // PR reopened ‡ (This is a closed pull request, being reopened. `action === 'reopened'`) let baseHeaders = { 'User-Agent': 'Fleetie pie', @@ -221,17 +220,20 @@ module.exports = { let changedPaths = _.pluck(await sails.helpers.http.get(`https://api.github.com/repos/${owner}/${repo}/pulls/${prNumber}/files`, { per_page: 100,//eslint-disable-line camelcase }, baseHeaders), 'filename');// (don't worry, it's the whole path, not the filename) + sails.log.verbose(`Received notice that a new PR (#${prNumber}) was opened that changes the following paths:`, changedPaths); isSenderDRIForAllChangedPaths = _.all(changedPaths, (changedPath)=>{ changedPath = changedPath.replace(/\/+$/,'');// « trim trailing slashes, just in case (b/c otherwise could loop forever) require('assert')(sender.login !== undefined); + sails.log.verbose(`…checking DRI of changed path "${changedPath}"`); if (sender.login === DRI_BY_PATH[changedPath]) { return true; } let numRemainingPathsToCheck = changedPath.split('/').length; while (numRemainingPathsToCheck > 0) { let ancestralPath = changedPath.split('/').slice(0, -1 * numRemainingPathsToCheck).join('/'); + sails.log.verbose(`…checking DRI of ancestral path "${ancestralPath}" for changed path`); if (sender.login === DRI_BY_PATH[ancestralPath]) { return true; }