From 4eb891b935b42cd170f029eb8a735f94195d13c5 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 1/2] 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 a39f8b46..5a2ca63b 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 40e05739..9b1099b6 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 fbc2afed..470984a7 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 56f78a88..1dc69f91 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) }) }) }) From 9b2a0d63330ffa825f87a338020634ae9944b6a4 Mon Sep 17 00:00:00 2001 From: PendaGTP <38917281+PendaGTP@users.noreply.github.com> Date: Fri, 10 Jan 2025 14:01:57 +0100 Subject: [PATCH 2/2] refactor: rename noop to nop for consistency --- full-sync.js | 10 +++++----- index.js | 4 ++-- lib/env.js | 2 +- test/unit/lib/env.test.js | 12 ++++++------ test/unit/lib/plugins/branches.test.js | 4 ++-- test/unit/lib/plugins/repository.test.js | 4 ++-- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/full-sync.js b/full-sync.js index 5a2ca63b..8ba1c735 100644 --- a/full-sync.js +++ b/full-sync.js @@ -1,14 +1,14 @@ const appFn = require('./') -const { FULL_SYNC_NOOP } = require('./lib/env') +const { FULL_SYNC_NOP } = require('./lib/env') const { createProbot } = require('probot') -async function performFullSync (appFn, noop) { +async function performFullSync (appFn, nop) { const probot = createProbot() - probot.log.info(`Starting full sync with NOOP=${noop}`) + probot.log.info(`Starting full sync with NOP=${nop}`) try { const app = appFn(probot, {}) - const settings = await app.syncInstallation(noop) + const settings = await app.syncInstallation(nop) if (settings.errors && settings.errors.length > 0) { probot.log.error('Errors occurred during full sync.') @@ -22,7 +22,7 @@ async function performFullSync (appFn, noop) { } } -performFullSync(appFn, FULL_SYNC_NOOP).catch((error) => { +performFullSync(appFn, FULL_SYNC_NOP).catch((error) => { console.error('Fatal error during full sync:', error) process.exit(1) }) diff --git a/index.js b/index.js index 9b1099b6..86d31d9b 100644 --- a/index.js +++ b/index.js @@ -230,7 +230,7 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) => } } - async function syncInstallation (noop = false) { + async function syncInstallation (nop = 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(noop, context) + return syncAllSettings(nop, context) } return null } diff --git a/lib/env.js b/lib/env.js index 470984a7..53d83c33 100644 --- a/lib/env.js +++ b/lib/env.js @@ -6,5 +6,5 @@ module.exports = { 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', - FULL_SYNC_NOOP: process.env.FULL_SYNC_NOOP === 'true' + FULL_SYNC_NOP: process.env.FULL_SYNC_NOP === 'true' } diff --git a/test/unit/lib/env.test.js b/test/unit/lib/env.test.js index 1dc69f91..cd9ea774 100644 --- a/test/unit/lib/env.test.js +++ b/test/unit/lib/env.test.js @@ -28,9 +28,9 @@ describe('env', () => { 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) + it('loads default FULL_SYNC_NOP if not passed', () => { + const FULL_SYNC_NOP = envTest.FULL_SYNC_NOP + expect(FULL_SYNC_NOP).toEqual(false) }) }) @@ -42,7 +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 + process.env.FULL_SYNC_NOP = false }) it('loads override values if passed', () => { @@ -57,8 +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) + const FULL_SYNC_NOP = envTest.FULL_SYNC_NOP + expect(FULL_SYNC_NOP).toEqual(false) }) }) }) diff --git a/test/unit/lib/plugins/branches.test.js b/test/unit/lib/plugins/branches.test.js index 68290ea4..680f5852 100644 --- a/test/unit/lib/plugins/branches.test.js +++ b/test/unit/lib/plugins/branches.test.js @@ -10,9 +10,9 @@ describe('Branches', () => { log.error = jest.fn() function configure (config) { - const noop = false + const nop = false const errors = [] - return new Branches(noop, github, { owner: 'bkeepers', repo: 'test' }, config, log, errors) + return new Branches(nop, github, { owner: 'bkeepers', repo: 'test' }, config, log, errors) } beforeEach(() => { diff --git a/test/unit/lib/plugins/repository.test.js b/test/unit/lib/plugins/repository.test.js index b7af3912..fc4c453b 100644 --- a/test/unit/lib/plugins/repository.test.js +++ b/test/unit/lib/plugins/repository.test.js @@ -17,9 +17,9 @@ describe('Repository', () => { log.error = jest.fn() function configure (config) { - const noop = false + const nop = false const errors = [] - return new Repository(noop, github, { owner: 'bkeepers', repo: 'test' }, config, 1, log, errors) + return new Repository(nop, github, { owner: 'bkeepers', repo: 'test' }, config, 1, log, errors) } describe('sync', () => {