@@ -10,10 +10,10 @@ const env = require('./env')
1010const CONFIG_PATH = env . CONFIG_PATH
1111const eta = new Eta ( { views : path . join ( __dirname ) } )
1212const SCOPE = { ORG : 'org' , REPO : 'repo' } // Determine if the setting is a org setting or repo setting
13- const yaml = require ( 'js-yaml' ) ;
13+ const yaml = require ( 'js-yaml' )
1414
1515class Settings {
16- static fileCache = { } ;
16+ static fileCache = { }
1717
1818 static async syncAll ( nop , context , repo , config , ref ) {
1919 const settings = new Settings ( nop , context , repo , config , ref )
@@ -170,10 +170,10 @@ class Settings {
170170
171171 // remove duplicate rows in this.results
172172 this . results = this . results . filter ( ( thing , index , self ) => {
173- return index === self . findIndex ( ( t ) => {
174- return t . type === thing . type && t . repo === thing . repo && t . plugin === thing . plugin
175- } )
173+ return index === self . findIndex ( ( t ) => {
174+ return t . type === thing . type && t . repo === thing . repo && t . plugin === thing . plugin
176175 } )
176+ } )
177177
178178 let error = false
179179 // Different logic
@@ -300,7 +300,7 @@ ${this.results.reduce((x, y) => {
300300 }
301301 }
302302
303- async updateRepos ( repo ) {
303+ async updateRepos ( repo ) {
304304 this . subOrgConfigs = this . subOrgConfigs || await this . getSubOrgConfigs ( )
305305 // Keeping this as is instead of doing an object assign as that would cause `Cannot read properties of undefined (reading 'startsWith')` error
306306 // Copilot code review would recoommend using object assign but that would cause the error
@@ -336,17 +336,34 @@ ${this.results.reduce((x, y) => {
336336 if ( repoConfig ) {
337337 try {
338338 this . log . debug ( `found a matching repoconfig for this repo ${ JSON . stringify ( repoConfig ) } ` )
339+
339340 const childPlugins = this . childPluginsList ( repo )
340341 const RepoPlugin = Settings . PLUGINS . repository
341- return new RepoPlugin ( this . nop , this . github , repo , repoConfig , this . installation_id , this . log , this . errors ) . sync ( ) . then ( res => {
342- this . appendToResults ( res )
343- return Promise . all (
344- childPlugins . map ( ( [ Plugin , config ] ) => {
345- return new Plugin ( this . nop , this . github , repo , config , this . log , this . errors ) . sync ( )
346- } ) )
347- } ) . then ( res => {
348- this . appendToResults ( res )
349- } )
342+
343+ const archivePlugin = new Archive ( this . nop , this . github , repo , repoConfig , this . log )
344+ const { shouldArchive, shouldUnarchive } = await archivePlugin . getState ( )
345+
346+ if ( shouldUnarchive ) {
347+ this . log . debug ( `Unarchiving repo ${ repo . repo } ` )
348+ const unArchiveResults = await archivePlugin . sync ( )
349+ this . appendToResults ( unArchiveResults )
350+ }
351+
352+ const repoResults = await new RepoPlugin ( this . nop , this . github , repo , repoConfig , this . installation_id , this . log , this . errors ) . sync ( )
353+ this . appendToResults ( repoResults )
354+
355+ const childResults = await Promise . all (
356+ childPlugins . map ( ( [ Plugin , config ] ) => {
357+ return new Plugin ( this . nop , this . github , repo , config , this . log , this . errors ) . sync ( )
358+ } )
359+ )
360+ this . appendToResults ( childResults )
361+
362+ if ( shouldArchive ) {
363+ this . log . debug ( `Archiving repo ${ repo . repo } ` )
364+ const archiveResults = await archivePlugin . sync ( )
365+ this . appendToResults ( archiveResults )
366+ }
350367 } catch ( e ) {
351368 if ( this . nop ) {
352369 const nopcommand = new NopCommand ( this . constructor . name , this . repo , null , `${ e } ` , 'ERROR' )
@@ -368,7 +385,6 @@ ${this.results.reduce((x, y) => {
368385 }
369386 }
370387
371-
372388 async updateAll ( ) {
373389 // this.subOrgConfigs = this.subOrgConfigs || await this.getSubOrgConfigs(this.github, this.repo, this.log)
374390 // this.repoConfigs = this.repoConfigs || await this.getRepoConfigs(this.github, this.repo, this.log)
@@ -791,14 +807,14 @@ ${this.results.reduce((x, y) => {
791807 * @param params Params to fetch the file with
792808 * @return The parsed YAML file
793809 */
794- async loadYaml ( filePath ) {
810+ async loadYaml ( filePath ) {
795811 try {
796812 const repo = { owner : this . repo . owner , repo : env . ADMIN_REPO }
797813 const params = Object . assign ( repo , {
798814 path : filePath ,
799815 ref : this . ref
800816 } )
801- const namespacedFilepath = `${ this . repo . owner } /${ filePath } ` ;
817+ const namespacedFilepath = `${ this . repo . owner } /${ filePath } `
802818
803819 // If the filepath already exists in the fileCache, add the etag to the params
804820 // to check if the file has changed
@@ -898,7 +914,6 @@ ${this.results.reduce((x, y) => {
898914 }
899915 }
900916
901-
902917 async getSubOrgRepositories ( subOrgProperties ) {
903918 const organizationName = this . repo . owner
904919 try {
0 commit comments