Skip to content

Commit cf0a8e7

Browse files
committed
fixup! feat: Refactor team data sources to latest pattern
1 parent 0a577e4 commit cf0a8e7

9 files changed

Lines changed: 57 additions & 14 deletions

docs/data-sources/organization_repository_role.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ description: |-
99

1010
Data source to lookup a custom organization repository role.
1111

12+
~> Custom organization repository roles are currently only available for GitHub Enterprise organizations.
13+
1214
## Example Usage
1315

1416
```terraform

docs/data-sources/organization_repository_roles.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ description: |-
99

1010
Data source to list all custom repository roles in an organization.
1111

12+
~> Custom organization repository roles are currently only available for GitHub Enterprise organizations.
13+
1214
## Example Usage
1315

1416
```terraform

github/data_source_github_organization_teams.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func dataSourceGithubOrganizationTeamsRead(ctx context.Context, d *schema.Resour
188188
}
189189

190190
t["parent"] = map[string]any{
191-
"id": strconv.FormatInt(team.Parent.GetID(), 10),
191+
"id": team.Parent.GetNodeID(),
192192
"slug": team.Parent.GetSlug(),
193193
"name": team.Parent.GetName(),
194194
}

github/data_source_github_organization_teams_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ data "github_organization_teams" "test" {
7171
"members": knownvalue.ListSizeExact(0),
7272
"repositories": knownvalue.ListSizeExact(0),
7373
"parent": knownvalue.MapExact(map[string]knownvalue.Check{
74-
"id": knownvalue.StringExact(strconv.FormatInt(team1.GetID(), 10)),
74+
"id": knownvalue.StringExact(team1.GetNodeID()),
7575
"slug": knownvalue.StringExact(team1.GetSlug()),
7676
"name": knownvalue.StringExact(team1.GetName()),
7777
}),

github/data_source_github_repository_teams.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,10 @@ func dataSourceGithubRepositoryTeams() *schema.Resource {
9292
func dataSourceGithubRepositoryTeamsRead(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics {
9393
meta, _ := m.(*Owner)
9494

95-
if ok, diags := checkOrganizationOK(meta); !ok {
96-
return diags
97-
}
95+
// TODO: Reinstate this check for v7 when `full_name` is removed from the schema.
96+
// if ok, diags := checkOrganizationOK(meta); !ok {
97+
// return diags
98+
// }
9899

99100
var owner, repoName string
100101
if v, ok := d.GetOk("full_name"); ok {

github/data_source_github_team.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ func dataSourceGithubTeam() *schema.Resource {
1919

2020
Schema: map[string]*schema.Schema{
2121
"team_id": {
22-
Description: "ID of the team.",
23-
Type: schema.TypeInt,
24-
Optional: true,
25-
Computed: true,
26-
ExactlyOneOf: []string{"team_id", "slug"},
22+
Description: "ID of the team.",
23+
Type: schema.TypeInt,
24+
Optional: true,
25+
Computed: true,
26+
ExactlyOneOf: []string{"team_id", "slug"},
27+
ValidateDiagFunc: validation.ToDiagFunc(validation.IntAtLeast(1)),
2728
},
2829
"slug": {
2930
Description: "Slug of the team name.",

github/data_source_github_team_test.go

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,24 +93,57 @@ data "github_team" "test" {
9393
t.Parallel()
9494

9595
skipUnlessHasOrgUser1(t)
96+
skipUnlessHasOrgUser2(t)
9697

9798
team := mustCreateTestTeam(t, nil)
98-
repo := mustCreateTestRepository(t)
9999
mustAddTeamMember(t, team, testAccConf.testOrgUser1)
100+
childTeam := mustCreateTestTeam(t, new(team.GetID()))
101+
mustAddTeamMember(t, childTeam, testAccConf.testOrgUser2)
102+
repo := mustCreateTestRepository(t)
100103
mustAddRepositoryTeam(t, repo, team)
101104

102105
config := fmt.Sprintf(`
103106
data "github_team" "test" {
104-
slug = "%s"
105-
summary_only = false
107+
slug = "%s"
108+
summary_only = false
109+
membership_type = "%%v"
106110
}
107111
`, team.GetSlug())
108112

109113
resource.Test(t, resource.TestCase{
110114
ProviderFactories: providerFactories,
111115
Steps: []resource.TestStep{
112116
{
113-
Config: config,
117+
Config: fmt.Sprintf(config, "all"),
118+
ConfigStateChecks: []statecheck.StateCheck{
119+
statecheck.ExpectKnownValue("data.github_team.test", tfjsonpath.New("team_id"), knownvalue.Int32Exact(int32(team.GetID()))),
120+
statecheck.ExpectKnownValue("data.github_team.test", tfjsonpath.New("slug"), knownvalue.StringExact(team.GetSlug())),
121+
statecheck.ExpectKnownValue("data.github_team.test", tfjsonpath.New("node_id"), knownvalue.StringExact(team.GetNodeID())),
122+
statecheck.ExpectKnownValue("data.github_team.test", tfjsonpath.New("name"), knownvalue.StringExact(team.GetName())),
123+
statecheck.ExpectKnownValue("data.github_team.test", tfjsonpath.New("description"), knownvalue.StringExact(team.GetDescription())),
124+
statecheck.ExpectKnownValue("data.github_team.test", tfjsonpath.New("type"), knownvalue.StringExact(team.GetType())),
125+
statecheck.ExpectKnownValue("data.github_team.test", tfjsonpath.New("privacy"), knownvalue.StringExact(team.GetPrivacy())),
126+
statecheck.ExpectKnownValue("data.github_team.test", tfjsonpath.New("notification_setting"), knownvalue.StringExact(team.GetNotificationSetting())),
127+
statecheck.ExpectKnownValue("data.github_team.test", tfjsonpath.New("permission"), knownvalue.StringExact(team.GetPermission())),
128+
statecheck.ExpectKnownValue("data.github_team.test", tfjsonpath.New("parent_team"), knownvalue.Null()),
129+
statecheck.ExpectKnownValue("data.github_team.test", tfjsonpath.New("members"), knownvalue.ListExact([]knownvalue.Check{
130+
knownvalue.StringExact(testAccConf.testOrgUser1),
131+
knownvalue.StringExact(testAccConf.testOrgUser2),
132+
})),
133+
statecheck.ExpectKnownValue("data.github_team.test", tfjsonpath.New("repositories"), knownvalue.ListExact([]knownvalue.Check{
134+
knownvalue.StringExact(repo.GetName()),
135+
})),
136+
statecheck.ExpectKnownValue("data.github_team.test", tfjsonpath.New("repositories_detailed"), knownvalue.ListExact([]knownvalue.Check{
137+
knownvalue.MapExact(map[string]knownvalue.Check{
138+
"repo_id": knownvalue.Int32Exact(int32(repo.GetID())),
139+
"repo_name": knownvalue.StringExact(repo.GetName()),
140+
"role_name": knownvalue.StringExact("read"),
141+
}),
142+
})),
143+
},
144+
},
145+
{
146+
Config: fmt.Sprintf(config, "immediate"),
114147
ConfigStateChecks: []statecheck.StateCheck{
115148
statecheck.ExpectKnownValue("data.github_team.test", tfjsonpath.New("team_id"), knownvalue.Int32Exact(int32(team.GetID()))),
116149
statecheck.ExpectKnownValue("data.github_team.test", tfjsonpath.New("slug"), knownvalue.StringExact(team.GetSlug())),

templates/data-sources/organization_repository_role.md.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ description: |-
99

1010
{{ .Description | trimspace }}
1111

12+
~> Custom organization repository roles are currently only available for GitHub Enterprise organizations.
13+
1214
{{ if .HasExamples -}}
1315
## Example Usage
1416

templates/data-sources/organization_repository_roles.md.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ description: |-
99

1010
{{ .Description | trimspace }}
1111

12+
~> Custom organization repository roles are currently only available for GitHub Enterprise organizations.
13+
1214
{{ if .HasExamples -}}
1315
## Example Usage
1416

0 commit comments

Comments
 (0)