-
Notifications
You must be signed in to change notification settings - Fork 192
Handle multiple config changes in a PR or Push event and process them as a batch #888
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
base: main-enterprise
Are you sure you want to change the base?
Changes from 3 commits
de8bab4
fa00d78
b87397c
6b358e5
c971041
ac8e195
8bc76fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,15 +40,15 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) => | |
} | ||
} | ||
|
||
async function syncSubOrgSettings (nop, context, suborg, repo = context.repo(), ref) { | ||
async function syncSettings (nop, context, repo = context.repo(), ref) { | ||
try { | ||
deploymentConfig = await loadYamlFileSystem() | ||
robot.log.debug(`deploymentConfig is ${JSON.stringify(deploymentConfig)}`) | ||
const configManager = new ConfigManager(context, ref) | ||
const runtimeConfig = await configManager.loadGlobalSettingsYaml() | ||
const config = Object.assign({}, deploymentConfig, runtimeConfig) | ||
robot.log.debug(`config for ref ${ref} is ${JSON.stringify(config)}`) | ||
return Settings.syncSubOrgs(nop, context, suborg, repo, config, ref) | ||
return Settings.sync(nop, context, repo, config, ref) | ||
} catch (e) { | ||
if (nop) { | ||
let filename = env.SETTINGS_FILE_PATH | ||
|
@@ -65,25 +65,25 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) => | |
} | ||
} | ||
|
||
async function syncSettings (nop, context, repo = context.repo(), ref) { | ||
async function syncSelectedSettings (nop, context, repos, subOrgs, ref) { | ||
try { | ||
deploymentConfig = await loadYamlFileSystem() | ||
robot.log.debug(`deploymentConfig is ${JSON.stringify(deploymentConfig)}`) | ||
const configManager = new ConfigManager(context, ref) | ||
const runtimeConfig = await configManager.loadGlobalSettingsYaml() | ||
const config = Object.assign({}, deploymentConfig, runtimeConfig) | ||
robot.log.debug(`config for ref ${ref} is ${JSON.stringify(config)}`) | ||
return Settings.sync(nop, context, repo, config, ref) | ||
return Settings.syncSelectedRepos(nop, context, repos, subOrgs, config, ref) | ||
} catch (e) { | ||
if (nop) { | ||
let filename = env.SETTINGS_FILE_PATH | ||
if (!deploymentConfig) { | ||
filename = env.DEPLOYMENT_CONFIG_FILE_PATH | ||
deploymentConfig = {} | ||
} | ||
const nopcommand = new NopCommand(filename, repo, null, e, 'ERROR') | ||
const nopcommand = new NopCommand(filename, context.repo(), null, e, 'ERROR') | ||
robot.log.error(`NOPCOMMAND ${JSON.stringify(nopcommand)}`) | ||
Settings.handleError(nop, context, repo, deploymentConfig, ref, nopcommand) | ||
Settings.handleError(nop, context, context.repo(), deploymentConfig, ref, nopcommand) | ||
} else { | ||
throw e | ||
} | ||
|
@@ -264,17 +264,11 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) => | |
} | ||
|
||
const repoChanges = getAllChangedRepoConfigs(payload, context.repo().owner) | ||
if (repoChanges.length > 0) { | ||
return Promise.all(repoChanges.map(repo => { | ||
return syncSettings(false, context, repo) | ||
})) | ||
} | ||
|
||
const changes = getAllChangedSubOrgConfigs(payload) | ||
if (changes.length) { | ||
return Promise.all(changes.map(suborg => { | ||
return syncSubOrgSettings(false, context, suborg) | ||
})) | ||
const subOrgChanges = getAllChangedSubOrgConfigs(payload) | ||
|
||
if (repoChanges.length > 0 || subOrgChanges.length > 0) { | ||
return syncSelectedSettings(false, context, repoChanges, subOrgChanges) | ||
} | ||
|
||
robot.log.debug(`No changes in '${Settings.FILE_PATH}' detected, returning...`) | ||
|
@@ -572,15 +566,10 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) => | |
robot.log.debug(`Updating check run ${JSON.stringify(params)}`) | ||
await context.octokit.checks.update(params) | ||
|
||
// guarding against null value from upstream libary that is | ||
// causing a 404 and the check to stall | ||
// from issue: https://github.com/github/safe-settings/issues/185#issuecomment-1075240374 | ||
if (check_suite.before === '0000000000000000000000000000000000000000') { | ||
check_suite.before = check_suite.pull_requests[0].base.sha | ||
} | ||
params = Object.assign(context.repo(), { basehead: `${check_suite.before}...${check_suite.after}` }) | ||
const changes = await context.octokit.repos.compareCommitsWithBasehead(params) | ||
const files = changes.data.files.map(f => { return f.filename }) | ||
params = Object.assign(context.repo(), { pull_number: pull_request.number }) | ||
|
||
const changes = await context.octokit.pulls.listFiles(params) | ||
Comment on lines
+574
to
+576
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] The variable Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
const files = changes.data.map(f => { return f.filename }) | ||
|
||
const settingsModified = files.includes(Settings.FILE_PATH) | ||
|
||
|
@@ -590,17 +579,10 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) => | |
} | ||
|
||
const repoChanges = getChangedRepoConfigName(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(files) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent property naming: Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
if (subOrgChanges.length) { | ||
return Promise.all(subOrgChanges.map(suborg => { | ||
return syncSubOrgSettings(true, context, suborg, context.repo(), pull_request.head.ref) | ||
})) | ||
|
||
if (repoChanges.length > 0 || subOrgChanges.length > 0) { | ||
return syncSelectedSettings(true, context, repoChanges, subOrgChanges, pull_request.head.ref) | ||
} | ||
|
||
// if no safe-settings changes detected, send a success to the check run | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems like it would cause a regression of #185
why remove it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we have changed the API call to a different one which does not require the before and after commits.