Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(yaml): add yaml as valid file format #1

Open
wants to merge 8 commits into
base: main-enterprise
Choose a base branch
from
12 changes: 8 additions & 4 deletions lib/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,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)
}
Expand Down Expand Up @@ -384,8 +384,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)}`)
Expand Down Expand Up @@ -413,6 +413,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) {
Expand Down Expand Up @@ -643,7 +647,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
Expand Down
40 changes: 40 additions & 0 deletions test/unit/lib/settings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,44 @@ describe('Settings Tests', () => {
})
})
}) // 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', () => {
const settings = createSettings(stubConfig)
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', () => {
const settings = createSettings(stubConfig)
const repoConfig = settings.getRepoOverrideConfig('repository')

expect(typeof repoConfig).toBe('object')
expect(repoConfig).not.toBeNull()
expect(Object.keys(repoConfig).length).toBeGreaterThan(0)
})
})
}) // repoOverrideConfig
}) // Settings Tests