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

Add required_approving_review_count #89 (required go-github update) #160

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
4 changes: 2 additions & 2 deletions github/data_source_github_team.go
Original file line number Diff line number Diff line change
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
18 changes: 14 additions & 4 deletions github/resource_github_branch_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

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

func resourceGithubBranchProtection() *schema.Resource {
Expand Down Expand Up @@ -96,6 +97,13 @@ func resourceGithubBranchProtection() *schema.Resource {
Type: schema.TypeBool,
Optional: true,
},
"required_approving_review_count": {
Type: schema.TypeInt,
Optional: true,
Description: "Number of approvals required to merge a pull request",
Default: 1,
ValidateFunc: validation.IntBetween(1, 6),
},
},
},
},
Expand Down Expand Up @@ -338,10 +346,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 +436,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
7 changes: 6 additions & 1 deletion github/resource_github_branch_protection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func TestAccGithubBranchProtection_basic(t *testing.T) {
resource.TestCheckResourceAttr("github_branch_protection.master", "required_pull_request_reviews.0.dismissal_users.#", "1"),
resource.TestCheckResourceAttr("github_branch_protection.master", "required_pull_request_reviews.0.dismissal_teams.#", "0"),
resource.TestCheckResourceAttr("github_branch_protection.master", "required_pull_request_reviews.0.require_code_owner_reviews", "true"),
resource.TestCheckResourceAttr("github_branch_protection.master", "required_pull_request_reviews.0.required_approving_review_count", "1"),
resource.TestCheckResourceAttr("github_branch_protection.master", "restrictions.0.users.#", "1"),
resource.TestCheckResourceAttr("github_branch_protection.master", "restrictions.0.teams.#", "0"),
),
Expand Down Expand Up @@ -94,6 +95,7 @@ func TestAccGithubBranchProtection_teams(t *testing.T) {
resource.TestCheckResourceAttr("github_branch_protection.master", "required_pull_request_reviews.0.dismissal_users.#", "0"),
resource.TestCheckResourceAttr("github_branch_protection.master", "required_pull_request_reviews.0.dismissal_teams.#", "2"),
resource.TestCheckResourceAttr("github_branch_protection.master", "required_pull_request_reviews.0.require_code_owner_reviews", "false"),
resource.TestCheckResourceAttr("github_branch_protection.master", "required_pull_request_reviews.0.required_approving_review_count", "2"),
resource.TestCheckResourceAttr("github_branch_protection.master", "restrictions.0.users.#", "0"),
resource.TestCheckResourceAttr("github_branch_protection.master", "restrictions.0.teams.#", "2"),
),
Expand All @@ -108,6 +110,7 @@ func TestAccGithubBranchProtection_teams(t *testing.T) {
resource.TestCheckResourceAttr("github_branch_protection.master", "enforce_admins", "true"),
resource.TestCheckResourceAttr("github_branch_protection.master", "required_status_checks.#", "1"),
resource.TestCheckResourceAttr("github_branch_protection.master", "required_pull_request_reviews.#", "1"),
resource.TestCheckResourceAttr("github_branch_protection.master", "required_pull_request_reviews.0.required_approving_review_count", "1"),
resource.TestCheckResourceAttr("github_branch_protection.master", "restrictions.#", "1"),
),
},
Expand All @@ -127,6 +130,7 @@ func TestAccGithubBranchProtection_teams(t *testing.T) {
resource.TestCheckResourceAttr("github_branch_protection.master", "required_pull_request_reviews.0.dismissal_users.#", "0"),
resource.TestCheckResourceAttr("github_branch_protection.master", "required_pull_request_reviews.0.dismissal_teams.#", "2"),
resource.TestCheckResourceAttr("github_branch_protection.master", "required_pull_request_reviews.0.require_code_owner_reviews", "false"),
resource.TestCheckResourceAttr("github_branch_protection.master", "required_pull_request_reviews.0.required_approving_review_count", "2"),
resource.TestCheckResourceAttr("github_branch_protection.master", "restrictions.0.users.#", "0"),
resource.TestCheckResourceAttr("github_branch_protection.master", "restrictions.0.teams.#", "2"),
),
Expand Down Expand Up @@ -461,7 +465,8 @@ resource "github_branch_protection" "master" {

required_pull_request_reviews {
dismiss_stale_reviews = true
dismissal_teams = ["${github_team.first.slug}", "${github_team.second.slug}"]
dismissal_teams = ["${github_team.first.slug}", "${github_team.second.slug}"]
required_approving_review_count = 2
}

restrictions {
Expand Down
10 changes: 6 additions & 4 deletions github/resource_github_organization_project.go
Original file line number Diff line number Diff line change
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
11 changes: 7 additions & 4 deletions github/resource_github_repository_project.go
Original file line number Diff line number Diff line change
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 @@ -120,10 +121,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
12 changes: 6 additions & 6 deletions github/resource_github_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func resourceGithubTeamCreate(d *schema.ResourceData, meta interface{}) error {

orgName := meta.(*Organization).name
name := d.Get("name").(string)
newTeam := &github.NewTeam{
newTeam := github.NewTeam{
Name: name,
Description: github.String(d.Get("description").(string)),
Privacy: github.String(d.Get("privacy").(string)),
Expand All @@ -72,7 +72,7 @@ func resourceGithubTeamCreate(d *schema.ResourceData, meta interface{}) error {
ctx := context.Background()

log.Printf("[DEBUG] Creating team: %s (%s)", name, orgName)
githubTeam, _, err := client.Organizations.CreateTeam(ctx,
githubTeam, _, err := client.Teams.CreateTeam(ctx,
orgName, newTeam)
if err != nil {
return err
Expand Down Expand Up @@ -105,7 +105,7 @@ func resourceGithubTeamRead(d *schema.ResourceData, meta interface{}) error {
}

log.Printf("[DEBUG] Reading team: %s", d.Id())
team, resp, err := client.Organizations.GetTeam(ctx, id)
team, resp, err := client.Teams.GetTeam(ctx, id)
if err != nil {
if ghErr, ok := err.(*github.ErrorResponse); ok {
if ghErr.Response.StatusCode == http.StatusNotModified {
Expand Down Expand Up @@ -139,7 +139,7 @@ func resourceGithubTeamRead(d *schema.ResourceData, meta interface{}) error {
func resourceGithubTeamUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*Organization).client

editedTeam := &github.NewTeam{
editedTeam := github.NewTeam{
Name: d.Get("name").(string),
Description: github.String(d.Get("description").(string)),
Privacy: github.String(d.Get("privacy").(string)),
Expand All @@ -156,7 +156,7 @@ func resourceGithubTeamUpdate(d *schema.ResourceData, meta interface{}) error {
ctx := context.WithValue(context.Background(), ctxId, d.Id())

log.Printf("[DEBUG] Updating team: %s", d.Id())
team, _, err := client.Organizations.EditTeam(ctx, teamId, editedTeam)
team, _, err := client.Teams.EditTeam(ctx, teamId, editedTeam)
if err != nil {
return err
}
Expand Down Expand Up @@ -186,6 +186,6 @@ func resourceGithubTeamDelete(d *schema.ResourceData, meta interface{}) error {
ctx := context.WithValue(context.Background(), ctxId, d.Id())

log.Printf("[DEBUG] Deleting team: %s", d.Id())
_, err = client.Organizations.DeleteTeam(ctx, id)
_, err = client.Teams.DeleteTeam(ctx, id)
return err
}
8 changes: 4 additions & 4 deletions github/resource_github_team_membership.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ func resourceGithubTeamMembershipCreateOrUpdate(d *schema.ResourceData, meta int
role := d.Get("role").(string)

log.Printf("[DEBUG] Creating team membership: %s/%s (%s)", teamIdString, username, role)
_, _, err = client.Organizations.AddTeamMembership(ctx,
_, _, err = client.Teams.AddTeamMembership(ctx,
teamId,
username,
&github.OrganizationAddTeamMembershipOptions{
&github.TeamAddTeamMembershipOptions{
Role: role,
},
)
Expand Down Expand Up @@ -94,7 +94,7 @@ func resourceGithubTeamMembershipRead(d *schema.ResourceData, meta interface{})
}

log.Printf("[DEBUG] Reading team membership: %s/%s", teamIdString, username)
membership, resp, err := client.Organizations.GetTeamMembership(ctx,
membership, resp, err := client.Teams.GetTeamMembership(ctx,
teamId, username)
if err != nil {
if ghErr, ok := err.(*github.ErrorResponse); ok {
Expand Down Expand Up @@ -133,7 +133,7 @@ func resourceGithubTeamMembershipDelete(d *schema.ResourceData, meta interface{}
ctx := context.WithValue(context.Background(), ctxId, d.Id())

log.Printf("[DEBUG] Deleting team membership: %s/%s", teamIdString, username)
_, err = client.Organizations.RemoveTeamMembership(ctx, teamId, username)
_, err = client.Teams.RemoveTeamMembership(ctx, teamId, username)

return err
}
Expand Down
6 changes: 3 additions & 3 deletions github/resource_github_team_membership_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func testAccCheckGithubTeamMembershipDestroy(s *terraform.State) error {
return unconvertibleIdErr(teamIdString, err)
}

membership, resp, err := conn.Organizations.GetTeamMembership(context.TODO(),
membership, resp, err := conn.Teams.GetTeamMembership(context.TODO(),
teamId, username)
if err == nil {
if membership != nil {
Expand Down Expand Up @@ -114,7 +114,7 @@ func testAccCheckGithubTeamMembershipExists(n string, membership *github.Members
return unconvertibleIdErr(teamIdString, err)
}

teamMembership, _, err := conn.Organizations.GetTeamMembership(context.TODO(), teamId, username)
teamMembership, _, err := conn.Teams.GetTeamMembership(context.TODO(), teamId, username)

if err != nil {
return err
Expand Down Expand Up @@ -145,7 +145,7 @@ func testAccCheckGithubTeamMembershipRoleState(n, expected string, membership *g
return unconvertibleIdErr(teamIdString, err)
}

teamMembership, _, err := conn.Organizations.GetTeamMembership(context.TODO(),
teamMembership, _, err := conn.Teams.GetTeamMembership(context.TODO(),
teamId, username)
if err != nil {
return err
Expand Down
12 changes: 6 additions & 6 deletions github/resource_github_team_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ func resourceGithubTeamRepositoryCreate(d *schema.ResourceData, meta interface{}

log.Printf("[DEBUG] Creating team repository association: %s:%s (%s/%s)",
teamIdString, permission, orgName, repoName)
_, err = client.Organizations.AddTeamRepo(ctx,
_, err = client.Teams.AddTeamRepo(ctx,
teamId,
orgName,
repoName,
&github.OrganizationAddTeamRepoOptions{
&github.TeamAddTeamRepoOptions{
Permission: permission,
},
)
Expand Down Expand Up @@ -98,7 +98,7 @@ func resourceGithubTeamRepositoryRead(d *schema.ResourceData, meta interface{})

log.Printf("[DEBUG] Reading team repository association: %s (%s/%s)",
teamIdString, orgName, repoName)
repo, resp, repoErr := client.Organizations.IsTeamRepo(ctx,
repo, resp, repoErr := client.Teams.IsTeamRepo(ctx,
teamId, orgName, repoName)
if repoErr != nil {
if ghErr, ok := err.(*github.ErrorResponse); ok {
Expand Down Expand Up @@ -145,11 +145,11 @@ func resourceGithubTeamRepositoryUpdate(d *schema.ResourceData, meta interface{}
log.Printf("[DEBUG] Updating team repository association: %s:%s (%s/%s)",
teamIdString, permission, orgName, repoName)
// the go-github library's AddTeamRepo method uses the add/update endpoint from Github API
_, err = client.Organizations.AddTeamRepo(ctx,
_, err = client.Teams.AddTeamRepo(ctx,
teamId,
orgName,
repoName,
&github.OrganizationAddTeamRepoOptions{
&github.TeamAddTeamRepoOptions{
Permission: permission,
},
)
Expand Down Expand Up @@ -177,7 +177,7 @@ func resourceGithubTeamRepositoryDelete(d *schema.ResourceData, meta interface{}

log.Printf("[DEBUG] Deleting team repository association: %s (%s/%s)",
teamIdString, orgName, repoName)
_, err = client.Organizations.RemoveTeamRepo(ctx,
_, err = client.Teams.RemoveTeamRepo(ctx,
teamId, orgName, repoName)
return err
}
4 changes: 2 additions & 2 deletions github/resource_github_team_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func testAccCheckGithubTeamRepositoryExists(n string, repository *github.Reposit
return unconvertibleIdErr(teamIdString, err)
}

repo, _, err := conn.Organizations.IsTeamRepo(context.TODO(),
repo, _, err := conn.Teams.IsTeamRepo(context.TODO(),
teamId,
testAccProvider.Meta().(*Organization).name,
repoName)
Expand Down Expand Up @@ -155,7 +155,7 @@ func testAccCheckGithubTeamRepositoryDestroy(s *terraform.State) error {
return unconvertibleIdErr(teamIdString, err)
}

repo, resp, err := conn.Organizations.IsTeamRepo(context.TODO(),
repo, resp, err := conn.Teams.IsTeamRepo(context.TODO(),
teamId,
testAccProvider.Meta().(*Organization).name,
repoName)
Expand Down
4 changes: 2 additions & 2 deletions github/resource_github_team_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func testAccCheckGithubTeamExists(n string, team *github.Team) resource.TestChec
return unconvertibleIdErr(rs.Primary.ID, err)
}

githubTeam, _, err := conn.Organizations.GetTeam(context.TODO(), id)
githubTeam, _, err := conn.Teams.GetTeam(context.TODO(), id)
if err != nil {
return err
}
Expand Down Expand Up @@ -190,7 +190,7 @@ func testAccCheckGithubTeamDestroy(s *terraform.State) error {
return unconvertibleIdErr(rs.Primary.ID, err)
}

team, resp, err := conn.Organizations.GetTeam(context.TODO(), id)
team, resp, err := conn.Teams.GetTeam(context.TODO(), id)
if err == nil {
teamId := strconv.FormatInt(*team.ID, 10)
if team != nil && teamId == rs.Primary.ID {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions vendor/github.com/google/go-github/github/activity_star.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading