@@ -4,6 +4,7 @@ const fs = require('fs')
44const cron = require ( 'node-cron' )
55const Glob = require ( './lib/glob' )
66const ConfigManager = require ( './lib/configManager' )
7+ const DeploymentConfig = require ( './lib/deploymentConfig' )
78const NopCommand = require ( './lib/nopcommand' )
89const env = require ( './lib/env' )
910
@@ -13,11 +14,11 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
1314 let appSlug = 'safe-settings'
1415 async function syncAllSettings ( nop , context , repo = context . repo ( ) , ref ) {
1516 try {
16- deploymentConfig = await loadYamlFileSystem ( )
17+ deploymentConfig = await loadYamlFileSystem ( context )
1718 robot . log . debug ( `deploymentConfig is ${ JSON . stringify ( deploymentConfig ) } ` )
1819 const configManager = new ConfigManager ( context , ref )
1920 const runtimeConfig = await configManager . loadGlobalSettingsYaml ( )
20- const config = Object . assign ( { } , deploymentConfig , runtimeConfig )
21+ const config = { deploymentConfig, runtimeConfig }
2122 robot . log . debug ( `config for ref ${ ref } is ${ JSON . stringify ( config ) } ` )
2223 if ( ref ) {
2324 return Settings . syncAll ( nop , context , repo , config , ref )
@@ -42,11 +43,11 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
4243
4344 async function syncSubOrgSettings ( nop , context , suborg , repo = context . repo ( ) , ref ) {
4445 try {
45- deploymentConfig = await loadYamlFileSystem ( )
46+ deploymentConfig = await loadYamlFileSystem ( context )
4647 robot . log . debug ( `deploymentConfig is ${ JSON . stringify ( deploymentConfig ) } ` )
4748 const configManager = new ConfigManager ( context , ref )
4849 const runtimeConfig = await configManager . loadGlobalSettingsYaml ( )
49- const config = Object . assign ( { } , deploymentConfig , runtimeConfig )
50+ const config = { deploymentConfig, runtimeConfig }
5051 robot . log . debug ( `config for ref ${ ref } is ${ JSON . stringify ( config ) } ` )
5152 return Settings . syncSubOrgs ( nop , context , suborg , repo , config , ref )
5253 } catch ( e ) {
@@ -67,11 +68,11 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
6768
6869 async function syncSettings ( nop , context , repo = context . repo ( ) , ref ) {
6970 try {
70- deploymentConfig = await loadYamlFileSystem ( )
71+ deploymentConfig = await loadYamlFileSystem ( context )
7172 robot . log . debug ( `deploymentConfig is ${ JSON . stringify ( deploymentConfig ) } ` )
7273 const configManager = new ConfigManager ( context , ref )
7374 const runtimeConfig = await configManager . loadGlobalSettingsYaml ( )
74- const config = Object . assign ( { } , deploymentConfig , runtimeConfig )
75+ const config = { deploymentConfig, runtimeConfig }
7576 robot . log . debug ( `config for ref ${ ref } is ${ JSON . stringify ( config ) } ` )
7677 return Settings . sync ( nop , context , repo , config , ref )
7778 } catch ( e ) {
@@ -92,14 +93,14 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
9293
9394 async function renameSync ( nop , context , repo = context . repo ( ) , rename , ref ) {
9495 try {
95- deploymentConfig = await loadYamlFileSystem ( )
96+ deploymentConfig = await loadYamlFileSystem ( context )
9697 robot . log . debug ( `deploymentConfig is ${ JSON . stringify ( deploymentConfig ) } ` )
9798 const configManager = new ConfigManager ( context , ref )
9899 const runtimeConfig = await configManager . loadGlobalSettingsYaml ( )
99- const config = Object . assign ( { } , deploymentConfig , runtimeConfig )
100- const renameConfig = Object . assign ( { } , config , rename )
100+ const renameConfig = Object . assign ( { } , runtimeConfig , rename )
101+ const config = { deploymentConfig , runtimeConfig : renameConfig }
101102 robot . log . debug ( `config for ref ${ ref } is ${ JSON . stringify ( config ) } ` )
102- return Settings . sync ( nop , context , repo , renameConfig , ref )
103+ return Settings . sync ( nop , context , repo , config , ref )
103104 } catch ( e ) {
104105 if ( nop ) {
105106 let filename = env . SETTINGS_FILE_PATH
@@ -121,16 +122,8 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
121122 *
122123 * @return The parsed YAML file
123124 */
124- async function loadYamlFileSystem ( ) {
125- if ( deploymentConfig === undefined ) {
126- const deploymentConfigPath = env . DEPLOYMENT_CONFIG_FILE
127- if ( fs . existsSync ( deploymentConfigPath ) ) {
128- deploymentConfig = yaml . load ( fs . readFileSync ( deploymentConfigPath ) )
129- } else {
130- deploymentConfig = { restrictedRepos : [ 'admin' , '.github' , 'safe-settings' ] }
131- }
132- }
133- return deploymentConfig
125+ async function loadYamlFileSystem ( context ) {
126+ return new DeploymentConfig ( context )
134127 }
135128
136129 function getAllChangedSubOrgConfigs ( payload ) {
0 commit comments