Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent a panic when trying to use DismissalRestrictions #385

Merged
merged 1 commit into from
Mar 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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