@@ -40,15 +40,15 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
4040 }
4141 }
4242
43- async function syncSubOrgSettings ( nop , context , suborg , repo = context . repo ( ) , ref ) {
43+ async function syncSettings ( nop , context , repo = context . repo ( ) , ref ) {
4444 try {
4545 deploymentConfig = await loadYamlFileSystem ( )
4646 robot . log . debug ( `deploymentConfig is ${ JSON . stringify ( deploymentConfig ) } ` )
4747 const configManager = new ConfigManager ( context , ref )
4848 const runtimeConfig = await configManager . loadGlobalSettingsYaml ( )
4949 const config = Object . assign ( { } , deploymentConfig , runtimeConfig )
5050 robot . log . debug ( `config for ref ${ ref } is ${ JSON . stringify ( config ) } ` )
51- return Settings . syncSubOrgs ( nop , context , suborg , repo , config , ref )
51+ return Settings . sync ( nop , context , repo , config , ref )
5252 } catch ( e ) {
5353 if ( nop ) {
5454 let filename = env . SETTINGS_FILE_PATH
@@ -65,25 +65,29 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
6565 }
6666 }
6767
68- async function syncSettings ( nop , context , repo = context . repo ( ) , ref ) {
68+ async function syncSelectedSettings ( nop , context , repos , subOrgs , ref ) {
6969 try {
7070 deploymentConfig = await loadYamlFileSystem ( )
7171 robot . log . debug ( `deploymentConfig is ${ JSON . stringify ( deploymentConfig ) } ` )
7272 const configManager = new ConfigManager ( context , ref )
7373 const runtimeConfig = await configManager . loadGlobalSettingsYaml ( )
7474 const config = Object . assign ( { } , deploymentConfig , runtimeConfig )
7575 robot . log . debug ( `config for ref ${ ref } is ${ JSON . stringify ( config ) } ` )
76- return Settings . sync ( nop , context , repo , config , ref )
76+ if ( ref ) {
77+ return Settings . syncSelectedRepos ( nop , context , repos , subOrgs , config , ref )
78+ } else {
79+ return Settings . syncSelectedRepos ( nop , context , repos , subOrgs , config )
80+ }
7781 } catch ( e ) {
7882 if ( nop ) {
7983 let filename = env . SETTINGS_FILE_PATH
8084 if ( ! deploymentConfig ) {
8185 filename = env . DEPLOYMENT_CONFIG_FILE_PATH
8286 deploymentConfig = { }
8387 }
84- const nopcommand = new NopCommand ( filename , repo , null , e , 'ERROR' )
88+ const nopcommand = new NopCommand ( filename , context . repo ( ) , null , e , 'ERROR' )
8589 robot . log . error ( `NOPCOMMAND ${ JSON . stringify ( nopcommand ) } ` )
86- Settings . handleError ( nop , context , repo , deploymentConfig , ref , nopcommand )
90+ Settings . handleError ( nop , context , context . repo ( ) , deploymentConfig , ref , nopcommand )
8791 } else {
8892 throw e
8993 }
@@ -264,17 +268,11 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
264268 }
265269
266270 const repoChanges = getAllChangedRepoConfigs ( payload , context . repo ( ) . owner )
267- if ( repoChanges . length > 0 ) {
268- return Promise . all ( repoChanges . map ( repo => {
269- return syncSettings ( false , context , repo )
270- } ) )
271- }
272271
273- const changes = getAllChangedSubOrgConfigs ( payload )
274- if ( changes . length ) {
275- return Promise . all ( changes . map ( suborg => {
276- return syncSubOrgSettings ( false , context , suborg )
277- } ) )
272+ const subOrgChanges = getAllChangedSubOrgConfigs ( payload )
273+
274+ if ( repoChanges . length > 0 || subOrgChanges . length > 0 ) {
275+ return syncSelectedSettings ( false , context , repoChanges , subOrgChanges )
278276 }
279277
280278 robot . log . debug ( `No changes in '${ Settings . FILE_PATH } ' detected, returning...` )
@@ -572,15 +570,10 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
572570 robot . log . debug ( `Updating check run ${ JSON . stringify ( params ) } ` )
573571 await context . octokit . checks . update ( params )
574572
575- // guarding against null value from upstream libary that is
576- // causing a 404 and the check to stall
577- // from issue: https://github.com/github/safe-settings/issues/185#issuecomment-1075240374
578- if ( check_suite . before === '0000000000000000000000000000000000000000' ) {
579- check_suite . before = check_suite . pull_requests [ 0 ] . base . sha
580- }
581- params = Object . assign ( context . repo ( ) , { basehead : `${ check_suite . before } ...${ check_suite . after } ` } )
582- const changes = await context . octokit . repos . compareCommitsWithBasehead ( params )
583- const files = changes . data . files . map ( f => { return f . filename } )
573+ params = Object . assign ( context . repo ( ) , { pull_number : pull_request . number } )
574+
575+ const changes = await context . octokit . request ( 'GET /repos/{owner}/{repo}/pulls/{pull_number}/files' , params )
576+ const files = changes . data . map ( f => { return f . filename } )
584577
585578 const settingsModified = files . includes ( Settings . FILE_PATH )
586579
@@ -590,17 +583,10 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
590583 }
591584
592585 const repoChanges = getChangedRepoConfigName ( files , context . repo ( ) . owner )
593- if ( repoChanges . length > 0 ) {
594- return Promise . all ( repoChanges . map ( repo => {
595- return syncSettings ( true , context , repo , pull_request . head . ref )
596- } ) )
597- }
598-
599586 const subOrgChanges = getChangedSubOrgConfigName ( files )
600- if ( subOrgChanges . length ) {
601- return Promise . all ( subOrgChanges . map ( suborg => {
602- return syncSubOrgSettings ( true , context , suborg , context . repo ( ) , pull_request . head . ref )
603- } ) )
587+
588+ if ( repoChanges . length > 0 || subOrgChanges . length > 0 ) {
589+ return syncSelectedSettings ( true , context , repoChanges , subOrgChanges , pull_request . head . ref )
604590 }
605591
606592 // if no safe-settings changes detected, send a success to the check run
0 commit comments