Skip to content

Commit

Permalink
Add support for assigning apps in branch protection rules
Browse files Browse the repository at this point in the history
  • Loading branch information
gposton committed Jan 31, 2020
1 parent 681be09 commit 81f19ae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions github/resource_github_branch_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
},
},
},
},
Expand Down Expand Up @@ -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),
},
})
}
Expand Down Expand Up @@ -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{})
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion github/resource_github_team_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func resourceGithubTeamRepository() *schema.Resource {
Type: schema.TypeString,
Optional: true,
Default: "pull",
ValidateFunc: validateValueFunc([]string{"pull", "push", "admin"}),
ValidateFunc: validateValueFunc([]string{"pull", "triage", "push", "maintain", "admin"}),
},
"etag": {
Type: schema.TypeString,
Expand Down

0 comments on commit 81f19ae

Please sign in to comment.