diff --git a/index.js b/index.js index 40e057391..1ab3d3e4a 100644 --- a/index.js +++ b/index.js @@ -28,7 +28,7 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) => if (nop) { let filename = env.SETTINGS_FILE_PATH if (!deploymentConfig) { - filename = env.DEPLOYMENT_CONFIG_FILE + filename = env.DEPLOYMENT_CONFIG_FILE_PATH deploymentConfig = {} } const nopcommand = new NopCommand(filename, repo, null, e, 'ERROR') @@ -53,7 +53,7 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) => if (nop) { let filename = env.SETTINGS_FILE_PATH if (!deploymentConfig) { - filename = env.DEPLOYMENT_CONFIG_FILE + filename = env.DEPLOYMENT_CONFIG_FILE_PATH deploymentConfig = {} } const nopcommand = new NopCommand(filename, repo, null, e, 'ERROR') @@ -78,7 +78,7 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) => if (nop) { let filename = env.SETTINGS_FILE_PATH if (!deploymentConfig) { - filename = env.DEPLOYMENT_CONFIG_FILE + filename = env.DEPLOYMENT_CONFIG_FILE_PATH deploymentConfig = {} } const nopcommand = new NopCommand(filename, repo, null, e, 'ERROR') @@ -104,7 +104,7 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) => if (nop) { let filename = env.SETTINGS_FILE_PATH if (!deploymentConfig) { - filename = env.DEPLOYMENT_CONFIG_FILE + filename = env.DEPLOYMENT_CONFIG_FILE_PATH deploymentConfig = {} } const nopcommand = new NopCommand(filename, repo, null, e, 'ERROR') @@ -123,7 +123,7 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) => */ async function loadYamlFileSystem () { if (deploymentConfig === undefined) { - const deploymentConfigPath = env.DEPLOYMENT_CONFIG_FILE + const deploymentConfigPath = env.DEPLOYMENT_CONFIG_FILE_PATH if (fs.existsSync(deploymentConfigPath)) { deploymentConfig = yaml.load(fs.readFileSync(deploymentConfigPath)) } else { @@ -134,7 +134,7 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) => } function getAllChangedSubOrgConfigs (payload) { - const settingPattern = new Glob(`${env.CONFIG_PATH}/suborgs/*.yml`) + const settingPattern = Settings.SUB_ORG_PATTERN // Changes will be an array of files that were added const added = payload.commits.map(c => { return (c.added.filter(s => { @@ -158,7 +158,7 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) => } function getAllChangedRepoConfigs (payload, owner) { - const settingPattern = new Glob(`${env.CONFIG_PATH}/repos/*.yml`) + const settingPattern = Settings.REPO_PATTERN // Changes will be an array of files that were added const added = payload.commits.map(c => { return (c.added.filter(s => { @@ -270,11 +270,11 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) => } const settingsModified = payload.commits.find(commit => { - return commit.added.includes(Settings.FILE_NAME) || - commit.modified.includes(Settings.FILE_NAME) + return commit.added.includes(Settings.FILE_PATH) || + commit.modified.includes(Settings.FILE_PATH) }) if (settingsModified) { - robot.log.debug(`Changes in '${Settings.FILE_NAME}' detected, doing a full synch...`) + robot.log.debug(`Changes in '${Settings.FILE_PATH}' detected, doing a full synch...`) return syncAllSettings(false, context) } @@ -292,7 +292,7 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) => })) } - robot.log.debug(`No changes in '${Settings.FILE_NAME}' detected, returning...`) + robot.log.debug(`No changes in '${Settings.FILE_PATH}' detected, returning...`) }) robot.on('create', async context => { @@ -597,21 +597,21 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) => const changes = await context.octokit.repos.compareCommitsWithBasehead(params) const files = changes.data.files.map(f => { return f.filename }) - const settingsModified = files.includes(Settings.FILE_NAME) + const settingsModified = files.includes(Settings.FILE_PATH) if (settingsModified) { - robot.log.debug(`Changes in '${Settings.FILE_NAME}' detected, doing a full synch...`) + robot.log.debug(`Changes in '${Settings.FILE_PATH}' detected, doing a full synch...`) return syncAllSettings(true, context, context.repo(), pull_request.head.ref) } - const repoChanges = getChangedRepoConfigName(new Glob(`${env.CONFIG_PATH}/repos/*.yml`), files, context.repo().owner) + const repoChanges = getChangedRepoConfigName(Settings.REPO_PATTERN, files, context.repo().owner) if (repoChanges.length > 0) { return Promise.all(repoChanges.map(repo => { return syncSettings(true, context, repo, pull_request.head.ref) })) } - const subOrgChanges = getChangedSubOrgConfigName(new Glob(`${env.CONFIG_PATH}/suborgs/*.yml`), files, context.repo().owner) + const subOrgChanges = getChangedSubOrgConfigName(Settings.SUB_ORG_PATTERN, files, context.repo().owner) if (subOrgChanges.length) { return Promise.all(subOrgChanges.map(suborg => { return syncSubOrgSettings(true, context, suborg, context.repo(), pull_request.head.ref) diff --git a/lib/deploymentConfig.js b/lib/deploymentConfig.js index e515c91b1..e62ba9081 100644 --- a/lib/deploymentConfig.js +++ b/lib/deploymentConfig.js @@ -13,7 +13,7 @@ class DeploymentConfig { static overridevalidators = {} static { - const deploymentConfigPath = process.env.DEPLOYMENT_CONFIG_FILE ? process.env.DEPLOYMENT_CONFIG_FILE : 'deployment-settings.yml' + const deploymentConfigPath = env.DEPLOYMENT_CONFIG_FILE_PATH if (fs.existsSync(deploymentConfigPath)) { this.config = yaml.load(fs.readFileSync(deploymentConfigPath)) || {} } else { diff --git a/lib/env.js b/lib/env.js index fbc2afed9..48e34b9ce 100644 --- a/lib/env.js +++ b/lib/env.js @@ -2,7 +2,7 @@ module.exports = { ADMIN_REPO: process.env.ADMIN_REPO || 'admin', CONFIG_PATH: process.env.CONFIG_PATH || '.github', SETTINGS_FILE_PATH: process.env.SETTINGS_FILE_PATH || 'settings.yml', - DEPLOYMENT_CONFIG_FILE: process.env.DEPLOYMENT_CONFIG_FILE || 'deployment-settings.yml', + DEPLOYMENT_CONFIG_FILE_PATH: 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' diff --git a/lib/plugins/branches.js b/lib/plugins/branches.js index fb43a8d76..d28e2f905 100644 --- a/lib/plugins/branches.js +++ b/lib/plugins/branches.js @@ -33,7 +33,7 @@ module.exports = class Branches extends ErrorStash { let p = Object.assign(this.repo, { branch: branch.name }) if (branch.name === 'default') { p = Object.assign(this.repo, { branch: currentRepo.data.default_branch }) - this.log(`Deleting default branch protection for branch ${currentRepo.data.default_branch}`) + this.log.debug(`Deleting default branch protection for branch ${currentRepo.data.default_branch}`) } // Hack to handle closures and keep params from changing const params = Object.assign({}, p) @@ -50,7 +50,7 @@ module.exports = class Branches extends ErrorStash { let p = Object.assign(this.repo, { branch: branch.name }) if (branch.name === 'default') { p = Object.assign(this.repo, { branch: currentRepo.data.default_branch }) - // this.log(`Setting default branch protection for branch ${currentRepo.data.default_branch}`) + // this.log.debug(`Setting default branch protection for branch ${currentRepo.data.default_branch}`) } // Hack to handle closures and keep params from changing const params = Object.assign({}, p) @@ -80,7 +80,7 @@ module.exports = class Branches extends ErrorStash { return Promise.resolve(resArray) } this.log.debug(`Adding branch protection ${JSON.stringify(params)}`) - return this.github.repos.updateBranchProtection(params).then(res => this.log(`Branch protection applied successfully ${JSON.stringify(res.url)}`)).catch(e => { this.logError(`Error applying branch protection ${JSON.stringify(e)}`); return [] }) + return this.github.repos.updateBranchProtection(params).then(res => this.log.debug(`Branch protection applied successfully ${JSON.stringify(res.url)}`)).catch(e => { this.logError(`Error applying branch protection ${JSON.stringify(e)}`); return [] }) }).catch((e) => { if (e.status === 404) { Object.assign(params, Overrides.removeOverrides(overrides, branch.protection, {}), { headers: previewHeaders }) @@ -89,7 +89,7 @@ module.exports = class Branches extends ErrorStash { return Promise.resolve(resArray) } this.log.debug(`Adding branch protection ${JSON.stringify(params)}`) - return this.github.repos.updateBranchProtection(params).then(res => this.log(`Branch protection applied successfully ${JSON.stringify(res.url)}`)).catch(e => { this.logError(`Error applying branch protection ${JSON.stringify(e)}`); return [] }) + return this.github.repos.updateBranchProtection(params).then(res => this.log.debug(`Branch protection applied successfully ${JSON.stringify(res.url)}`)).catch(e => { this.logError(`Error applying branch protection ${JSON.stringify(e)}`); return [] }) } else { this.logError(e) if (this.nop) { diff --git a/lib/plugins/rulesets.js b/lib/plugins/rulesets.js index c4208de8a..b77ead1bd 100644 --- a/lib/plugins/rulesets.js +++ b/lib/plugins/rulesets.js @@ -34,7 +34,7 @@ module.exports = class Rulesets extends Diffable { org: this.repo.owner, headers: version }) - this.log(listOptions) + this.log.debug(listOptions) return this.github.paginate(listOptions) .then(res => { const rulesets = res.map(ruleset => { @@ -63,7 +63,7 @@ module.exports = class Rulesets extends Diffable { repo: this.repo.repo, headers: version }) - this.log(listOptions) + this.log.debug(listOptions) return this.github.paginate(listOptions) .then(res => { const rulesets = res @@ -111,7 +111,7 @@ module.exports = class Rulesets extends Diffable { Overrides.removeOverrides(overrides, parms, existing) this.log.debug(`Updating Ruleset with the following values ${JSON.stringify(parms, null, 2)}`) return this.github.request('PUT /orgs/{org}/rulesets/{id}', parms).then(res => { - this.log(`Ruleset updated successfully ${JSON.stringify(res.url)}`) + this.log.debug(`Ruleset updated successfully ${JSON.stringify(res.url)}`) return res }).catch(e => { return this.handleError(e) @@ -125,7 +125,7 @@ module.exports = class Rulesets extends Diffable { Overrides.removeOverrides(overrides, parms, existing) this.log.debug(`Updating Ruleset with the following values ${JSON.stringify(parms, null, 2)}`) return this.github.request('PUT /repos/{owner}/{repo}/rulesets/{id}', parms).then(res => { - this.log(`Ruleset updated successfully ${JSON.stringify(res.url)}`) + this.log.debug(`Ruleset updated successfully ${JSON.stringify(res.url)}`) return res }).catch(e => { return this.handleError(e) @@ -143,7 +143,7 @@ module.exports = class Rulesets extends Diffable { Overrides.removeOverrides(overrides, attrs, {}) this.log.debug(`Creating Rulesets with the following values ${JSON.stringify(attrs, null, 2)}`) return this.github.request('POST /orgs/{org}/rulesets', this.wrapAttrs(attrs)).then(res => { - this.log(`Ruleset created successfully ${JSON.stringify(res.url)}`) + this.log.debug(`Ruleset created successfully ${JSON.stringify(res.url)}`) return res }).catch(e => { return this.handleError(e) @@ -157,7 +157,7 @@ module.exports = class Rulesets extends Diffable { Overrides.removeOverrides(overrides, attrs, {}) this.log.debug(`Creating Rulesets with the following values ${JSON.stringify(attrs, null, 2)}`) return this.github.request('POST /repos/{owner}/{repo}/rulesets', this.wrapAttrs(attrs)).then(res => { - this.log(`Ruleset created successfully ${JSON.stringify(res.url)}`) + this.log.debug(`Ruleset created successfully ${JSON.stringify(res.url)}`) return res }).catch(e => { return this.handleError(e) @@ -175,7 +175,7 @@ module.exports = class Rulesets extends Diffable { } this.log.debug(`Deleting Ruleset with the following values ${JSON.stringify(parms, null, 2)}`) return this.github.request('DELETE /orgs/{org}/rulesets/{id}', parms).then(res => { - this.log(`Ruleset deleted successfully ${JSON.stringify(res.url)}`) + this.log.debug(`Ruleset deleted successfully ${JSON.stringify(res.url)}`) return res }).catch(e => { return this.handleError(e) @@ -188,7 +188,7 @@ module.exports = class Rulesets extends Diffable { } this.log.debug(`Deleting Ruleset with the following values ${JSON.stringify(parms, null, 2)}`) return this.github.request('DELETE /repos/{owner}/{repo}/rulesets/{id}', parms).then(res => { - this.log(`Ruleset deleted successfully ${JSON.stringify(res.url)}`) + this.log.debug(`Ruleset deleted successfully ${JSON.stringify(res.url)}`) return res }).catch(e => { if (e.status === 404) { diff --git a/lib/plugins/validator.js b/lib/plugins/validator.js index 45f04d60c..8ee72af9a 100644 --- a/lib/plugins/validator.js +++ b/lib/plugins/validator.js @@ -20,7 +20,7 @@ module.exports = class Validator { } }).then(res => { if (this.repo.repo.search(this.regex) >= 0) { - this.log(`Repo ${this.repo.repo} Passed Validation for pattern ${this.pattern}`) + this.log.debug(`Repo ${this.repo.repo} Passed Validation for pattern ${this.pattern}`) if (this.nop) { return Promise.resolve([ new NopCommand(this.constructor.name, this.repo, null, `Passed Validation for pattern ${this.pattern}`) @@ -38,7 +38,7 @@ module.exports = class Validator { }) } } else { - this.log(`Repo ${this.repo.repo} Failed Validation for pattern ${this.pattern}`) + this.log.debug(`Repo ${this.repo.repo} Failed Validation for pattern ${this.pattern}`) if (this.nop) { return Promise.resolve([ new NopCommand(this.constructor.name, this.repo, null, `Failed Validation for pattern ${this.pattern}`, 'ERROR') @@ -59,7 +59,7 @@ module.exports = class Validator { }) .catch(() => {}) } catch (error) { - this.log(`Error in Validation checking ${error}`) + this.log.debug(`Error in Validation checking ${error}`) } } } diff --git a/lib/settings.js b/lib/settings.js index 96a8cf962..4da9f697d 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -908,7 +908,9 @@ function prettify (obj) { return JSON.stringify(obj, null, 2).replaceAll('\n', '
').replaceAll(' ', ' ') } -Settings.FILE_NAME = path.posix.join(CONFIG_PATH, env.SETTINGS_FILE_PATH) +Settings.FILE_PATH = path.posix.join(CONFIG_PATH, env.SETTINGS_FILE_PATH) +Settings.SUB_ORG_PATTERN = new Glob(`${CONFIG_PATH}/suborgs/*.yml`) +Settings.REPO_PATTERN = new Glob(`${CONFIG_PATH}/repos/*.yml`) Settings.PLUGINS = { repository: require('./plugins/repository'), diff --git a/test/integration/common.js b/test/integration/common.js index 13d476179..4d47b210a 100644 --- a/test/integration/common.js +++ b/test/integration/common.js @@ -38,7 +38,7 @@ function buildPushEvent () { payload: { ref: 'refs/heads/master', repository, - commits: [{ modified: [settings.FILE_NAME], added: [] }] + commits: [{ modified: [settings.FILE_PATH], added: [] }] } } } diff --git a/test/integration/plugins/collaborators.test.js b/test/integration/plugins/collaborators.test.js index 4522c9069..81dddff5d 100644 --- a/test/integration/plugins/collaborators.test.js +++ b/test/integration/plugins/collaborators.test.js @@ -21,7 +21,7 @@ describe('collaborators plugin', function () { const configFile = Buffer.from(fs.readFileSync(pathToConfig, 'utf8')) const encodedConfig = configFile.toString('base64') githubScope - .get(`/repos/${repository.owner.name}/${repository.name}/contents/${settings.FILE_NAME}`) + .get(`/repos/${repository.owner.name}/${repository.name}/contents/${settings.FILE_PATH}`) .reply(OK, { content: encodedConfig, name: 'settings.yml', type: 'file' }) githubScope .get(`/repos/${repository.owner.name}/${repository.name}/collaborators?affiliation=direct`) diff --git a/test/integration/plugins/milestones.test.js b/test/integration/plugins/milestones.test.js index b95412391..0c86b0244 100644 --- a/test/integration/plugins/milestones.test.js +++ b/test/integration/plugins/milestones.test.js @@ -21,7 +21,7 @@ describe('milestones plugin', function () { const configFile = Buffer.from(fs.readFileSync(pathToConfig, 'utf8')) const encodedConfig = configFile.toString('base64') githubScope - .get(`/repos/${repository.owner.name}/${repository.name}/contents/${settings.FILE_NAME}`) + .get(`/repos/${repository.owner.name}/${repository.name}/contents/${settings.FILE_PATH}`) .reply(OK, { content: encodedConfig, name: 'settings.yml', type: 'file' }) githubScope .patch(`/repos/${repository.owner.name}/${repository.name}`) diff --git a/test/integration/plugins/repository.test.js b/test/integration/plugins/repository.test.js index b7390a0b6..1d0115283 100644 --- a/test/integration/plugins/repository.test.js +++ b/test/integration/plugins/repository.test.js @@ -22,7 +22,7 @@ describe('repository plugin', function () { const config = yaml.safeLoad(configFile, 'utf8') const encodedConfig = configFile.toString('base64') githubScope - .get(`/repos/${repository.owner.name}/${repository.name}/contents/${settings.FILE_NAME}`) + .get(`/repos/${repository.owner.name}/${repository.name}/contents/${settings.FILE_PATH}`) .reply(200, { content: encodedConfig, name: 'settings.yml', type: 'file' }) githubScope .patch(`/repos/${repository.owner.name}/${repository.name}`, body => { diff --git a/test/integration/plugins/teams.test.js b/test/integration/plugins/teams.test.js index c7b9ca7bd..4fde0637f 100644 --- a/test/integration/plugins/teams.test.js +++ b/test/integration/plugins/teams.test.js @@ -25,7 +25,7 @@ describe('teams plugin', function () { const greenkeeperKeeperTeamId = any.integer() const formationTeamId = any.integer() githubScope - .get(`/repos/${repository.owner.name}/${repository.name}/contents/${settings.FILE_NAME}`) + .get(`/repos/${repository.owner.name}/${repository.name}/contents/${settings.FILE_PATH}`) .reply(OK, { content: encodedConfig, name: 'settings.yml', type: 'file' }) githubScope .get(`/repos/${repository.owner.name}/${repository.name}/teams`) diff --git a/test/integration/triggers/push.test.js b/test/integration/triggers/push.test.js index 746fde79e..0eab2a771 100644 --- a/test/integration/triggers/push.test.js +++ b/test/integration/triggers/push.test.js @@ -19,7 +19,7 @@ describe('push trigger', function () { payload: { ref: 'refs/heads/wip', repository, - commits: [{ modified: [settings.FILE_NAME], added: [] }] + commits: [{ modified: [settings.FILE_PATH], added: [] }] } }) }) diff --git a/test/integration/triggers/repository-created.test.js b/test/integration/triggers/repository-created.test.js index 4245c00d0..fa53dd9c5 100644 --- a/test/integration/triggers/repository-created.test.js +++ b/test/integration/triggers/repository-created.test.js @@ -16,13 +16,13 @@ describe('repository.created trigger', function () { it('does not apply configuration when the repository does not have a settings.yml', async () => { githubScope - .get(`/repos/${repository.owner.name}/${repository.name}/contents/${settings.FILE_NAME}`) + .get(`/repos/${repository.owner.name}/${repository.name}/contents/${settings.FILE_PATH}`) .reply(NOT_FOUND, { message: 'Not Found', documentation_url: 'https://developer.github.com/v3/repos/contents/#get-contents' }) githubScope - .get(`/repos/${repository.owner.name}/.github/contents/${settings.FILE_NAME}`) + .get(`/repos/${repository.owner.name}/.github/contents/${settings.FILE_PATH}`) .reply(NOT_FOUND, { message: 'Not Found', documentation_url: 'https://developer.github.com/v3/repos/contents/#get-contents' diff --git a/test/integration/triggers/repository-edited.test.js b/test/integration/triggers/repository-edited.test.js index d5d6c6f39..1a0f36f63 100644 --- a/test/integration/triggers/repository-edited.test.js +++ b/test/integration/triggers/repository-edited.test.js @@ -26,13 +26,13 @@ describe('repository.edited trigger', function () { it('does not apply configuration when the repository does not have a settings.yml', async () => { githubScope - .get(`/repos/${repository.owner.name}/${repository.name}/contents/${settings.FILE_NAME}`) + .get(`/repos/${repository.owner.name}/${repository.name}/contents/${settings.FILE_PATH}`) .reply(NOT_FOUND, { message: 'Not Found', documentation_url: 'https://developer.github.com/v3/repos/contents/#get-contents' }) githubScope - .get(`/repos/${repository.owner.name}/.github/contents/${settings.FILE_NAME}`) + .get(`/repos/${repository.owner.name}/.github/contents/${settings.FILE_PATH}`) .reply(NOT_FOUND, { message: 'Not Found', documentation_url: 'https://developer.github.com/v3/repos/contents/#get-contents' diff --git a/test/unit/lib/env.test.js b/test/unit/lib/env.test.js index 56f78a883..e4a53eb86 100644 --- a/test/unit/lib/env.test.js +++ b/test/unit/lib/env.test.js @@ -18,8 +18,8 @@ describe('env', () => { expect(SETTINGS_FILE_PATH).toEqual('settings.yml') }) - it('loads default DEPLOYMENT_CONFIG_FILE if not passed', () => { - const SETTINGS_FILE_PATH = envTest.DEPLOYMENT_CONFIG_FILE + it('loads default DEPLOYMENT_CONFIG_FILE_PATH if not passed', () => { + const SETTINGS_FILE_PATH = envTest.DEPLOYMENT_CONFIG_FILE_PATH expect(SETTINGS_FILE_PATH).toEqual('deployment-settings.yml') }) @@ -47,8 +47,8 @@ describe('env', () => { expect(CONFIG_PATH).toEqual('.config') const SETTINGS_FILE_PATH = envTest.SETTINGS_FILE_PATH expect(SETTINGS_FILE_PATH).toEqual('safe-settings.yml') - const DEPLOYMENT_CONFIG_FILE = envTest.DEPLOYMENT_CONFIG_FILE - expect(DEPLOYMENT_CONFIG_FILE).toEqual('safe-settings-deployment.yml') + const DEPLOYMENT_CONFIG_FILE_PATH = envTest.DEPLOYMENT_CONFIG_FILE_PATH + expect(DEPLOYMENT_CONFIG_FILE_PATH).toEqual('safe-settings-deployment.yml') const CREATE_PR_COMMENT = envTest.CREATE_PR_COMMENT expect(CREATE_PR_COMMENT).toEqual('false') })