Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add missing nop param for full-sync #733

Open
wants to merge 2 commits into
base: main-enterprise
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions full-sync.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
const { createProbot } = require('probot')
const appFn = require('./')
const { FULL_SYNC_NOP } = require('./lib/env')
const { createProbot } = require('probot')

async function performFullSync (appFn, nop) {
const probot = createProbot()
probot.log.info(`Starting full sync with NOP=${nop}`)

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(nop)

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_NOP).catch((error) => {
console.error('Fatal error during full sync:', error)
process.exit(1)
})
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
}
}

async function syncInstallation () {
async function syncInstallation (nop = false) {
robot.log.trace('Fetching installations')
const github = await robot.auth()

Expand All @@ -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(nop, context)
}
return null
}
Expand Down
3 changes: 2 additions & 1 deletion lib/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -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_NOP: process.env.FULL_SYNC_NOP === 'true'
}
8 changes: 8 additions & 0 deletions test/unit/lib/env.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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_NOP if not passed', () => {
const FULL_SYNC_NOP = envTest.FULL_SYNC_NOP
expect(FULL_SYNC_NOP).toEqual(false)
})
})

describe('load override values', () => {
Expand All @@ -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_NOP = false
})

it('loads override values if passed', () => {
Expand All @@ -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_NOP = envTest.FULL_SYNC_NOP
expect(FULL_SYNC_NOP).toEqual(false)
})
})
})
4 changes: 2 additions & 2 deletions test/unit/lib/plugins/branches.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/lib/plugins/repository.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down