Skip to content

Commit c674c20

Browse files
PendaGTPdecyjphr
andauthored
fix: add missing nop param for full-sync (#733)
* fix: add missing noop param for full-sync * refactor: rename noop to nop for consistency --------- Co-authored-by: Yadhav Jayaraman <[email protected]>
1 parent 8503a94 commit c674c20

File tree

6 files changed

+37
-19
lines changed

6 files changed

+37
-19
lines changed

full-sync.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
1-
const { createProbot } = require('probot')
21
const appFn = require('./')
2+
const { FULL_SYNC_NOP } = require('./lib/env')
3+
const { createProbot } = require('probot')
4+
5+
async function performFullSync (appFn, nop) {
6+
const probot = createProbot()
7+
probot.log.info(`Starting full sync with NOP=${nop}`)
38

4-
const probot = createProbot()
5-
probot.log.info('Starting full sync.')
6-
const app = appFn(probot, {})
7-
app.syncInstallation()
8-
.then(settings => {
9-
if (settings.errors.length > 0) {
9+
try {
10+
const app = appFn(probot, {})
11+
const settings = await app.syncInstallation(nop)
12+
13+
if (settings.errors && settings.errors.length > 0) {
1014
probot.log.error('Errors occurred during full sync.')
1115
process.exit(1)
12-
} else {
13-
probot.log.info('Done with full sync.')
1416
}
15-
})
16-
.catch(error => {
17+
18+
probot.log.info('Full sync completed successfully.')
19+
} catch (error) {
1720
process.stdout.write(`Unexpected error during full sync: ${error}\n`)
1821
process.exit(1)
19-
})
22+
}
23+
}
24+
25+
performFullSync(appFn, FULL_SYNC_NOP).catch((error) => {
26+
console.error('Fatal error during full sync:', error)
27+
process.exit(1)
28+
})

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
230230
}
231231
}
232232

233-
async function syncInstallation () {
233+
async function syncInstallation (nop = false) {
234234
robot.log.trace('Fetching installations')
235235
const github = await robot.auth()
236236

@@ -249,7 +249,7 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
249249
log: robot.log,
250250
repo: () => { return { repo: env.ADMIN_REPO, owner: installation.account.login } }
251251
}
252-
return syncAllSettings(false, context)
252+
return syncAllSettings(nop, context)
253253
}
254254
return null
255255
}

lib/env.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ module.exports = {
55
DEPLOYMENT_CONFIG_FILE_PATH: process.env.DEPLOYMENT_CONFIG_FILE || 'deployment-settings.yml',
66
CREATE_PR_COMMENT: process.env.CREATE_PR_COMMENT || 'true',
77
CREATE_ERROR_ISSUE: process.env.CREATE_ERROR_ISSUE || 'true',
8-
BLOCK_REPO_RENAME_BY_HUMAN: process.env.BLOCK_REPO_RENAME_BY_HUMAN || 'false'
8+
BLOCK_REPO_RENAME_BY_HUMAN: process.env.BLOCK_REPO_RENAME_BY_HUMAN || 'false',
9+
FULL_SYNC_NOP: process.env.FULL_SYNC_NOP === 'true'
910
}

test/unit/lib/env.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ describe('env', () => {
2727
const CREATE_PR_COMMENT = envTest.CREATE_PR_COMMENT
2828
expect(CREATE_PR_COMMENT).toEqual('true')
2929
})
30+
31+
it('loads default FULL_SYNC_NOP if not passed', () => {
32+
const FULL_SYNC_NOP = envTest.FULL_SYNC_NOP
33+
expect(FULL_SYNC_NOP).toEqual(false)
34+
})
3035
})
3136

3237
describe('load override values', () => {
@@ -37,6 +42,7 @@ describe('env', () => {
3742
process.env.SETTINGS_FILE_PATH = 'safe-settings.yml'
3843
process.env.DEPLOYMENT_CONFIG_FILE = 'safe-settings-deployment.yml'
3944
process.env.CREATE_PR_COMMENT = 'false'
45+
process.env.FULL_SYNC_NOP = false
4046
})
4147

4248
it('loads override values if passed', () => {
@@ -51,6 +57,8 @@ describe('env', () => {
5157
expect(DEPLOYMENT_CONFIG_FILE_PATH).toEqual('safe-settings-deployment.yml')
5258
const CREATE_PR_COMMENT = envTest.CREATE_PR_COMMENT
5359
expect(CREATE_PR_COMMENT).toEqual('false')
60+
const FULL_SYNC_NOP = envTest.FULL_SYNC_NOP
61+
expect(FULL_SYNC_NOP).toEqual(false)
5462
})
5563
})
5664
})

test/unit/lib/plugins/branches.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ describe('Branches', () => {
1010
log.error = jest.fn()
1111

1212
function configure (config) {
13-
const noop = false
13+
const nop = false
1414
const errors = []
15-
return new Branches(noop, github, { owner: 'bkeepers', repo: 'test' }, config, log, errors)
15+
return new Branches(nop, github, { owner: 'bkeepers', repo: 'test' }, config, log, errors)
1616
}
1717

1818
beforeEach(() => {

test/unit/lib/plugins/repository.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ describe('Repository', () => {
1717
log.error = jest.fn()
1818

1919
function configure (config) {
20-
const noop = false
20+
const nop = false
2121
const errors = []
22-
return new Repository(noop, github, { owner: 'bkeepers', repo: 'test' }, config, 1, log, errors)
22+
return new Repository(nop, github, { owner: 'bkeepers', repo: 'test' }, config, 1, log, errors)
2323
}
2424

2525
describe('sync', () => {

0 commit comments

Comments
 (0)