Skip to content

Commit 620cf14

Browse files
dabcoderdecyjphr
andauthored
feat(extension): also allow .yaml file format (#735)
* feat(yaml): add yaml as valid file format * fix(syntax) * test(settings): add tests to verify both yaml and yml extensions work * fix(function): test new function * fix(overrideRepoConfig): remove helper function use * test(settings): attempt to fix failing tests * test(settings): simplify * fix(settings): load repo configuration in tests * docs(readme): yaml extension can be used too --------- Co-authored-by: Yadhav Jayaraman <[email protected]>
1 parent cbff6be commit 620cf14

File tree

3 files changed

+79
-35
lines changed

3 files changed

+79
-35
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
> [!NOTE]
3131
> The `suborg` and `repo` level settings directory structure cannot be customized.
3232
>
33-
> Settings files must have a `.yml` extension only. For now, the `.yaml` extension is ignored.
3433
3534

3635
## How it works

lib/settings.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ ${this.results.reduce((x, y) => {
323323

324324
// Overlay repo config
325325
// RepoConfigs should be preloaded but checking anyway
326-
const overrideRepoConfig = this.repoConfigs[`${repo.repo}.yml`]?.repository
326+
const overrideRepoConfig = this.repoConfigs[`${repo.repo}.yml`]?.repository || this.repoConfigs[`${repo.repo}.yaml`]?.repository
327327
if (overrideRepoConfig) {
328328
repoConfig = this.mergeDeep.mergeDeep({}, repoConfig, overrideRepoConfig)
329329
}
@@ -396,8 +396,8 @@ ${this.results.reduce((x, y) => {
396396
childPluginsList(repo) {
397397
const repoName = repo.repo
398398
const subOrgOverrideConfig = this.getSubOrgConfig(repoName)
399-
this.log.debug(`suborg config for ${repoName} is ${JSON.stringify(subOrgOverrideConfig)}`)
400-
const repoOverrideConfig = this.repoConfigs[`${repoName}.yml`] || {}
399+
this.log.debug(`suborg config for ${repoName} is ${JSON.stringify(subOrgOverrideConfig)}`)
400+
const repoOverrideConfig = this.getRepoOverrideConfig(repoName)
401401
const overrideConfig = this.mergeDeep.mergeDeep({}, this.returnRepoSpecificConfigs(this.config), subOrgOverrideConfig, repoOverrideConfig)
402402

403403
this.log.debug(`consolidated config is ${JSON.stringify(overrideConfig)}`)
@@ -425,6 +425,10 @@ ${this.results.reduce((x, y) => {
425425
return childPlugins
426426
}
427427

428+
getRepoOverrideConfig(repoName) {
429+
return this.repoConfigs[`${repoName}.yml`] || this.repoConfigs[`${repoName}.yaml`] || {}
430+
}
431+
428432
validate(section, baseConfig, overrideConfig) {
429433
const configValidator = this.configvalidators[section]
430434
if (configValidator) {
@@ -685,7 +689,7 @@ ${this.results.reduce((x, y) => {
685689
// If repo is passed get only its config
686690
// else load all the config
687691
if (repo) {
688-
if (override.name === `${repo.repo}.yml`) {
692+
if (override.name === `${repo.repo}.yml` || override.name === `${repo.repo}.yaml`) {
689693
const data = await this.loadYaml(override.path)
690694
this.log.debug(`data = ${JSON.stringify(data)}`)
691695
repoConfigs[override.name] = data
@@ -791,7 +795,7 @@ ${this.results.reduce((x, y) => {
791795
}
792796
)) {
793797
delete subOrgConfigs[key]
794-
}
798+
}
795799
}
796800
}
797801
return subOrgConfigs
@@ -862,7 +866,7 @@ ${this.results.reduce((x, y) => {
862866
if (this.nop) {
863867
//Remove nulls and undefined from the results
864868
const results = res.flat(3).filter(r => r)
865-
869+
866870
this.results = this.results.concat(results)
867871
}
868872
}

test/unit/lib/settings.test.js

Lines changed: 69 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,32 @@ describe('Settings Tests', () => {
2424
beforeEach(() => {
2525
const mockOctokit = jest.mocked(Octokit)
2626
const content = Buffer.from(`
27-
suborgrepos:
28-
- new-repo
29-
#- test*
30-
#- secret*
31-
27+
suborgrepos:
28+
- new-repo
29+
#- test*
30+
#- secret*
31+
3232
suborgteams:
3333
- core
3434
35-
suborgproperties:
35+
suborgproperties:
3636
- EDP: true
3737
- do_no_delete: true
38-
39-
teams:
40-
- name: core
41-
permission: bypass
38+
39+
teams:
40+
- name: core
41+
permission: bypass
4242
- name: docss
4343
permission: pull
4444
- name: docs
4545
permission: pull
46-
46+
4747
validator:
48-
pattern: '[a-zA-Z0-9_-]+_[a-zA-Z0-9_-]+.*'
48+
pattern: '[a-zA-Z0-9_-]+_[a-zA-Z0-9_-]+.*'
4949
50-
repository:
50+
repository:
5151
# A comma-separated list of topics to set on the repository
52-
topics:
52+
topics:
5353
- frontend
5454
`).toString('base64');
5555
mockOctokit.repos = {
@@ -191,6 +191,47 @@ repository:
191191
})
192192
}) // restrictedRepos
193193

194+
describe('getRepoOverrideConfig', () => {
195+
describe('repository defined in a file using the .yaml extension', () => {
196+
beforeEach(() => {
197+
stubConfig = {
198+
repoConfigs: {
199+
'repository.yaml': { repository: { name: 'repository', config: 'config1' } }
200+
}
201+
}
202+
})
203+
204+
it('Picks up a repository defined in file using the .yaml extension', () => {
205+
settings = createSettings(stubConfig)
206+
settings.repoConfigs = stubConfig.repoConfigs
207+
const repoConfig = settings.getRepoOverrideConfig('repository')
208+
209+
expect(typeof repoConfig).toBe('object')
210+
expect(repoConfig).not.toBeNull()
211+
expect(Object.keys(repoConfig).length).toBeGreaterThan(0)
212+
})
213+
})
214+
215+
describe('repository defined in a file using the .yml extension', () => {
216+
beforeEach(() => {
217+
stubConfig = {
218+
repoConfigs: {
219+
'repository.yml': { repository: { name: 'repository', config: 'config1' } }
220+
}
221+
}
222+
})
223+
224+
it('Picks up a repository defined in file using the .yml extension', () => {
225+
settings = createSettings(stubConfig)
226+
settings.repoConfigs = stubConfig.repoConfigs
227+
const repoConfig = settings.getRepoOverrideConfig('repository')
228+
229+
expect(typeof repoConfig).toBe('object')
230+
expect(repoConfig).not.toBeNull()
231+
expect(Object.keys(repoConfig).length).toBeGreaterThan(0)
232+
})
233+
})
234+
}) // repoOverrideConfig
194235
describe('loadConfigs', () => {
195236
describe('load suborg configs', () => {
196237
beforeEach(() => {
@@ -199,29 +240,29 @@ repository:
199240
}
200241
}
201242
subOrgConfig = yaml.load(`
202-
suborgrepos:
203-
- new-repo
204-
205-
suborgproperties:
243+
suborgrepos:
244+
- new-repo
245+
246+
suborgproperties:
206247
- EDP: true
207248
- do_no_delete: true
208-
209-
teams:
210-
- name: core
211-
permission: bypass
249+
250+
teams:
251+
- name: core
252+
permission: bypass
212253
- name: docss
213254
permission: pull
214255
- name: docs
215256
permission: pull
216-
257+
217258
validator:
218-
pattern: '[a-zA-Z0-9_-]+_[a-zA-Z0-9_-]+.*'
219-
220-
repository:
259+
pattern: '[a-zA-Z0-9_-]+_[a-zA-Z0-9_-]+.*'
260+
261+
repository:
221262
# A comma-separated list of topics to set on the repository
222-
topics:
263+
topics:
223264
- frontend
224-
265+
225266
`)
226267

227268
})

0 commit comments

Comments
 (0)