Skip to content

Commit

Permalink
fix: handle empty deployment config yaml file
Browse files Browse the repository at this point in the history
  • Loading branch information
PendaGTP committed Jan 9, 2025
1 parent 1fff61c commit 7d1a1b4
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions lib/deploymentConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ class DeploymentConfig {
static {
const deploymentConfigPath = process.env.DEPLOYMENT_CONFIG_FILE ? process.env.DEPLOYMENT_CONFIG_FILE : 'deployment-settings.yml'
if (fs.existsSync(deploymentConfigPath)) {
this.config = yaml.load(fs.readFileSync(deploymentConfigPath))
this.config = yaml.load(fs.readFileSync(deploymentConfigPath)) || {}
} else {
this.config = { restrictedRepos: ['admin', '.github', 'safe-settings'] }
}

const overridevalidators = this.config.overridevalidators
if (this.isIterable(overridevalidators)) {
const overridevalidators = this.config.overridevalidators || []
if (this.isNonEmptyArray(overridevalidators)) {
for (const validator of overridevalidators) {
// eslint-disable-next-line no-new-func
const f = new Function('baseconfig', 'overrideconfig', 'githubContext', validator.script)
this.overridevalidators[validator.plugin] = { canOverride: f, error: validator.error }
}
}
const configvalidators = this.config.configvalidators
if (this.isIterable(configvalidators)) {
const configvalidators = this.config.configvalidators || []
if (this.isNonEmptyArray(configvalidators)) {
for (const validator of configvalidators) {
// eslint-disable-next-line no-new-func
const f = new Function('baseconfig', 'githubContext', validator.script)
Expand All @@ -38,12 +38,8 @@ class DeploymentConfig {
}
}

static isIterable (obj) {
// checks for null and undefined
if (obj == null) {
return false
}
return typeof obj[Symbol.iterator] === 'function'
static isNonEmptyArray (obj) {
return Array.isArray(obj) && obj.length > 0
}

// eslint-disable-next-line no-useless-constructor
Expand Down

0 comments on commit 7d1a1b4

Please sign in to comment.