From b8e9f707e0bb063bf2e8e1b2b7f287337c0082c1 Mon Sep 17 00:00:00 2001 From: Yadhav Jayaraman <57544838+decyjphr@users.noreply.github.com> Date: Fri, 21 Mar 2025 15:59:40 -0400 Subject: [PATCH 1/3] Update settings.js --- lib/settings.js | 94 ++++++++++++++++++++++++++----------------------- 1 file changed, 50 insertions(+), 44 deletions(-) diff --git a/lib/settings.js b/lib/settings.js index 591f2ad0..cb313281 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -321,48 +321,61 @@ ${this.results.reduce((x, y) => { } } - // Overlay repo config + // Overlay repo config // RepoConfigs should be preloaded but checking anyway const overrideRepoConfig = this.repoConfigs[`${repo.repo}.yml`]?.repository || this.repoConfigs[`${repo.repo}.yaml`]?.repository if (overrideRepoConfig) { repoConfig = this.mergeDeep.mergeDeep({}, repoConfig, overrideRepoConfig) } - const {shouldContinue, nopCommands} = await new Archive(this.nop, this.github, repo, repoConfig, this.log).sync() - if (nopCommands) this.appendToResults(nopCommands) - if (shouldContinue) { - if (repoConfig) { - try { - this.log.debug(`found a matching repoconfig for this repo ${JSON.stringify(repoConfig)}`) - const childPlugins = this.childPluginsList(repo) - const RepoPlugin = Settings.PLUGINS.repository - return new RepoPlugin(this.nop, this.github, repo, repoConfig, this.installation_id, this.log, this.errors).sync().then(res => { - this.appendToResults(res) - return Promise.all( - childPlugins.map(([Plugin, config]) => { - return new Plugin(this.nop, this.github, repo, config, this.log, this.errors).sync() - })) - }).then(res => { - this.appendToResults(res) - }) - } catch (e) { - if (this.nop) { - const nopcommand = new NopCommand(this.constructor.name, this.repo, null, `${e}`, 'ERROR') - this.log.error(`NOPCOMMAND ${JSON.stringify(nopcommand)}`) - this.appendToResults([nopcommand]) - // throw e - } else { - throw e - } - } - } else { - this.log.debug(`Didnt find any a matching repoconfig for this repo ${JSON.stringify(repo)} in ${JSON.stringify(this.repoConfigs)}`) + if (repoConfig) { + try { + this.log.debug(`found a matching repoconfig for this repo ${JSON.stringify(repoConfig)}`) + const childPlugins = this.childPluginsList(repo) - return Promise.all(childPlugins.map(([Plugin, config]) => { - return new Plugin(this.nop, this.github, repo, config, this.log, this.errors).sync().then(res => { - this.appendToResults(res) + const RepoPlugin = Settings.PLUGINS.repository + + const archivePlugin = new Archive(this.nop, this.github, repo, repoConfig, this.log) + const { shouldArchive, shouldUnarchive } = await archivePlugin.getState() + + if (shouldUnarchive) { + this.log.debug(`Unarchiving repo ${repo.repo}`) + const unArchiveResults = await archivePlugin.sync() + this.appendToResults(unArchiveResults) + } + + const repoResults = await new RepoPlugin(this.nop, this.github, repo, repoConfig, this.installation_id, this.log, this.errors).sync() + this.appendToResults(repoResults) + + const childResults = await Promise.all( + childPlugins.map(([Plugin, config]) => { + return new Plugin(this.nop, this.github, repo, config, this.log, this.errors).sync() }) - })) + ) + this.appendToResults(childResults) + + if (shouldArchive) { + this.log.debug(`Archiving repo ${repo.repo}`) + const archiveResults = await archivePlugin.sync() + this.appendToResults(archiveResults) + } + } catch (e) { + if (this.nop) { + const nopcommand = new NopCommand(this.constructor.name, this.repo, null, `${e}`, 'ERROR') + this.log.error(`NOPCOMMAND ${JSON.stringify(nopcommand)}`) + this.appendToResults([nopcommand]) + // throw e + } else { + throw e + } } + } else { + this.log.debug(`Didnt find any a matching repoconfig for this repo ${JSON.stringify(repo)} in ${JSON.stringify(this.repoConfigs)}`) + const childPlugins = this.childPluginsList(repo) + return Promise.all(childPlugins.map(([Plugin, config]) => { + return new Plugin(this.nop, this.github, repo, config, this.log, this.errors).sync().then(res => { + this.appendToResults(res) + }) + })) } } @@ -885,17 +898,10 @@ ${this.results.reduce((x, y) => { const value = propertyFilter[name] try { - const query = `props.${name}.${value}` + const query = `props.${name}:${value}` const encodedQuery = encodeURIComponent(query) - - return this.github.paginate( - this.github.repos.getCustomPropertiesValues, - { - org: organizationName, - repository_query: encodedQuery, - per_page: 100 - } - ) + const options = this.github.request.endpoint((`/orgs/${this.repo.owner}/properties/values?repository_query=${encodedQuery}`)) + return this.github.paginate(options) } catch (error) { throw new Error(`Failed to filter repositories for property ${name}: ${error.message}`) } From 3f9550aa5a63f95a1552828c8b4cf2e63df10c31 Mon Sep 17 00:00:00 2001 From: Yadhav Jayaraman <57544838+decyjphr@users.noreply.github.com> Date: Fri, 21 Mar 2025 16:04:44 -0400 Subject: [PATCH 2/3] Fix getRepositoriesByProperty --- lib/settings.js | 82 +++++++++++++++++++++---------------------------- 1 file changed, 35 insertions(+), 47 deletions(-) diff --git a/lib/settings.js b/lib/settings.js index cb313281..aa2d67c3 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -321,61 +321,48 @@ ${this.results.reduce((x, y) => { } } - // Overlay repo config + // Overlay repo config // RepoConfigs should be preloaded but checking anyway const overrideRepoConfig = this.repoConfigs[`${repo.repo}.yml`]?.repository || this.repoConfigs[`${repo.repo}.yaml`]?.repository if (overrideRepoConfig) { repoConfig = this.mergeDeep.mergeDeep({}, repoConfig, overrideRepoConfig) } - if (repoConfig) { - try { - this.log.debug(`found a matching repoconfig for this repo ${JSON.stringify(repoConfig)}`) - - const childPlugins = this.childPluginsList(repo) - const RepoPlugin = Settings.PLUGINS.repository - - const archivePlugin = new Archive(this.nop, this.github, repo, repoConfig, this.log) - const { shouldArchive, shouldUnarchive } = await archivePlugin.getState() - - if (shouldUnarchive) { - this.log.debug(`Unarchiving repo ${repo.repo}`) - const unArchiveResults = await archivePlugin.sync() - this.appendToResults(unArchiveResults) - } - - const repoResults = await new RepoPlugin(this.nop, this.github, repo, repoConfig, this.installation_id, this.log, this.errors).sync() - this.appendToResults(repoResults) - - const childResults = await Promise.all( - childPlugins.map(([Plugin, config]) => { - return new Plugin(this.nop, this.github, repo, config, this.log, this.errors).sync() + const {shouldContinue, nopCommands} = await new Archive(this.nop, this.github, repo, repoConfig, this.log).sync() + if (nopCommands) this.appendToResults(nopCommands) + if (shouldContinue) { + if (repoConfig) { + try { + this.log.debug(`found a matching repoconfig for this repo ${JSON.stringify(repoConfig)}`) + const childPlugins = this.childPluginsList(repo) + const RepoPlugin = Settings.PLUGINS.repository + return new RepoPlugin(this.nop, this.github, repo, repoConfig, this.installation_id, this.log, this.errors).sync().then(res => { + this.appendToResults(res) + return Promise.all( + childPlugins.map(([Plugin, config]) => { + return new Plugin(this.nop, this.github, repo, config, this.log, this.errors).sync() + })) + }).then(res => { + this.appendToResults(res) }) - ) - this.appendToResults(childResults) - - if (shouldArchive) { - this.log.debug(`Archiving repo ${repo.repo}`) - const archiveResults = await archivePlugin.sync() - this.appendToResults(archiveResults) - } - } catch (e) { - if (this.nop) { - const nopcommand = new NopCommand(this.constructor.name, this.repo, null, `${e}`, 'ERROR') - this.log.error(`NOPCOMMAND ${JSON.stringify(nopcommand)}`) - this.appendToResults([nopcommand]) - // throw e - } else { - throw e + } catch (e) { + if (this.nop) { + const nopcommand = new NopCommand(this.constructor.name, this.repo, null, `${e}`, 'ERROR') + this.log.error(`NOPCOMMAND ${JSON.stringify(nopcommand)}`) + this.appendToResults([nopcommand]) + // throw e + } else { + throw e + } } + } else { + this.log.debug(`Didnt find any a matching repoconfig for this repo ${JSON.stringify(repo)} in ${JSON.stringify(this.repoConfigs)}`) + const childPlugins = this.childPluginsList(repo) + return Promise.all(childPlugins.map(([Plugin, config]) => { + return new Plugin(this.nop, this.github, repo, config, this.log, this.errors).sync().then(res => { + this.appendToResults(res) + }) + })) } - } else { - this.log.debug(`Didnt find any a matching repoconfig for this repo ${JSON.stringify(repo)} in ${JSON.stringify(this.repoConfigs)}`) - const childPlugins = this.childPluginsList(repo) - return Promise.all(childPlugins.map(([Plugin, config]) => { - return new Plugin(this.nop, this.github, repo, config, this.log, this.errors).sync().then(res => { - this.appendToResults(res) - }) - })) } } @@ -906,6 +893,7 @@ ${this.results.reduce((x, y) => { throw new Error(`Failed to filter repositories for property ${name}: ${error.message}`) } } + async getSubOrgRepositories (subOrgProperties) { const organizationName = this.repo.owner From 0859ceb2b6388b4afbee6bf3ec2e0ddf8874c18d Mon Sep 17 00:00:00 2001 From: Yadhav Jayaraman <57544838+decyjphr@users.noreply.github.com> Date: Fri, 21 Mar 2025 18:14:41 -0400 Subject: [PATCH 3/3] Update endpoint to use organizationName variable --- lib/settings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/settings.js b/lib/settings.js index aa2d67c3..56e20e88 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -887,7 +887,7 @@ ${this.results.reduce((x, y) => { try { const query = `props.${name}:${value}` const encodedQuery = encodeURIComponent(query) - const options = this.github.request.endpoint((`/orgs/${this.repo.owner}/properties/values?repository_query=${encodedQuery}`)) + const options = this.github.request.endpoint((`/orgs/${organizationName}/properties/values?repository_query=${encodedQuery}`)) return this.github.paginate(options) } catch (error) { throw new Error(`Failed to filter repositories for property ${name}: ${error.message}`)