From a24dcb82f893e26f4583b81e7426db42a3b2d29b Mon Sep 17 00:00:00 2001 From: Kyle Harding Date: Thu, 4 Apr 2024 14:25:53 -0400 Subject: [PATCH] Avoid errors when variables or protection rules are unset Signed-off-by: Kyle Harding --- lib/plugins/environments.js | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/lib/plugins/environments.js b/lib/plugins/environments.js index 98e63827..6987230b 100644 --- a/lib/plugins/environments.js +++ b/lib/plugins/environments.js @@ -231,7 +231,7 @@ module.exports = class Environments extends Diffable { wait_timer: attrs.wait_timer, prevent_self_review: attrs.prevent_self_review, reviewers: attrs.reviewers, - deployment_branch_policy: attrs.deployment_branch_policy === null + deployment_branch_policy: attrs.deployment_branch_policy == null ? null : { protected_branches: attrs.deployment_branch_policy.protected_branches, @@ -250,23 +250,27 @@ module.exports = class Environments extends Diffable { } } - for (const variable of attrs.variables) { - await this.github.request('POST /repos/:org/:repo/environments/:environment_name/variables', { - org: this.repo.owner, - repo: this.repo.repo, - environment_name: attrs.name, - name: variable.name, - value: variable.value - }) + if (attrs.variables) { + for (const variable of attrs.variables) { + await this.github.request('POST /repos/:org/:repo/environments/:environment_name/variables', { + org: this.repo.owner, + repo: this.repo.repo, + environment_name: attrs.name, + name: variable.name, + value: variable.value + }) + } } - for (const rule of attrs.deployment_protection_rules) { - await this.github.request('POST /repos/:org/:repo/environments/:environment_name/deployment_protection_rules', { - org: this.repo.owner, - repo: this.repo.repo, - environment_name: attrs.name, - integration_id: rule.app_id - }) + if (attrs.deployment_protection_rules) { + for (const rule of attrs.deployment_protection_rules) { + await this.github.request('POST /repos/:org/:repo/environments/:environment_name/deployment_protection_rules', { + org: this.repo.owner, + repo: this.repo.repo, + environment_name: attrs.name, + integration_id: rule.app_id + }) + } } }