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

Include required review count #211

Closed
Closed
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
2 changes: 1 addition & 1 deletion github/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/http"
"net/url"

"github.com/google/go-github/github"
"github.com/google/go-github/v24/github"
"github.com/hashicorp/terraform/helper/logging"
"golang.org/x/oauth2"
)
Expand Down
2 changes: 1 addition & 1 deletion github/data_source_github_repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"log"

"github.com/google/go-github/github"
"github.com/google/go-github/v24/github"
"github.com/hashicorp/terraform/helper/schema"
)

Expand Down
6 changes: 3 additions & 3 deletions github/data_source_github_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"log"
"strconv"

"github.com/google/go-github/github"
"github.com/google/go-github/v24/github"
"github.com/hashicorp/terraform/helper/schema"
)

Expand Down Expand Up @@ -56,7 +56,7 @@ func dataSourceGithubTeamRead(d *schema.ResourceData, meta interface{}) error {
return err
}

member, _, err := client.Organizations.ListTeamMembers(ctx, team.GetID(), nil)
member, _, err := client.Teams.ListTeamMembers(ctx, team.GetID(), nil)
if err != nil {
return err
}
Expand All @@ -79,7 +79,7 @@ func dataSourceGithubTeamRead(d *schema.ResourceData, meta interface{}) error {
func getGithubTeamBySlug(client *github.Client, org string, slug string) (team *github.Team, err error) {
opt := &github.ListOptions{PerPage: 10}
for {
teams, resp, err := client.Organizations.ListTeams(context.TODO(), org, opt)
teams, resp, err := client.Teams.ListTeams(context.TODO(), org, opt)
if err != nil {
return team, err
}
Expand Down
19 changes: 14 additions & 5 deletions github/resource_github_branch_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
"log"
"net/http"

"github.com/google/go-github/github"
"github.com/google/go-github/v24/github"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
)

func resourceGithubBranchProtection() *schema.Resource {
Expand Down Expand Up @@ -96,6 +97,12 @@ func resourceGithubBranchProtection() *schema.Resource {
Type: schema.TypeBool,
Optional: true,
},
"required_approving_review_count": {
Type: schema.TypeInt,
Optional: true,
Default: 1,
ValidateFunc: validation.IntBetween(1, 6),
},
},
},
},
Expand Down Expand Up @@ -338,10 +345,11 @@ func flattenAndSetRequiredPullRequestReviews(d *schema.ResourceData, protection

return d.Set("required_pull_request_reviews", []interface{}{
map[string]interface{}{
"dismiss_stale_reviews": rprr.DismissStaleReviews,
"dismissal_users": schema.NewSet(schema.HashString, users),
"dismissal_teams": schema.NewSet(schema.HashString, teams),
"require_code_owner_reviews": rprr.RequireCodeOwnerReviews,
"dismiss_stale_reviews": rprr.DismissStaleReviews,
"dismissal_users": schema.NewSet(schema.HashString, users),
"dismissal_teams": schema.NewSet(schema.HashString, teams),
"require_code_owner_reviews": rprr.RequireCodeOwnerReviews,
"required_approving_review_count": rprr.RequiredApprovingReviewCount,
},
})
}
Expand Down Expand Up @@ -427,6 +435,7 @@ func expandRequiredPullRequestReviews(d *schema.ResourceData) (*github.PullReque
rprr.DismissalRestrictionsRequest = drr
rprr.DismissStaleReviews = m["dismiss_stale_reviews"].(bool)
rprr.RequireCodeOwnerReviews = m["require_code_owner_reviews"].(bool)
rprr.RequiredApprovingReviewCount = m["required_approving_review_count"].(int)
}

return rprr, nil
Expand Down
2 changes: 1 addition & 1 deletion github/resource_github_branch_protection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"sort"
"testing"

"github.com/google/go-github/github"
"github.com/google/go-github/v24/github"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
Expand Down
2 changes: 1 addition & 1 deletion github/resource_github_issue_label.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"net/http"

"github.com/google/go-github/github"
"github.com/google/go-github/v24/github"
"github.com/hashicorp/terraform/helper/schema"
)

Expand Down
2 changes: 1 addition & 1 deletion github/resource_github_issue_label_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"testing"

"github.com/google/go-github/github"
"github.com/google/go-github/v24/github"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
Expand Down
2 changes: 1 addition & 1 deletion github/resource_github_membership.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"net/http"

"github.com/google/go-github/github"
"github.com/google/go-github/v24/github"
"github.com/hashicorp/terraform/helper/schema"
)

