Skip to content
Merged
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
30 changes: 15 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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 {
Expand All @@ -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 => {
Expand All @@ -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 => {
Expand Down Expand Up @@ -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)
}

Expand All @@ -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 => {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/deploymentConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion lib/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
8 changes: 4 additions & 4 deletions lib/plugins/branches.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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 })
Expand All @@ -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) {
Expand Down
16 changes: 8 additions & 8 deletions lib/plugins/rulesets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions lib/plugins/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
Expand All @@ -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')
Expand All @@ -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}`)
}
}
}
4 changes: 3 additions & 1 deletion lib/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,9 @@ function prettify (obj) {
return JSON.stringify(obj, null, 2).replaceAll('\n', '<br>').replaceAll(' ', '&nbsp;')
}

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'),
Expand Down
2 changes: 1 addition & 1 deletion test/integration/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function buildPushEvent () {
payload: {
ref: 'refs/heads/master',
repository,
commits: [{ modified: [settings.FILE_NAME], added: [] }]
commits: [{ modified: [settings.FILE_PATH], added: [] }]
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/integration/plugins/collaborators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
2 changes: 1 addition & 1 deletion test/integration/plugins/milestones.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
Expand Down
2 changes: 1 addition & 1 deletion test/integration/plugins/repository.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/plugins/teams.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
2 changes: 1 addition & 1 deletion test/integration/triggers/push.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [] }]
}
})
})
Expand Down
4 changes: 2 additions & 2 deletions test/integration/triggers/repository-created.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions test/integration/triggers/repository-edited.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Loading