Skip to content

Commit

Permalink
Avoid errors when variables or protection rules are unset
Browse files Browse the repository at this point in the history
Signed-off-by: Kyle Harding <kyle@balena.io>
  • Loading branch information
klutchell committed Jun 18, 2024
1 parent 1b628d0 commit a24dcb8
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions lib/plugins/environments.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
})
}
}
}

Expand Down

0 comments on commit a24dcb8

Please sign in to comment.