Skip to content
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
7 changes: 0 additions & 7 deletions github/data_source_github_organization_ip_allow_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,6 @@ func dataSourceGithubOrganizationIpAllowListRead(d *schema.ResourceData, meta an
client := meta.(*Owner).v4client
orgName := meta.(*Owner).name

type PageInfo struct {
StartCursor githubv4.String
EndCursor githubv4.String
HasNextPage githubv4.Boolean
HasPreviousPage githubv4.Boolean
}

type IpAllowListEntry struct {
ID githubv4.String
Name githubv4.String
Expand Down
9 changes: 3 additions & 6 deletions github/data_source_github_organization_ip_allow_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,18 @@ import (
func TestAccGithubOrganizationIpAllowListDataSource(t *testing.T) {
t.Run("queries without error", func(t *testing.T) {
config := `

data "github_organization_ip_allow_list" "all" {}
`

check := resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("data.github_organization_ip_allow_list.all", "ip_allow_list.#"),
)

resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessHasOrgs(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
Check: check,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("data.github_organization_ip_allow_list.all", "ip_allow_list.#"),
),
},
},
})
Expand Down
27 changes: 14 additions & 13 deletions github/data_source_github_organization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,21 @@ func TestAccGithubOrganizationDataSource(t *testing.T) {
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
repoName := fmt.Sprintf("%srepo-archived-%s", testResourcePrefix, randomID)

config := fmt.Sprintf(`
config := `
resource "github_repository" "archived" {
name = "%s"
archived = true
}
archived = %t
}

data "github_organization" "skip_archived" {
name = "%s"
name = "%[3]s"
ignore_archived_repos = true
depends_on = [
github_repository.archived,
]
}
data "github_organization" "all_repos" {
name = "%s"
name = "%[3]s"
ignore_archived_repos = false
depends_on = [
github_repository.archived,
Expand All @@ -86,20 +86,21 @@ func TestAccGithubOrganizationDataSource(t *testing.T) {
output "should_be_true" {
value = contains(data.github_organization.all_repos.repositories, github_repository.archived.full_name)
}
`, repoName, testAccConf.owner, testAccConf.owner)

check := resource.ComposeTestCheckFunc(
resource.TestCheckOutput("should_be_false", "false"),
resource.TestCheckOutput("should_be_true", "true"),
)
`

resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessHasOrgs(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
Check: check,
Config: fmt.Sprintf(config, repoName, false, testAccConf.owner), // We are removing the option to create archived repositories
},
{
Config: fmt.Sprintf(config, repoName, true, testAccConf.owner),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckOutput("should_be_false", "false"),
resource.TestCheckOutput("should_be_true", "true"),
),
},
},
})
Expand Down
5 changes: 3 additions & 2 deletions github/data_source_github_user_external_identity_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package github

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

func TestAccGithubUserExternalIdentity(t *testing.T) {
t.Run("queries without error", func(t *testing.T) {
config := `data "github_user_external_identity" "test" {}`
config := `data "github_user_external_identity" "test" { username = "%s" }`

check := resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("data.github_user_external_identity.test", "login"),
Expand All @@ -21,7 +22,7 @@ func TestAccGithubUserExternalIdentity(t *testing.T) {
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
Config: fmt.Sprintf(config, testAccConf.testExternalUser),
Check: check,
},
},
Expand Down
43 changes: 18 additions & 25 deletions github/resource_github_team_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ func resourceGithubTeamSettings() *schema.Resource {
"algorithm": {
Type: schema.TypeString,
Optional: true,
Description: "The algorithm to use when assigning pull requests to team members. Supported values are 'ROUND_ROBIN' and 'LOAD_BALANCE'.",
Default: "ROUND_ROBIN",
ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"ROUND_ROBIN", "LOAD_BALANCE"}, false)),
Description: "The algorithm to use when assigning pull requests to team members. Supported values are " + string(githubv4.TeamReviewAssignmentAlgorithmRoundRobin) + " and " + string(githubv4.TeamReviewAssignmentAlgorithmLoadBalance) + ".",
Default: string(githubv4.TeamReviewAssignmentAlgorithmRoundRobin),
ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{string(githubv4.TeamReviewAssignmentAlgorithmRoundRobin), string(githubv4.TeamReviewAssignmentAlgorithmLoadBalance)}, false)),
},
"member_count": {
Type: schema.TypeInt,
Expand Down Expand Up @@ -159,12 +159,13 @@ func resourceGithubTeamSettingsUpdate(d *schema.ResourceData, meta any) error {
} `graphql:"updateTeamReviewAssignment(input:$input)"`
}

