Skip to content

Commit b5198aa

Browse files
authored
[MAINT] Upgrade v4 client package (#3194)
* Upgrade shurcool/githubv4 package to latest Signed-off-by: Timo Sand <[email protected]> * Fix v4client tests Signed-off-by: Timo Sand <[email protected]> * Replace custom `UpdateTeamReviewAssignmentInput` with `githubv4.UpdateTeamReviewAssignmentInput` Signed-off-by: Timo Sand <[email protected]> * Replace hard-coded `TeamReviewAssignmentAlgorithm` mentions Signed-off-by: Timo Sand <[email protected]> * Remove duplicate `PageInfo` struct Signed-off-by: Timo Sand <[email protected]> * Minor test cleanup Signed-off-by: Timo Sand <[email protected]> --------- Signed-off-by: Timo Sand <[email protected]>
1 parent 09a39fb commit b5198aa

26 files changed

Lines changed: 2583 additions & 708 deletions

github/data_source_github_organization_ip_allow_list.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,6 @@ func dataSourceGithubOrganizationIpAllowListRead(d *schema.ResourceData, meta an
5858
client := meta.(*Owner).v4client
5959
orgName := meta.(*Owner).name
6060

61-
type PageInfo struct {
62-
StartCursor githubv4.String
63-
EndCursor githubv4.String
64-
HasNextPage githubv4.Boolean
65-
HasPreviousPage githubv4.Boolean
66-
}
67-
6861
type IpAllowListEntry struct {
6962
ID githubv4.String
7063
Name githubv4.String

github/data_source_github_organization_ip_allow_list_test.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,18 @@ import (
99
func TestAccGithubOrganizationIpAllowListDataSource(t *testing.T) {
1010
t.Run("queries without error", func(t *testing.T) {
1111
config := `
12-
1312
data "github_organization_ip_allow_list" "all" {}
1413
`
1514

16-
check := resource.ComposeAggregateTestCheckFunc(
17-
resource.TestCheckResourceAttrSet("data.github_organization_ip_allow_list.all", "ip_allow_list.#"),
18-
)
19-
2015
resource.Test(t, resource.TestCase{
2116
PreCheck: func() { skipUnlessHasOrgs(t) },
2217
ProviderFactories: providerFactories,
2318
Steps: []resource.TestStep{
2419
{
2520
Config: config,
26-
Check: check,
21+
Check: resource.ComposeAggregateTestCheckFunc(
22+
resource.TestCheckResourceAttrSet("data.github_organization_ip_allow_list.all", "ip_allow_list.#"),
23+
),
2724
},
2825
},
2926
})

github/data_source_github_organization_test.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,21 @@ func TestAccGithubOrganizationDataSource(t *testing.T) {
5959
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
6060
repoName := fmt.Sprintf("%srepo-archived-%s", testResourcePrefix, randomID)
6161

62-
config := fmt.Sprintf(`
62+
config := `
6363
resource "github_repository" "archived" {
6464
name = "%s"
65-
archived = true
66-
}
65+
archived = %t
66+
}
6767
6868
data "github_organization" "skip_archived" {
69-
name = "%s"
69+
name = "%[3]s"
7070
ignore_archived_repos = true
7171
depends_on = [
7272
github_repository.archived,
7373
]
7474
}
7575
data "github_organization" "all_repos" {
76-
name = "%s"
76+
name = "%[3]s"
7777
ignore_archived_repos = false
7878
depends_on = [
7979
github_repository.archived,
@@ -86,20 +86,21 @@ func TestAccGithubOrganizationDataSource(t *testing.T) {
8686
output "should_be_true" {
8787
value = contains(data.github_organization.all_repos.repositories, github_repository.archived.full_name)
8888
}
89-
`, repoName, testAccConf.owner, testAccConf.owner)
90-
91-
check := resource.ComposeTestCheckFunc(
92-
resource.TestCheckOutput("should_be_false", "false"),
93-
resource.TestCheckOutput("should_be_true", "true"),
94-
)
89+
`
9590

9691
resource.Test(t, resource.TestCase{
9792
PreCheck: func() { skipUnlessHasOrgs(t) },
9893
ProviderFactories: providerFactories,
9994
Steps: []resource.TestStep{
10095
{
101-
Config: config,
102-
Check: check,
96+
Config: fmt.Sprintf(config, repoName, false, testAccConf.owner), // We are removing the option to create archived repositories
97+
},
98+
{
99+
Config: fmt.Sprintf(config, repoName, true, testAccConf.owner),
100+
Check: resource.ComposeTestCheckFunc(
101+
resource.TestCheckOutput("should_be_false", "false"),
102+
resource.TestCheckOutput("should_be_true", "true"),
103+
),
103104
},
104105
},
105106
})

github/data_source_github_user_external_identity_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package github
22

33
import (
4+
"fmt"
45
"testing"
56

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

910
func TestAccGithubUserExternalIdentity(t *testing.T) {
1011
t.Run("queries without error", func(t *testing.T) {
11-
config := `data "github_user_external_identity" "test" {}`
12+
config := `data "github_user_external_identity" "test" { username = "%s" }`
1213

1314
check := resource.ComposeAggregateTestCheckFunc(
1415
resource.TestCheckResourceAttrSet("data.github_user_external_identity.test", "login"),
@@ -21,7 +22,7 @@ func TestAccGithubUserExternalIdentity(t *testing.T) {
2122
ProviderFactories: providerFactories,
2223
Steps: []resource.TestStep{
2324
{
24-
Config: config,
25+
Config: fmt.Sprintf(config, testAccConf.testExternalUser),
2526
Check: check,
2627
},
2728
},

github/resource_github_team_settings.go

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ func resourceGithubTeamSettings() *schema.Resource {
4646
"algorithm": {
4747
Type: schema.TypeString,
4848
Optional: true,
49-
Description: "The algorithm to use when assigning pull requests to team members. Supported values are 'ROUND_ROBIN' and 'LOAD_BALANCE'.",
50-
Default: "ROUND_ROBIN",
51-
ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"ROUND_ROBIN", "LOAD_BALANCE"}, false)),
49+
Description: "The algorithm to use when assigning pull requests to team members. Supported values are " + string(githubv4.TeamReviewAssignmentAlgorithmRoundRobin) + " and " + string(githubv4.TeamReviewAssignmentAlgorithmLoadBalance) + ".",
50+
Default: string(githubv4.TeamReviewAssignmentAlgorithmRoundRobin),
51+
ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{string(githubv4.TeamReviewAssignmentAlgorithmRoundRobin), string(githubv4.TeamReviewAssignmentAlgorithmLoadBalance)}, false)),
5252
},
5353
"member_count": {
5454
Type: schema.TypeInt,
@@ -159,12 +159,13 @@ func resourceGithubTeamSettingsUpdate(d *schema.ResourceData, meta any) error {
159159
} `graphql:"updateTeamReviewAssignment(input:$input)"`
160160
}
161161

162-
return graphql.Mutate(ctx, &mutation, UpdateTeamReviewAssignmentInput{
163-
TeamID: d.Id(),
164-
ReviewRequestDelegation: true,
165-
ReviewRequestDelegationAlgorithm: settings["algorithm"].(string),
166-
ReviewRequestDelegationCount: settings["member_count"].(int),
167-
ReviewRequestDelegationNotifyAll: settings["notify"].(bool),
162+
teamReviewAlgorithm := githubv4.TeamReviewAssignmentAlgorithm(settings["algorithm"].(string))
163+
return graphql.Mutate(ctx, &mutation, githubv4.UpdateTeamReviewAssignmentInput{
164+
ID: d.Id(),
165+
Enabled: githubv4.Boolean(true),
166+
Algorithm: &teamReviewAlgorithm,
167+
TeamMemberCount: githubv4.NewInt(githubv4.Int(settings["member_count"].(int))),
168+
NotifyTeam: githubv4.NewBoolean(githubv4.Boolean(settings["notify"].(bool))),
168169
}, nil)
169170
}
170171
}
@@ -233,22 +234,14 @@ func resolveTeamIDs(idOrSlug string, meta *Owner, ctx context.Context) (nodeId,
233234
}
234235
}
235236

236-
type UpdateTeamReviewAssignmentInput struct {
237-
ClientMutationID string `json:"clientMutationId,omitempty"`
238-
TeamID string `graphql:"id" json:"id"`
239-
ReviewRequestDelegation bool `graphql:"enabled" json:"enabled"`
240-
ReviewRequestDelegationAlgorithm string `graphql:"algorithm" json:"algorithm"`
241-
ReviewRequestDelegationCount int `graphql:"teamMemberCount" json:"teamMemberCount"`
242-
ReviewRequestDelegationNotifyAll bool `graphql:"notifyTeam" json:"notifyTeam"`
243-
}
244-
245-
func defaultTeamReviewAssignmentSettings(id string) UpdateTeamReviewAssignmentInput {
246-
return UpdateTeamReviewAssignmentInput{
247-
TeamID: id,
248-
ReviewRequestDelegation: false,
249-
ReviewRequestDelegationAlgorithm: "ROUND_ROBIN",
250-
ReviewRequestDelegationCount: 1,
251-
ReviewRequestDelegationNotifyAll: true,
237+
func defaultTeamReviewAssignmentSettings(id string) githubv4.UpdateTeamReviewAssignmentInput {
238+
roundRobinAlgo := githubv4.TeamReviewAssignmentAlgorithmRoundRobin
239+
return githubv4.UpdateTeamReviewAssignmentInput{
240+
ID: id,
241+
Enabled: githubv4.Boolean(false),
242+
Algorithm: &roundRobinAlgo,
243+
TeamMemberCount: githubv4.NewInt(githubv4.Int(1)),
244+
NotifyTeam: githubv4.NewBoolean(true),
252245
}
253246
}
254247

github/resource_github_team_settings_test.go

Lines changed: 31 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
1010
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
11+
"github.com/shurcooL/githubv4"
1112
)
1213

1314
func TestAccGithubTeamSettings(t *testing.T) {
@@ -25,23 +26,23 @@ func TestAccGithubTeamSettings(t *testing.T) {
2526
}
2627
`, teamName)
2728

28-
check := resource.ComposeTestCheckFunc(
29-
resource.TestCheckResourceAttrSet("github_team_settings.test", "team_id"),
30-
)
31-
3229
resource.Test(t, resource.TestCase{
3330
PreCheck: func() { skipUnlessHasOrgs(t) },
3431
ProviderFactories: providerFactories,
3532
Steps: []resource.TestStep{
3633
{
3734
Config: config,
38-
Check: check,
35+
Check: resource.ComposeTestCheckFunc(
36+
resource.TestCheckResourceAttrSet("github_team_settings.test", "team_id"),
37+
),
3938
},
4039
{
4140
Config: strings.Replace(config,
4241
`github_team.test.id`,
4342
`github_team.test.slug`, 1),
44-
Check: check,
43+
Check: resource.ComposeTestCheckFunc(
44+
resource.TestCheckResourceAttrSet("github_team_settings.test", "team_id"),
45+
),
4546
},
4647
},
4748
})
@@ -50,7 +51,8 @@ func TestAccGithubTeamSettings(t *testing.T) {
5051
t.Run("manages team code review settings", func(t *testing.T) {
5152
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
5253
teamName := fmt.Sprintf("%steam-settings-%s", testResourcePrefix, randomID)
53-
config := fmt.Sprintf(`
54+
testAlgorithm := githubv4.TeamReviewAssignmentAlgorithmRoundRobin
55+
config := `
5456
resource "github_team" "test" {
5557
name = "%s"
5658
description = "generated by terraform provider automated testing"
@@ -59,65 +61,40 @@ func TestAccGithubTeamSettings(t *testing.T) {
5961
resource "github_team_settings" "test" {
6062
team_id = "${github_team.test.id}"
6163
review_request_delegation {
62-
algorithm = "ROUND_ROBIN"
63-
member_count = 1
64-
notify = true
64+
algorithm = "%s"
65+
member_count = %d
66+
notify = %t
6567
}
6668
}
67-
`, teamName)
68-
69-
checks := map[string]resource.TestCheckFunc{
70-
"round_robin": resource.ComposeTestCheckFunc(
71-
resource.TestCheckResourceAttr(
72-
"github_team_settings.test", "review_request_delegation.0.algorithm",
73-
"ROUND_ROBIN",
74-
),
75-
),
76-
"load_balance": resource.ComposeTestCheckFunc(
77-
resource.TestCheckResourceAttr(
78-
"github_team_settings.test", "review_request_delegation.0.algorithm",
79-
"LOAD_BALANCE",
80-
),
81-
),
82-
"review_count": resource.ComposeTestCheckFunc(
83-
resource.TestCheckResourceAttr(
84-
"github_team_settings.test", "review_request_delegation.0.member_count",
85-
"3",
86-
),
87-
),
88-
"notify": resource.ComposeTestCheckFunc(
89-
resource.TestCheckResourceAttr(
90-
"github_team_settings.test", "review_request_delegation.0.notify",
91-
"false",
92-
),
93-
),
94-
}
69+
`
9570

9671
resource.Test(t, resource.TestCase{
9772
PreCheck: func() { skipUnlessHasOrgs(t) },
9873
ProviderFactories: providerFactories,
9974
Steps: []resource.TestStep{
10075
{
101-
Config: config,
102-
Check: checks["round_robin"],
76+
Config: fmt.Sprintf(config, teamName, testAlgorithm, 1, true),
77+
Check: resource.ComposeTestCheckFunc(
78+
resource.TestCheckResourceAttr("github_team_settings.test", "review_request_delegation.0.algorithm", string(testAlgorithm)),
79+
),
10380
},
10481
{
105-
Config: strings.Replace(config,
106-
`algorithm = "ROUND_ROBIN"`,
107-
`algorithm = "LOAD_BALANCE"`, 1),
108-
Check: checks["load_balance"],
82+
Config: fmt.Sprintf(config, teamName, githubv4.TeamReviewAssignmentAlgorithmLoadBalance, 1, true),
83+
Check: resource.ComposeTestCheckFunc(
84+
resource.TestCheckResourceAttr("github_team_settings.test", "review_request_delegation.0.algorithm", string(githubv4.TeamReviewAssignmentAlgorithmLoadBalance)),
85+
),
10986
},
11087
{
111-
Config: strings.Replace(config,
112-
`member_count = 1`,
113-
`member_count = 3`, 1),
114-
Check: checks["review_count"],
88+
Config: fmt.Sprintf(config, teamName, testAlgorithm, 3, true),
89+
Check: resource.ComposeTestCheckFunc(
90+
resource.TestCheckResourceAttr("github_team_settings.test", "review_request_delegation.0.member_count", "3"),
91+
),
11592
},
11693
{
117-
Config: strings.Replace(config,
118-
`notify = true`,
119-
`notify = false`, 1),
120-
Check: checks["notify"],
94+
Config: fmt.Sprintf(config, teamName, testAlgorithm, 3, false),
95+
Check: resource.ComposeTestCheckFunc(
96+
resource.TestCheckResourceAttr("github_team_settings.test", "review_request_delegation.0.notify", "false"),
97+
),
12198
},
12299
},
123100
})
@@ -135,7 +112,7 @@ func TestAccGithubTeamSettings(t *testing.T) {
135112
resource "github_team_settings" "test" {
136113
team_id = "${github_team.test.id}"
137114
review_request_delegation {
138-
algorithm = "ROUND_ROBIN"
115+
algorithm = "invalid"
139116
member_count = 1
140117
notify = true
141118
}
@@ -147,9 +124,7 @@ func TestAccGithubTeamSettings(t *testing.T) {
147124
ProviderFactories: providerFactories,
148125
Steps: []resource.TestStep{
149126
{
150-
Config: strings.Replace(config,
151-
`algorithm = "ROUND_ROBIN"`,
152-
`algorithm = "invalid"`, 1),
127+
Config: config,
153128
ExpectError: regexp.MustCompile(`expected algorithm to be one of \[.*\]`),
154129
},
155130
},

github/util_v4.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import (
66
)
77

88
type PageInfo struct {
9-
EndCursor githubv4.String
10-
HasNextPage bool
9+
StartCursor githubv4.String
10+
EndCursor githubv4.String
11+
HasNextPage githubv4.Boolean
12+
HasPreviousPage githubv4.Boolean
1113
}
1214

1315
func expandNestedSet(m map[string]any, target string) []string {

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/hashicorp/terraform-plugin-log v0.10.0
1111
github.com/hashicorp/terraform-plugin-sdk/v2 v2.38.2
1212
github.com/hashicorp/terraform-plugin-testing v1.14.0
13-
github.com/shurcooL/githubv4 v0.0.0-20221126192849-0b5c4c7994eb
13+
github.com/shurcooL/githubv4 v0.0.0-20260209031235-2402fdf4a9ed
1414
golang.org/x/crypto v0.48.0
1515
golang.org/x/oauth2 v0.35.0
1616
)
@@ -51,7 +51,7 @@ require (
5151
github.com/mitchellh/mapstructure v1.5.0 // indirect
5252
github.com/mitchellh/reflectwalk v1.0.2 // indirect
5353
github.com/oklog/run v1.1.0 // indirect
54-
github.com/shurcooL/graphql v0.0.0-20220606043923-3cf50f8a0a29 // indirect
54+
github.com/shurcooL/graphql v0.0.0-20240915155400-7ee5256398cf // indirect
5555
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
5656
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
5757
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,10 @@ github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0t
146146
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
147147
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8=
148148
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
149-
github.com/shurcooL/githubv4 v0.0.0-20221126192849-0b5c4c7994eb h1:foJysa74+t41fG7adnt+TkfcNxQUWid8R/HlXe+Mmbw=
150-
github.com/shurcooL/githubv4 v0.0.0-20221126192849-0b5c4c7994eb/go.mod h1:hAF0iLZy4td2EX+/8Tw+4nodhlMrwN3HupfaXj3zkGo=
151-
github.com/shurcooL/graphql v0.0.0-20220606043923-3cf50f8a0a29 h1:B1PEwpArrNp4dkQrfxh/abbBAOZBVp0ds+fBEOUOqOc=
152-
github.com/shurcooL/graphql v0.0.0-20220606043923-3cf50f8a0a29/go.mod h1:AuYgA5Kyo4c7HfUmvRGs/6rGlMMV/6B1bVnB9JxJEEg=
149+
github.com/shurcooL/githubv4 v0.0.0-20260209031235-2402fdf4a9ed h1:KT7hI8vYXgU0s2qaMkrfq9tCA1w/iEPgfredVP+4Tzw=
150+
github.com/shurcooL/githubv4 v0.0.0-20260209031235-2402fdf4a9ed/go.mod h1:zqMwyHmnN/eDOZOdiTohqIUKUrTFX62PNlu7IJdu0q8=
151+
github.com/shurcooL/graphql v0.0.0-20240915155400-7ee5256398cf h1:o1uxfymjZ7jZ4MsgCErcwWGtVKSiNAXtS59Lhs6uI/g=
152+
github.com/shurcooL/graphql v0.0.0-20240915155400-7ee5256398cf/go.mod h1:9dIRpgIY7hVhoqfe0/FcYp0bpInZaT7dc3BYOprrIUE=
153153
github.com/skeema/knownhosts v1.3.1 h1:X2osQ+RAjK76shCbvhHHHVl3ZlgDm8apHEHFqRjnBY8=
154154
github.com/skeema/knownhosts v1.3.1/go.mod h1:r7KTdC8l4uxWRyK2TpQZ/1o5HaSzh06ePQNxPwTcfiY=
155155
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=

0 commit comments

Comments
 (0)