Skip to content

Commit

Permalink
attempt at flatten + expand
Browse files Browse the repository at this point in the history
  • Loading branch information
k24dizzle committed Apr 22, 2022
1 parent f7a02c7 commit 4c8d794
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion github/resource_github_branch_protection_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ func resourceGithubBranchProtectionV3() *schema.Resource {
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"context": {
Type: schema.TypeString,
Type: schema.TypeString,
Required: true,
},
"app_id": {
Type: schema.TypeInt,
Expand Down
18 changes: 18 additions & 0 deletions github/resource_github_branch_protection_v3_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,19 @@ func flattenAndSetRequiredStatusChecks(d *schema.ResourceData, protection *githu
contexts = append(contexts, c)
}

checks := make([]interface{}, 0, len(rsc.Checks))
for _, c := range rsc.Checks {
checkMap := make(map[string]interface{})
checkMap["context"] = c.Context
checkMap["app_id"] = c.AppID
checks = append(checks, checkMap)
}

return d.Set("required_status_checks", []interface{}{
map[string]interface{}{
"strict": rsc.Strict,
"contexts": schema.NewSet(schema.HashString, contexts),
"checks": checks,
},
})
}
Expand Down Expand Up @@ -193,6 +202,15 @@ func expandRequiredStatusChecks(d *schema.ResourceData) (*github.RequiredStatusC

contexts := expandNestedSet(m, "contexts")
rsc.Contexts = contexts

checks := make([]RequiredStatusCheck, 0)
for _, c := range m["checks"].([]map[string]interface{}) {
check := new(github.RequiredStatusCheck)
check.Context = c["context"]
check.AppID = c["app_id"]
checks = append(checks, check)
}
rsc.Checks = checks
}
return rsc, nil
}
Expand Down

0 comments on commit 4c8d794

Please sign in to comment.