return graphql.Mutate(ctx, &mutation, UpdateTeamReviewAssignmentInput{
TeamID: d.Id(),
ReviewRequestDelegation: true,
ReviewRequestDelegationAlgorithm: settings["algorithm"].(string),
ReviewRequestDelegationCount: settings["member_count"].(int),
ReviewRequestDelegationNotifyAll: settings["notify"].(bool),
teamReviewAlgorithm := githubv4.TeamReviewAssignmentAlgorithm(settings["algorithm"].(string))
return graphql.Mutate(ctx, &mutation, githubv4.UpdateTeamReviewAssignmentInput{
ID: d.Id(),
Enabled: githubv4.Boolean(true),
Algorithm: &teamReviewAlgorithm,
TeamMemberCount: githubv4.NewInt(githubv4.Int(settings["member_count"].(int))),
NotifyTeam: githubv4.NewBoolean(githubv4.Boolean(settings["notify"].(bool))),
}, nil)
}
}
Expand Down Expand Up @@ -233,22 +234,14 @@ func resolveTeamIDs(idOrSlug string, meta *Owner, ctx context.Context) (nodeId,
}
}

type UpdateTeamReviewAssignmentInput struct {
ClientMutationID string `json:"clientMutationId,omitempty"`
TeamID string `graphql:"id" json:"id"`
ReviewRequestDelegation bool `graphql:"enabled" json:"enabled"`
ReviewRequestDelegationAlgorithm string `graphql:"algorithm" json:"algorithm"`
ReviewRequestDelegationCount int `graphql:"teamMemberCount" json:"teamMemberCount"`
ReviewRequestDelegationNotifyAll bool `graphql:"notifyTeam" json:"notifyTeam"`
}

