Skip to content

Commit

Permalink
Revert PR #1020 to undo performance regression as reported in #1328 (#…
Browse files Browse the repository at this point in the history
…1330)

This reverts commit 553785b.
  • Loading branch information
kfcampbell committed Oct 13, 2022
1 parent ad2193c commit 05a8875
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 295 deletions.
53 changes: 2 additions & 51 deletions github/resource_github_branch_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,27 +154,6 @@ func resourceGithubBranchProtectionCreate(d *schema.ResourceData, meta interface
if err != nil {
return err
}

var reviewIds, pushIds, bypassIds []string
reviewIds, err = getActorIds(data.ReviewDismissalActorIDs, meta)
if err != nil {
return err
}

pushIds, err = getActorIds(data.PushActorIDs, meta)
if err != nil {
return err
}

bypassIds, err = getActorIds(data.BypassPullRequestActorIDs, meta)
if err != nil {
return err
}

data.PushActorIDs = pushIds
data.ReviewDismissalActorIDs = reviewIds
data.BypassPullRequestActorIDs = bypassIds

input := githubv4.CreateBranchProtectionRuleInput{
AllowsDeletions: githubv4.NewBoolean(githubv4.Boolean(data.AllowsDeletions)),
AllowsForcePushes: githubv4.NewBoolean(githubv4.Boolean(data.AllowsForcePushes)),
Expand Down Expand Up @@ -276,11 +255,7 @@ func resourceGithubBranchProtectionRead(d *schema.ResourceData, meta interface{}
log.Printf("[DEBUG] Problem setting '%s' in %s %s branch protection (%s)", PROTECTION_REQUIRES_CONVERSATION_RESOLUTION, protection.Repository.Name, protection.Pattern, d.Id())
}

approvingReviews, err := setApprovingReviews(protection, d, meta)
if err != nil {
return err
}

approvingReviews := setApprovingReviews(protection)
err = d.Set(PROTECTION_REQUIRES_APPROVING_REVIEWS, approvingReviews)
if err != nil {
log.Printf("[DEBUG] Problem setting '%s' in %s %s branch protection (%s)", PROTECTION_REQUIRES_APPROVING_REVIEWS, protection.Repository.Name, protection.Pattern, d.Id())
Expand All @@ -292,10 +267,7 @@ func resourceGithubBranchProtectionRead(d *schema.ResourceData, meta interface{}
log.Printf("[DEBUG] Problem setting '%s' in %s %s branch protection (%s)", PROTECTION_REQUIRES_STATUS_CHECKS, protection.Repository.Name, protection.Pattern, d.Id())
}

restrictsPushes, err := setPushes(protection, d, meta)
if err != nil {
return err
}
restrictsPushes := setPushes(protection)
err = d.Set(PROTECTION_RESTRICTS_PUSHES, restrictsPushes)
if err != nil {
log.Printf("[DEBUG] Problem setting '%s' in %s %s branch protection (%s)", PROTECTION_RESTRICTS_PUSHES, protection.Repository.Name, protection.Pattern, d.Id())
Expand All @@ -316,27 +288,6 @@ func resourceGithubBranchProtectionUpdate(d *schema.ResourceData, meta interface
if err != nil {
return err
}

var reviewIds, pushIds, bypassIds []string
reviewIds, err = getActorIds(data.ReviewDismissalActorIDs, meta)
if err != nil {
return err
}

pushIds, err = getActorIds(data.PushActorIDs, meta)
if err != nil {
return err
}

bypassIds, err = getActorIds(data.BypassPullRequestActorIDs, meta)
if err != nil {
return err
}

data.PushActorIDs = pushIds
data.ReviewDismissalActorIDs = reviewIds
data.BypassPullRequestActorIDs = bypassIds

input := githubv4.UpdateBranchProtectionRuleInput{
BranchProtectionRuleID: d.Id(),
AllowsDeletions: githubv4.NewBoolean(githubv4.Boolean(data.AllowsDeletions)),
Expand Down
54 changes: 0 additions & 54 deletions github/resource_github_branch_protection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,60 +380,6 @@ func TestAccGithubBranchProtection(t *testing.T) {

})

t.Run("configures branch push restrictions with username", func(t *testing.T) {

user := fmt.Sprintf("/%s", testOwnerFunc())
config := fmt.Sprintf(`
resource "github_repository" "test" {
name = "tf-acc-test-%s"
auto_init = true
}
resource "github_branch_protection" "test" {
repository_id = github_repository.test.name
pattern = "main"
push_restrictions = [
"%s",
]
}
`, randomID, user)

check := resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(
"github_branch_protection.test", "push_restrictions.#", "1",
),
)

testCase := func(t *testing.T, mode string) {
resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessMode(t, mode) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: config,
Check: check,
},
},
})
}

t.Run("with an anonymous account", func(t *testing.T) {
t.Skip("anonymous account not supported for this operation")
})

t.Run("with an individual account", func(t *testing.T) {
t.Skip("individual account not supported for this operation")
})

t.Run("with an organization account", func(t *testing.T) {
testCase(t, organization)
})

})

t.Run("configures force pushes and deletions", func(t *testing.T) {

config := fmt.Sprintf(`
Expand Down
8 changes: 2 additions & 6 deletions github/resource_github_repository_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,9 @@ func resourceGithubRepositoryEnvironmentRead(d *schema.ResourceData, meta interf
for _, r := range pr.Reviewers {
switch *r.Type {
case "Team":
if r.Reviewer.(*github.Team).ID != nil {
teams = append(teams, *r.Reviewer.(*github.Team).ID)
}
teams = append(teams, *r.Reviewer.(*github.Team).ID)
case "User":
if r.Reviewer.(*github.User).ID != nil {
users = append(users, *r.Reviewer.(*github.User).ID)
}
users = append(users, *r.Reviewer.(*github.User).ID)
}
}
d.Set("reviewers", []interface{}{
Expand Down

0 comments on commit 05a8875

Please sign in to comment.