From ef701087d4f14363202bcd931dab8fe6fc193b48 Mon Sep 17 00:00:00 2001 From: PendaGTP <38917281+PendaGTP@users.noreply.github.com> Date: Wed, 8 Jan 2025 13:10:16 +0100 Subject: [PATCH] fix: add missing noop param for full-sync --- full-sync.js | 33 +++++++++++++++++++++------------ index.js | 4 ++-- lib/env.js | 3 ++- test/unit/lib/env.test.js | 8 ++++++++ 4 files changed, 33 insertions(+), 15 deletions(-) diff --git a/full-sync.js b/full-sync.js index a39f8b464..5a2ca63b8 100644 --- a/full-sync.js +++ b/full-sync.js @@ -1,19 +1,28 @@ -const { createProbot } = require('probot') const appFn = require('./') +const { FULL_SYNC_NOOP } = require('./lib/env') +const { createProbot } = require('probot') + +async function performFullSync (appFn, noop) { + const probot = createProbot() + probot.log.info(`Starting full sync with NOOP=${noop}`) -const probot = createProbot() -probot.log.info('Starting full sync.') -const app = appFn(probot, {}) -app.syncInstallation() - .then(settings => { - if (settings.errors.length > 0) { + try { + const app = appFn(probot, {}) + const settings = await app.syncInstallation(noop) + + if (settings.errors && settings.errors.length > 0) { probot.log.error('Errors occurred during full sync.') process.exit(1) - } else { - probot.log.info('Done with full sync.') } - }) - .catch(error => { + + probot.log.info('Full sync completed successfully.') + } catch (error) { process.stdout.write(`Unexpected error during full sync: ${error}\n`) process.exit(1) - }) + } +} + +performFullSync(appFn, FULL_SYNC_NOOP).catch((error) => { + console.error('Fatal error during full sync:', error) + process.exit(1) +}) diff --git a/index.js b/index.js index 40e057391..9b1099b65 100644 --- a/index.js +++ b/index.js @@ -230,7 +230,7 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) => } } - async function syncInstallation () { + async function syncInstallation (noop = false) { robot.log.trace('Fetching installations') const github = await robot.auth() @@ -249,7 +249,7 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) => log: robot.log, repo: () => { return { repo: env.ADMIN_REPO, owner: installation.account.login } } } - return syncAllSettings(false, context) + return syncAllSettings(noop, context) } return null } diff --git a/lib/env.js b/lib/env.js index fbc2afed9..470984a71 100644 --- a/lib/env.js +++ b/lib/env.js @@ -5,5 +5,6 @@ module.exports = { DEPLOYMENT_CONFIG_FILE: process.env.DEPLOYMENT_CONFIG_FILE || 'deployment-settings.yml', CREATE_PR_COMMENT: process.env.CREATE_PR_COMMENT || 'true', CREATE_ERROR_ISSUE: process.env.CREATE_ERROR_ISSUE || 'true', - BLOCK_REPO_RENAME_BY_HUMAN: process.env.BLOCK_REPO_RENAME_BY_HUMAN || 'false' + BLOCK_REPO_RENAME_BY_HUMAN: process.env.BLOCK_REPO_RENAME_BY_HUMAN || 'false', + FULL_SYNC_NOOP: process.env.FULL_SYNC_NOOP === 'true' } diff --git a/test/unit/lib/env.test.js b/test/unit/lib/env.test.js index 56f78a883..1dc69f91b 100644 --- a/test/unit/lib/env.test.js +++ b/test/unit/lib/env.test.js @@ -27,6 +27,11 @@ describe('env', () => { const CREATE_PR_COMMENT = envTest.CREATE_PR_COMMENT expect(CREATE_PR_COMMENT).toEqual('true') }) + + it('loads default FULL_SYNC_NOOP if not passed', () => { + const FULL_SYNC_NOOP = envTest.FULL_SYNC_NOOP + expect(FULL_SYNC_NOOP).toEqual(false) + }) }) describe('load override values', () => { @@ -37,6 +42,7 @@ describe('env', () => { process.env.SETTINGS_FILE_PATH = 'safe-settings.yml' process.env.DEPLOYMENT_CONFIG_FILE = 'safe-settings-deployment.yml' process.env.CREATE_PR_COMMENT = 'false' + process.env.FULL_SYNC_NOOP = false }) it('loads override values if passed', () => { @@ -51,6 +57,8 @@ describe('env', () => { expect(DEPLOYMENT_CONFIG_FILE).toEqual('safe-settings-deployment.yml') const CREATE_PR_COMMENT = envTest.CREATE_PR_COMMENT expect(CREATE_PR_COMMENT).toEqual('false') + const FULL_SYNC_NOOP = envTest.FULL_SYNC_NOOP + expect(FULL_SYNC_NOOP).toEqual(false) }) }) })