func defaultTeamReviewAssignmentSettings(id string) UpdateTeamReviewAssignmentInput {
return UpdateTeamReviewAssignmentInput{
TeamID: id,
ReviewRequestDelegation: false,
ReviewRequestDelegationAlgorithm: "ROUND_ROBIN",
ReviewRequestDelegationCount: 1,
ReviewRequestDelegationNotifyAll: true,
func defaultTeamReviewAssignmentSettings(id string) githubv4.UpdateTeamReviewAssignmentInput {
roundRobinAlgo := githubv4.TeamReviewAssignmentAlgorithmRoundRobin
return githubv4.UpdateTeamReviewAssignmentInput{
ID: id,
Enabled: githubv4.Boolean(false),
Algorithm: &roundRobinAlgo,
TeamMemberCount: githubv4.NewInt(githubv4.Int(1)),
NotifyTeam: githubv4.NewBoolean(true),
}
}

Expand Down
87 changes: 31 additions & 56 deletions github/resource_github_team_settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/shurcooL/githubv4"
)

func TestAccGithubTeamSettings(t *testing.T) {
Expand All @@ -25,23 +26,23 @@ func TestAccGithubTeamSettings(t *testing.T) {
}
`, teamName)

check := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("github_team_settings.test", "team_id"),
)

resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessHasOrgs(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
Check: check,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("github_team_settings.test", "team_id"),
),
},
{
Config: strings.Replace(config,
`github_team.test.id`,
`github_team.test.slug`, 1),
Check: check,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("github_team_settings.test", "team_id"),
),
},
},
})
Expand All @@ -50,7 +51,8 @@ func TestAccGithubTeamSettings(t *testing.T) {
t.Run("manages team code review settings", func(t *testing.T) {
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
teamName := fmt.Sprintf("%steam-settings-%s", testResourcePrefix, randomID)
config := fmt.Sprintf(`
testAlgorithm := githubv4.TeamReviewAssignmentAlgorithmRoundRobin
config := `
resource "github_team" "test" {
name = "%s"
description = "generated by terraform provider automated testing"
Expand All @@ -59,65 +61,40 @@ func TestAccGithubTeamSettings(t *testing.T) {
resource "github_team_settings" "test" {
team_id = "${github_team.test.id}"
review_request_delegation {
algorithm = "ROUND_ROBIN"
member_count = 1
notify = true
algorithm = "%s"
member_count = %d
notify = %t
}
}
`, teamName)

checks := map[string]resource.TestCheckFunc{
"round_robin": resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"github_team_settings.test", "review_request_delegation.0.algorithm",
"ROUND_ROBIN",
),
),
"load_balance": resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"github_team_settings.test", "review_request_delegation.0.algorithm",
"LOAD_BALANCE",
),
),
"review_count": resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"github_team_settings.test", "review_request_delegation.0.member_count",
"3",
),
),
"notify": resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"github_team_settings.test", "review_request_delegation.0.notify",
"false",
),
),
}
`

resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessHasOrgs(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
Check: checks["round_robin"],
Config: fmt.Sprintf(config, teamName, testAlgorithm, 1, true),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("github_team_settings.test", "review_request_delegation.0.algorithm", string(testAlgorithm)),
),
},
{
Config: strings.Replace(config,
`algorithm = "ROUND_ROBIN"`,
`algorithm = "LOAD_BALANCE"`, 1),
Check: checks["load_balance"],
Config: fmt.Sprintf(config, teamName, githubv4.TeamReviewAssignmentAlgorithmLoadBalance, 1, true),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("github_team_settings.test", "review_request_delegation.0.algorithm", string(githubv4.TeamReviewAssignmentAlgorithmLoadBalance)),
),
},
{
Config: strings.Replace(config,
`member_count = 1`,
`member_count = 3`, 1),
Check: checks["review_count"],
Config: fmt.Sprintf(config, teamName, testAlgorithm, 3, true),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("github_team_settings.test", "review_request_delegation.0.member_count", "3"),
),
},
{
Config: strings.Replace(config,
`notify = true`,
`notify = false`, 1),
Check: checks["notify"],
Config: fmt.Sprintf(config, teamName, testAlgorithm, 3, false),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("github_team_settings.test", "review_request_delegation.0.notify", "false"),
),
},
},
})
Expand All @@ -135,7 +112,7 @@ func TestAccGithubTeamSettings(t *testing.T) {
resource "github_team_settings" "test" {
team_id = "${github_team.test.id}"
review_request_delegation {
algorithm = "ROUND_ROBIN"
algorithm = "invalid"
member_count = 1
notify = true
}
Expand All @@ -147,9 +124,7 @@ func TestAccGithubTeamSettings(t *testing.T) {
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: strings.Replace(config,
`algorithm = "ROUND_ROBIN"`,
`algorithm = "invalid"`, 1),
Config: config,
ExpectError: regexp.MustCompile(`expected algorithm to be one of \[.*\]`),
},
},
Expand Down
6 changes: 4 additions & 2 deletions github/util_v4.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import (
)

type PageInfo struct {
EndCursor githubv4.String
HasNextPage bool
StartCursor githubv4.String
EndCursor githubv4.String
HasNextPage githubv4.Boolean
HasPreviousPage githubv4.Boolean
}

func expandNestedSet(m map[string]any, target string) []string {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/hashicorp/terraform-plugin-log v0.10.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.38.2
github.com/hashicorp/terraform-plugin-testing v1.14.0
github.com/shurcooL/githubv4 v0.0.0-20221126192849-0b5c4c7994eb
github.com/shurcooL/githubv4 v0.0.0-20260209031235-2402fdf4a9ed
golang.org/x/crypto v0.48.0
golang.org/x/oauth2 v0.35.0
)
Expand Down Expand Up @@ -51,7 +51,7 @@ require (
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/shurcooL/graphql v0.0.0-20220606043923-3cf50f8a0a29 // indirect
github.com/shurcooL/graphql v0.0.0-20240915155400-7ee5256398cf // indirect
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0t
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8=
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
github.com/shurcooL/githubv4 v0.0.0-20221126192849-0b5c4c7994eb h1:foJysa74+t41fG7adnt+TkfcNxQUWid8R/HlXe+Mmbw=
github.com/shurcooL/githubv4 v0.0.0-20221126192849-0b5c4c7994eb/go.mod h1:hAF0iLZy4td2EX+/8Tw+4nodhlMrwN3HupfaXj3zkGo=
github.com/shurcooL/graphql v0.0.0-20220606043923-3cf50f8a0a29 h1:B1PEwpArrNp4dkQrfxh/abbBAOZBVp0ds+fBEOUOqOc=
github.com/shurcooL/graphql v0.0.0-20220606043923-3cf50f8a0a29/go.mod h1:AuYgA5Kyo4c7HfUmvRGs/6rGlMMV/6B1bVnB9JxJEEg=
github.com/shurcooL/githubv4 v0.0.0-20260209031235-2402fdf4a9ed h1:KT7hI8vYXgU0s2qaMkrfq9tCA1w/iEPgfredVP+4Tzw=
github.com/shurcooL/githubv4 v0.0.0-20260209031235-2402fdf4a9ed/go.mod h1:zqMwyHmnN/eDOZOdiTohqIUKUrTFX62PNlu7IJdu0q8=
github.com/shurcooL/graphql v0.0.0-20240915155400-7ee5256398cf h1:o1uxfymjZ7jZ4MsgCErcwWGtVKSiNAXtS59Lhs6uI/g=
github.com/shurcooL/graphql v0.0.0-20240915155400-7ee5256398cf/go.mod h1:9dIRpgIY7hVhoqfe0/FcYp0bpInZaT7dc3BYOprrIUE=
github.com/skeema/knownhosts v1.3.1 h1:X2osQ+RAjK76shCbvhHHHVl3ZlgDm8apHEHFqRjnBY8=
github.com/skeema/knownhosts v1.3.1/go.mod h1:r7KTdC8l4uxWRyK2TpQZ/1o5HaSzh06ePQNxPwTcfiY=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
Loading