diff --git a/README.md b/README.md index 49a5cee4..3a456e14 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,6 @@ > [!NOTE] > The `suborg` and `repo` level settings directory structure cannot be customized. > -> Settings files must have a `.yml` extension only. For now, the `.yaml` extension is ignored. ## How it works diff --git a/lib/settings.js b/lib/settings.js index 39ed2d51..264be42c 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -322,7 +322,7 @@ ${this.results.reduce((x, y) => { // Overlay repo config // RepoConfigs should be preloaded but checking anyway - const overrideRepoConfig = this.repoConfigs[`${repo.repo}.yml`]?.repository + const overrideRepoConfig = this.repoConfigs[`${repo.repo}.yml`]?.repository || this.repoConfigs[`${repo.repo}.yaml`]?.repository if (overrideRepoConfig) { repoConfig = this.mergeDeep.mergeDeep({}, repoConfig, overrideRepoConfig) } @@ -391,8 +391,8 @@ ${this.results.reduce((x, y) => { childPluginsList(repo) { const repoName = repo.repo const subOrgOverrideConfig = this.getSubOrgConfig(repoName) - this.log.debug(`suborg config for ${repoName} is ${JSON.stringify(subOrgOverrideConfig)}`) - const repoOverrideConfig = this.repoConfigs[`${repoName}.yml`] || {} + this.log.debug(`suborg config for ${repoName} is ${JSON.stringify(subOrgOverrideConfig)}`) + const repoOverrideConfig = this.getRepoOverrideConfig(repoName) const overrideConfig = this.mergeDeep.mergeDeep({}, this.returnRepoSpecificConfigs(this.config), subOrgOverrideConfig, repoOverrideConfig) this.log.debug(`consolidated config is ${JSON.stringify(overrideConfig)}`) @@ -420,6 +420,10 @@ ${this.results.reduce((x, y) => { return childPlugins } + getRepoOverrideConfig(repoName) { + return this.repoConfigs[`${repoName}.yml`] || this.repoConfigs[`${repoName}.yaml`] || {} + } + validate(section, baseConfig, overrideConfig) { const configValidator = this.configvalidators[section] if (configValidator) { @@ -680,7 +684,7 @@ ${this.results.reduce((x, y) => { // If repo is passed get only its config // else load all the config if (repo) { - if (override.name === `${repo.repo}.yml`) { + if (override.name === `${repo.repo}.yml` || override.name === `${repo.repo}.yaml`) { const data = await this.loadYaml(override.path) this.log.debug(`data = ${JSON.stringify(data)}`) repoConfigs[override.name] = data @@ -786,7 +790,7 @@ ${this.results.reduce((x, y) => { } )) { delete subOrgConfigs[key] - } + } } } return subOrgConfigs @@ -857,7 +861,7 @@ ${this.results.reduce((x, y) => { if (this.nop) { //Remove nulls and undefined from the results const results = res.flat(3).filter(r => r) - + this.results = this.results.concat(results) } } diff --git a/test/unit/lib/settings.test.js b/test/unit/lib/settings.test.js index c91583d3..5271dbe9 100644 --- a/test/unit/lib/settings.test.js +++ b/test/unit/lib/settings.test.js @@ -25,32 +25,32 @@ describe('Settings Tests', () => { beforeEach(() => { const mockOctokit = jest.mocked(Octokit) const content = Buffer.from(` -suborgrepos: -- new-repo -#- test* -#- secret* - +suborgrepos: +- new-repo +#- test* +#- secret* + suborgteams: - core -suborgproperties: +suborgproperties: - EDP: true - do_no_delete: true - -teams: - - name: core - permission: bypass + +teams: + - name: core + permission: bypass - name: docss permission: pull - name: docs permission: pull - + validator: - pattern: '[a-zA-Z0-9_-]+_[a-zA-Z0-9_-]+.*' + pattern: '[a-zA-Z0-9_-]+_[a-zA-Z0-9_-]+.*' -repository: +repository: # A comma-separated list of topics to set on the repository - topics: + topics: - frontend `).toString('base64'); mockOctokit.repos = { @@ -192,6 +192,47 @@ repository: }) }) // restrictedRepos + describe('getRepoOverrideConfig', () => { + describe('repository defined in a file using the .yaml extension', () => { + beforeEach(() => { + stubConfig = { + repoConfigs: { + 'repository.yaml': { repository: { name: 'repository', config: 'config1' } } + } + } + }) + + it('Picks up a repository defined in file using the .yaml extension', () => { + settings = createSettings(stubConfig) + settings.repoConfigs = stubConfig.repoConfigs + const repoConfig = settings.getRepoOverrideConfig('repository') + + expect(typeof repoConfig).toBe('object') + expect(repoConfig).not.toBeNull() + expect(Object.keys(repoConfig).length).toBeGreaterThan(0) + }) + }) + + describe('repository defined in a file using the .yml extension', () => { + beforeEach(() => { + stubConfig = { + repoConfigs: { + 'repository.yml': { repository: { name: 'repository', config: 'config1' } } + } + } + }) + + it('Picks up a repository defined in file using the .yml extension', () => { + settings = createSettings(stubConfig) + settings.repoConfigs = stubConfig.repoConfigs + const repoConfig = settings.getRepoOverrideConfig('repository') + + expect(typeof repoConfig).toBe('object') + expect(repoConfig).not.toBeNull() + expect(Object.keys(repoConfig).length).toBeGreaterThan(0) + }) + }) + }) // repoOverrideConfig describe('loadConfigs', () => { describe('load suborg configs', () => { beforeEach(() => { @@ -200,29 +241,29 @@ repository: } } subOrgConfig = yaml.load(` - suborgrepos: - - new-repo - - suborgproperties: + suborgrepos: + - new-repo + + suborgproperties: - EDP: true - do_no_delete: true - - teams: - - name: core - permission: bypass + + teams: + - name: core + permission: bypass - name: docss permission: pull - name: docs permission: pull - + validator: - pattern: '[a-zA-Z0-9_-]+_[a-zA-Z0-9_-]+.*' - - repository: + pattern: '[a-zA-Z0-9_-]+_[a-zA-Z0-9_-]+.*' + + repository: # A comma-separated list of topics to set on the repository - topics: + topics: - frontend - + `) })