From e4d4ccff171082d4a46b13b2896c4c6e29467e06 Mon Sep 17 00:00:00 2001 From: gposton Date: Thu, 21 Nov 2019 14:37:42 -0500 Subject: [PATCH] Add support for assigning apps in branch protection rules --- github/resource_github_branch_protection.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/github/resource_github_branch_protection.go b/github/resource_github_branch_protection.go index 28f6cf54b3..b74d85abc9 100644 --- a/github/resource_github_branch_protection.go +++ b/github/resource_github_branch_protection.go @@ -123,6 +123,11 @@ func resourceGithubBranchProtection() *schema.Resource { Optional: true, Elem: &schema.Schema{Type: schema.TypeString}, }, + "apps": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, }, }, }, @@ -473,10 +478,18 @@ func flattenAndSetRestrictions(d *schema.ResourceData, protection *github.Protec } } + apps := make([]interface{}, 0, len(restrictions.Apps)) + for _, t := range restrictions.Apps { + if t.Slug != nil { + apps = append(apps, *t.Slug) + } + } + return d.Set("restrictions", []interface{}{ map[string]interface{}{ "users": schema.NewSet(schema.HashString, users), "teams": schema.NewSet(schema.HashString, teams), + "apps": schema.NewSet(schema.HashString, apps), }, }) } @@ -557,6 +570,7 @@ func expandRestrictions(d *schema.ResourceData) (*github.BranchRestrictionsReque if v == nil { restrictions.Users = []string{} restrictions.Teams = []string{} + restrictions.Apps = []string{} return restrictions, nil } m := v.(map[string]interface{}) @@ -565,6 +579,8 @@ func expandRestrictions(d *schema.ResourceData) (*github.BranchRestrictionsReque restrictions.Users = users teams := expandNestedSet(m, "teams") restrictions.Teams = teams + apps := expandNestedSet(m, "apps") + restrictions.Apps = apps } return restrictions, nil }