Expand Down
2 changes: 1 addition & 1 deletion github/resource_github_membership_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"testing"

"github.com/google/go-github/github"
"github.com/google/go-github/v24/github"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
Expand Down
12 changes: 7 additions & 5 deletions github/resource_github_organization_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net/http"
"strconv"

"github.com/google/go-github/github"
"github.com/google/go-github/v24/github"
"github.com/hashicorp/terraform/helper/schema"
)

Expand Down Expand Up @@ -46,14 +46,15 @@ func resourceGithubOrganizationProjectCreate(d *schema.ResourceData, meta interf
client := meta.(*Organization).client
orgName := meta.(*Organization).name
name := d.Get("name").(string)
body := d.Get("body").(string)
ctx := context.Background()

log.Printf("[DEBUG] Creating organization project: %s (%s)", name, orgName)
project, _, err := client.Organizations.CreateProject(ctx,
orgName,
&github.ProjectOptions{
Name: name,
Body: d.Get("body").(string),
Name: &name,
Body: &body,
},
)
if err != nil {
Expand Down Expand Up @@ -108,9 +109,10 @@ func resourceGithubOrganizationProjectUpdate(d *schema.ResourceData, meta interf

orgName := meta.(*Organization).name
name := d.Get("name").(string)
body := d.Get("body").(string)
options := github.ProjectOptions{
Name: name,
Body: d.Get("body").(string),
Name: &name,
Body: &body,
}

projectID, err := strconv.ParseInt(d.Id(), 10, 64)
Expand Down
2 changes: 1 addition & 1 deletion github/resource_github_organization_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"
"testing"

"github.com/google/go-github/github"
"github.com/google/go-github/v24/github"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
Expand Down
8 changes: 3 additions & 5 deletions github/resource_github_organization_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net/http"
"strconv"

"github.com/google/go-github/github"
"github.com/google/go-github/v24/github"
"github.com/hashicorp/terraform/helper/schema"
)

Expand Down Expand Up @@ -68,7 +68,6 @@ func resourceGithubOrganizationWebhookObject(d *schema.ResourceData) *github.Hoo
}

hook := &github.Hook{
Name: github.String(d.Get("name").(string)),
URL: github.String(d.Get("url").(string)),
Events: events,
Active: github.Bool(d.Get("active").(bool)),
Expand All @@ -89,8 +88,8 @@ func resourceGithubOrganizationWebhookCreate(d *schema.ResourceData, meta interf
webhookObj := resourceGithubOrganizationWebhookObject(d)
ctx := context.Background()

log.Printf("[DEBUG] Creating organization webhook: %s (%s)",
webhookObj.GetName(), orgName)
log.Printf("[DEBUG] Creating organization webhook: %d (%s)",
webhookObj.GetID(), orgName)
hook, _, err := client.Organizations.CreateHook(ctx, orgName, webhookObj)

if err != nil {
Expand Down Expand Up @@ -132,7 +131,6 @@ func resourceGithubOrganizationWebhookRead(d *schema.ResourceData, meta interfac
}

d.Set("etag", resp.Header.Get("ETag"))
d.Set("name", hook.Name)
d.Set("url", hook.URL)
d.Set("active", hook.Active)
d.Set("events", hook.Events)
Expand Down
5 changes: 1 addition & 4 deletions github/resource_github_organization_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"testing"

"github.com/google/go-github/github"
"github.com/google/go-github/v24/github"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
Expand Down Expand Up @@ -122,9 +122,6 @@ type testAccGithubOrganizationWebhookExpectedAttributes struct {
func testAccCheckGithubOrganizationWebhookAttributes(hook *github.Hook, want *testAccGithubOrganizationWebhookExpectedAttributes) resource.TestCheckFunc {
return func(s *terraform.State) error {

if *hook.Name != want.Name {
return fmt.Errorf("got hook %q; want %q", *hook.Name, want.Name)
}
if *hook.Active != want.Active {
return fmt.Errorf("got hook %t; want %t", *hook.Active, want.Active)
}
Expand Down
2 changes: 1 addition & 1 deletion github/resource_github_project_column.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strconv"
"strings"

"github.com/google/go-github/github"
"github.com/google/go-github/v24/github"
"github.com/hashicorp/terraform/helper/schema"
)

Expand Down
2 changes: 1 addition & 1 deletion github/resource_github_project_column_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strconv"
"testing"

"github.com/google/go-github/github"
"github.com/google/go-github/v24/github"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
Expand Down
2 changes: 1 addition & 1 deletion github/resource_github_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"log"
"net/http"

"github.com/google/go-github/github"
"github.com/google/go-github/v24/github"
"github.com/hashicorp/terraform/helper/schema"
)

Expand Down
2 changes: 1 addition & 1 deletion github/resource_github_repository_collaborator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"log"

"github.com/google/go-github/github"
"github.com/google/go-github/v24/github"
"github.com/hashicorp/terraform/helper/schema"
)

Expand Down
2 changes: 1 addition & 1 deletion github/resource_github_repository_deploy_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strconv"
"strings"

"github.com/google/go-github/github"
"github.com/google/go-github/v24/github"
"github.com/hashicorp/terraform/helper/schema"
)

Expand Down
14 changes: 9 additions & 5 deletions github/resource_github_repository_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strconv"
"strings"

"github.com/google/go-github/github"
"github.com/google/go-github/v24/github"
"github.com/hashicorp/terraform/helper/schema"
)

Expand Down Expand Up @@ -62,9 +62,10 @@ func resourceGithubRepositoryProjectCreate(d *schema.ResourceData, meta interfac
orgName := meta.(*Organization).name
repoName := d.Get("repository").(string)
name := d.Get("name").(string)
body := d.Get("body").(string)
options := github.ProjectOptions{
Name: name,
Body: d.Get("body").(string),
Name: &name,
Body: &body,
}
ctx := context.Background()

Expand Down Expand Up @@ -121,9 +122,12 @@ func resourceGithubRepositoryProjectRead(d *schema.ResourceData, meta interface{
func resourceGithubRepositoryProjectUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*Organization).client

name := d.Get("name").(string)
body := d.Get("body").(string)

options := github.ProjectOptions{
Name: d.Get("name").(string),
Body: d.Get("body").(string),
Name: &name,
Body: &body,
}

projectID, err := strconv.ParseInt(d.Id(), 10, 64)
Expand Down
2 changes: 1 addition & 1 deletion github/resource_github_repository_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"testing"

"github.com/google/go-github/github"
"github.com/google/go-github/v24/github"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
Expand Down
2 changes: 1 addition & 1 deletion github/resource_github_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"
"testing"

"github.com/google/go-github/github"
"github.com/google/go-github/v24/github"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
Expand Down
7 changes: 2 additions & 5 deletions github/resource_github_repository_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strconv"
"strings"

"github.com/google/go-github/github"
"github.com/google/go-github/v24/github"
"github.com/hashicorp/terraform/helper/schema"
)

Expand Down Expand Up @@ -76,10 +76,8 @@ func resourceGithubRepositoryWebhookObject(d *schema.ResourceData) *github.Hook
for _, v := range eventSet.List() {
events = append(events, v.(string))
}
name := d.Get("name").(string)

hook := &github.Hook{
Name: &name,
URL: &url,
Events: events,
Active: &active,
Expand All @@ -101,7 +99,7 @@ func resourceGithubRepositoryWebhookCreate(d *schema.ResourceData, meta interfac
hk := resourceGithubRepositoryWebhookObject(d)
ctx := context.Background()

log.Printf("[DEBUG] Creating repository webhook: %s (%s/%s)", hk.GetName(), orgName, repoName)
log.Printf("[DEBUG] Creating repository webhook: %d (%s/%s)", hk.GetID(), orgName, repoName)
hook, _, err := client.Repositories.CreateHook(ctx, orgName, repoName, hk)
if err != nil {
return err
Expand Down Expand Up @@ -141,7 +139,6 @@ func resourceGithubRepositoryWebhookRead(d *schema.ResourceData, meta interface{
}
return err
}
d.Set("name", hook.Name)
d.Set("url", hook.URL)
d.Set("active", hook.Active)
d.Set("events", hook.Events)
Expand Down
5 changes: 1 addition & 4 deletions github/resource_github_repository_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"testing"

"github.com/google/go-github/github"
"github.com/google/go-github/v24/github"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
Expand Down Expand Up @@ -167,9 +167,6 @@ type testAccGithubRepositoryWebhookExpectedAttributes struct {
func testAccCheckGithubRepositoryWebhookAttributes(hook *github.Hook, want *testAccGithubRepositoryWebhookExpectedAttributes) resource.TestCheckFunc {
return func(s *terraform.State) error {

if *hook.Name != want.Name {
return fmt.Errorf("got hook %q; want %q", *hook.Name, want.Name)
}
if *hook.Active != want.Active {
return fmt.Errorf("got hook %t; want %t", *hook.Active, want.Active)
}
Expand Down
Loading