-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
de8bab4
handle multiple changes as a batch
decyjphr fa00d78
Update index.js
decyjphr b87397c
Update index.js
decyjphr 6b358e5
depup files in a push
decyjphr c971041
Update index.js
decyjphr ac8e195
moved the dedup logic
decyjphr 8bc76fc
Update index.js
decyjphr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
@@ -263,18 +263,17 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) => | |
return syncAllSettings(false, context) | ||
} | ||
|
||
const repoChanges = getAllChangedRepoConfigs(payload, context.repo().owner) | ||
if (repoChanges.length > 0) { | ||
return Promise.all(repoChanges.map(repo => { | ||
return syncSettings(false, context, repo) | ||
})) | ||
} | ||
let repoChanges = getAllChangedRepoConfigs(payload, context.repo().owner) | ||
|
||
const changes = getAllChangedSubOrgConfigs(payload) | ||
if (changes.length) { | ||
return Promise.all(changes.map(suborg => { | ||
return syncSubOrgSettings(false, context, suborg) | ||
})) | ||
let subOrgChanges = getAllChangedSubOrgConfigs(payload) | ||
repoChanges = repoChanges.filter((r, i, arr) => arr.findIndex(item => item.repo === r.repo) === i) | ||
|
||
subOrgChanges = subOrgChanges.filter((s, i, arr) => arr.findIndex(item => item.repo === s.repo) === i) | ||
robot.log.debug(`deduped repos ${JSON.stringify(repoChanges)}`) | ||
robot.log.debug(`deduped subOrgs ${JSON.stringify(subOrgChanges)}`) | ||
|
||
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 +571,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 +584,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) | ||
decyjphr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.