Skip to content

Commit

Permalink
Merge pull request integrations#385 from svanharmelen/svh/b-branch-pr…
Browse files Browse the repository at this point in the history
…otection

Prevent a panic when trying to use DismissalRestrictions
  • Loading branch information
Jeremy Udit authored Mar 25, 2020
2 parents c33ab7b + 0d722ee commit 0bb8e92
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
19 changes: 10 additions & 9 deletions github/resource_github_branch_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,17 +433,18 @@ func requireSignedCommitsUpdate(d *schema.ResourceData, meta interface{}) (err e
func flattenAndSetRequiredPullRequestReviews(d *schema.ResourceData, protection *github.Protection) error {
rprr := protection.RequiredPullRequestReviews
if rprr != nil {
users := make([]interface{}, 0, len(rprr.DismissalRestrictions.Users))
for _, u := range rprr.DismissalRestrictions.Users {
if u.Login != nil {
users = append(users, *u.Login)
var users, teams []interface{}
if rprr.DismissalRestrictions != nil {
for _, u := range rprr.DismissalRestrictions.Users {
if u.Login != nil {
users = append(users, *u.Login)
}
}
}

teams := make([]interface{}, 0, len(rprr.DismissalRestrictions.Teams))
for _, t := range rprr.DismissalRestrictions.Teams {
if t.Slug != nil {
teams = append(teams, *t.Slug)
for _, t := range rprr.DismissalRestrictions.Teams {
if t.Slug != nil {
teams = append(teams, *t.Slug)
}
}
}

Expand Down
17 changes: 10 additions & 7 deletions github/resource_github_branch_protection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,18 +305,21 @@ func testAccCheckGithubBranchProtectionPullRequestReviews(protection *github.Pro
return fmt.Errorf("Expected `dismiss_state_reviews` to be %t, got %t", expectedStale, reviews.DismissStaleReviews)
}

users := []string{}
for _, u := range reviews.DismissalRestrictions.Users {
users = append(users, *u.Login)
var users, teams []string
if reviews.DismissalRestrictions != nil {
for _, u := range reviews.DismissalRestrictions.Users {
users = append(users, *u.Login)
}

for _, t := range reviews.DismissalRestrictions.Teams {
teams = append(teams, *t.Slug)
}
}

if diff := pretty.Compare(users, expectedUsers); diff != "" {
return fmt.Errorf("diff %q: (-got +want)\n%s", "required_pull_request_reviews.dismissal_users", diff)
}

teams := []string{}
for _, t := range reviews.DismissalRestrictions.Teams {
teams = append(teams, *t.Slug)
}
sort.Strings(teams)
sort.Strings(expectedTeams)
if diff := pretty.Compare(teams, expectedTeams); diff != "" {
Expand Down

0 comments on commit 0bb8e92

Please sign in to comment.