Skip to content

Commit

Permalink
upgrade (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
galargh committed Sep 14, 2022
1 parent 5b79617 commit 71110a4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- links to supported resources in HOWTOs
- posting PR comments when terraform plan output is very long
- PR parsing in the update workflow
- array head retrieval in scripts
4 changes: 2 additions & 2 deletions scripts/src/resources/repository-branch-protection-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ export class RepositoryBranchProtectionRule implements Resource {
`:${resource.values.pattern}`
)[0]
const required_pull_request_reviews =
resource.values.required_pull_request_reviews[0]
resource.values.required_pull_request_reviews?.at(0)
const required_status_checks =
resource.values.required_status_checks[0]
resource.values.required_status_checks?.at(0)
rules.push(
plainToClassFromExist(
new RepositoryBranchProtectionRule(
Expand Down
6 changes: 3 additions & 3 deletions scripts/src/resources/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ export class Repository implements Resource {
resource.mode === 'managed'
) {
const pages = {
...resource.values.pages[0],
source: {...resource.values.pages[0]?.source?.[0]}
...resource.values.pages?.at(0),
source: {...resource.values.pages?.at(0)?.source?.at(0)}
}
const template = resource.values.template[0]
const template = resource.values.template?.at(0)
repositories.push(
plainToClassFromExist(new Repository(resource.values.name), {
...resource.values,
Expand Down
10 changes: 6 additions & 4 deletions scripts/src/terraform/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ export class State {

private updateIgnoredPropertiesFrom(path: string) {
if (fs.existsSync(path)) {
const hcl = HCL.parseToObject(fs.readFileSync(path))?.[0]
const hcl = HCL.parseToObject(fs.readFileSync(path))?.at(0)
for (const [name, resource] of Object.entries(hcl?.resource ?? {}) as [
string,
any
][]) {
const properties = resource?.this?.[0]?.lifecycle?.[0]?.ignore_changes
const properties = resource?.this
?.at(0)
?.lifecycle?.at(0)?.ignore_changes
if (properties !== undefined) {
this._ignoredProperties[name] = properties.map((v: string) =>
v.substring(2, v.length - 1)
Expand All @@ -59,8 +61,8 @@ export class State {

private updateIgnoredTypesFrom(path: string) {
if (fs.existsSync(path)) {
const hcl = HCL.parseToObject(fs.readFileSync(path))?.[0]
const types = hcl?.locals?.[0]?.resource_types
const hcl = HCL.parseToObject(fs.readFileSync(path))?.at(0)
const types = hcl?.locals?.at(0)?.resource_types
if (types !== undefined) {
this._ignoredTypes = ResourceConstructors.map(c => c.StateType).filter(
t => !types.includes(t)
Expand Down

0 comments on commit 71110a4

Please sign in to comment.