@@ -19,16 +19,29 @@ let deploymentConfig
1919
2020module . exports = ( robot , { getRouter } , Settings = require ( './lib/settings' ) ) => {
2121 let appSlug = 'safe-settings'
22- async function syncAllSettings ( nop , context , repo = context . repo ( ) , ref ) {
22+ async function syncAllSettings ( nop , context , repo = context . repo ( ) , ref , baseRef , changedFiles = { } ) {
2323 try {
2424 deploymentConfig = await loadYamlFileSystem ( )
2525 robot . log . debug ( `deploymentConfig is ${ JSON . stringify ( deploymentConfig ) } ` )
2626 const configManager = new ConfigManager ( context , ref )
2727 const runtimeConfig = await configManager . loadGlobalSettingsYaml ( )
2828 const config = Object . assign ( { } , deploymentConfig , runtimeConfig )
2929 robot . log . debug ( `config for ref ${ ref } is ${ JSON . stringify ( config ) } ` )
30+
31+ // Load base branch config for NOP filtering (only show PR-introduced changes)
32+ let baseConfig = null
33+ if ( nop && baseRef ) {
34+ try {
35+ const baseConfigManager = new ConfigManager ( context , baseRef )
36+ const baseRuntimeConfig = await baseConfigManager . loadGlobalSettingsYaml ( )
37+ baseConfig = Object . assign ( { } , deploymentConfig , baseRuntimeConfig )
38+ } catch ( e ) {
39+ robot . log . debug ( `Could not load base config for NOP filtering: ${ e . message } ` )
40+ }
41+ }
42+
3043 if ( ref ) {
31- return Settings . syncAll ( nop , context , repo , config , ref )
44+ return Settings . syncAll ( nop , context , repo , config , ref , baseConfig , changedFiles )
3245 } else {
3346 return Settings . syncAll ( nop , context , repo , config )
3447 }
@@ -73,15 +86,28 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
7386 }
7487 }
7588
76- async function syncSelectedSettings ( nop , context , repos , subOrgs , ref ) {
89+ async function syncSelectedSettings ( nop , context , repos , subOrgs , ref , baseRef ) {
7790 try {
7891 deploymentConfig = await loadYamlFileSystem ( )
7992 robot . log . debug ( `deploymentConfig is ${ JSON . stringify ( deploymentConfig ) } ` )
8093 const configManager = new ConfigManager ( context , ref )
8194 const runtimeConfig = await configManager . loadGlobalSettingsYaml ( )
8295 const config = Object . assign ( { } , deploymentConfig , runtimeConfig )
8396 robot . log . debug ( `config for ref ${ ref } is ${ JSON . stringify ( config ) } ` )
84- return Settings . syncSelectedRepos ( nop , context , repos , subOrgs , config , ref )
97+
98+ // Load base branch config for NOP filtering
99+ let baseConfig = null
100+ if ( nop && baseRef ) {
101+ try {
102+ const baseConfigManager = new ConfigManager ( context , baseRef )
103+ const baseRuntimeConfig = await baseConfigManager . loadGlobalSettingsYaml ( )
104+ baseConfig = Object . assign ( { } , deploymentConfig , baseRuntimeConfig )
105+ } catch ( e ) {
106+ robot . log . debug ( `Could not load base config for NOP filtering: ${ e . message } ` )
107+ }
108+ }
109+
110+ return Settings . syncSelectedRepos ( nop , context , repos , subOrgs , config , ref , baseConfig )
85111 } catch ( e ) {
86112 if ( nop ) {
87113 let filename = env . SETTINGS_FILE_PATH
@@ -585,17 +611,21 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
585611 const files = changes . data . map ( f => { return f . filename } )
586612
587613 const settingsModified = files . includes ( Settings . FILE_PATH )
614+ const repoChanges = getChangedRepoConfigName ( files , context . repo ( ) . owner )
615+ const subOrgChanges = getChangedSubOrgConfigName ( files )
588616
589617 if ( settingsModified ) {
590618 robot . log . debug ( `Changes in '${ Settings . FILE_PATH } ' detected, doing a full synch...` )
591- return syncAllSettings ( true , context , context . repo ( ) , pull_request . head . ref )
619+ const baseRef = pull_request . base . ref || repository . default_branch
620+ return syncAllSettings ( true , context , context . repo ( ) , pull_request . head . ref , baseRef , {
621+ repos : repoChanges ,
622+ subOrgs : subOrgChanges
623+ } )
592624 }
593625
594- const repoChanges = getChangedRepoConfigName ( files , context . repo ( ) . owner )
595- const subOrgChanges = getChangedSubOrgConfigName ( files )
596-
597626 if ( repoChanges . length > 0 || subOrgChanges . length > 0 ) {
598- return syncSelectedSettings ( true , context , repoChanges , subOrgChanges , pull_request . head . ref )
627+ const baseRef = pull_request . base . ref || repository . default_branch
628+ return syncSelectedSettings ( true , context , repoChanges , subOrgChanges , pull_request . head . ref , baseRef )
599629 }
600630
601631 // if no safe-settings changes detected, send a success to the check run
0 commit comments