Skip to content

Commit dd1a6e1

Browse files
authored
Merge branch 'main' into pr-2502
2 parents b5ae4dd + ad2d11d commit dd1a6e1

4 files changed

Lines changed: 56 additions & 19 deletions

File tree

github/data_source_github_organization_teams.go

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package github
22

33
import (
4+
"context"
5+
"strconv"
6+
7+
"github.com/google/go-github/v66/github"
48
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
59
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
610
"github.com/shurcooL/githubv4"
@@ -67,9 +71,18 @@ func dataSourceGithubOrganizationTeams() *schema.Resource {
6771
Elem: &schema.Schema{Type: schema.TypeString},
6872
},
6973
"parent": {
70-
Type: schema.TypeMap,
74+
Deprecated: "Use parent_team_id and parent_team_slug instead.",
75+
Type: schema.TypeMap,
76+
Computed: true,
77+
Elem: &schema.Schema{Type: schema.TypeString},
78+
},
79+
"parent_team_id": {
80+
Type: schema.TypeString,
81+
Computed: true,
82+
},
83+
"parent_team_slug": {
84+
Type: schema.TypeString,
7185
Computed: true,
72-
Elem: &schema.Schema{Type: schema.TypeString},
7386
},
7487
},
7588
},
@@ -84,6 +97,7 @@ func dataSourceGithubOrganizationTeamsRead(d *schema.ResourceData, meta interfac
8497
return err
8598
}
8699

100+
clientv3 := meta.(*Owner).v3client
87101
client := meta.(*Owner).v4client
88102
orgName := meta.(*Owner).name
89103
rootTeamsOnly := d.Get("root_teams_only").(bool)
@@ -107,7 +121,10 @@ func dataSourceGithubOrganizationTeamsRead(d *schema.ResourceData, meta interfac
107121
return err
108122
}
109123

110-
additionalTeams := flattenGitHubTeams(query)
124+
additionalTeams, err := flattenGitHubTeams(clientv3, meta.(*Owner).StopContext, orgName, query)
125+
if err != nil {
126+
return err
127+
}
111128
teams = append(teams, additionalTeams...)
112129

113130
if !query.Organization.Teams.PageInfo.HasNextPage {
@@ -125,11 +142,11 @@ func dataSourceGithubOrganizationTeamsRead(d *schema.ResourceData, meta interfac
125142
return nil
126143
}
127144

128-
func flattenGitHubTeams(tq TeamsQuery) []interface{} {
145+
func flattenGitHubTeams(client *github.Client, ctx context.Context, org string, tq TeamsQuery) ([]interface{}, error) {
129146
teams := tq.Organization.Teams.Nodes
130147

131148
if len(teams) == 0 {
132-
return make([]interface{}, 0)
149+
return make([]interface{}, 0), nil
133150
}
134151

135152
flatTeams := make([]interface{}, len(teams))
@@ -152,6 +169,18 @@ func flattenGitHubTeams(tq TeamsQuery) []interface{} {
152169

153170
t["members"] = flatMembers
154171

172+
var parentTeamId string
173+
if len(team.Parent.Slug) != 0 {
174+
parentTeam, _, err := client.Teams.GetTeamBySlug(ctx, org, string(team.Parent.Slug))
175+
if err != nil {
176+
return nil, err
177+
}
178+
parentTeamId = strconv.FormatInt(parentTeam.GetID(), 10)
179+
}
180+
181+
t["parent_team_id"] = parentTeamId
182+
t["parent_team_slug"] = team.Parent.Slug
183+
155184
parentTeam := make(map[string]interface{})
156185
parentTeam["id"] = team.Parent.ID
157186
parentTeam["slug"] = team.Parent.Slug
@@ -171,5 +200,5 @@ func flattenGitHubTeams(tq TeamsQuery) []interface{} {
171200
flatTeams[i] = t
172201
}
173202

174-
return flatTeams
203+
return flatTeams, nil
175204
}

github/data_source_github_team.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ func dataSourceGithubTeam() *schema.Resource {
4343
Elem: &schema.Schema{Type: schema.TypeString},
4444
},
4545
"repositories": {
46-
Type: schema.TypeList,
47-
Computed: true,
48-
Elem: &schema.Schema{Type: schema.TypeString},
46+
Deprecated: "Use repositories_detailed instead.",
47+
Type: schema.TypeList,
48+
Computed: true,
49+
Elem: &schema.Schema{Type: schema.TypeString},
4950
},
5051
"repositories_detailed": {
5152
Type: schema.TypeList,
@@ -56,6 +57,10 @@ func dataSourceGithubTeam() *schema.Resource {
5657
Type: schema.TypeInt,
5758
Computed: true,
5859
},
60+
"repo_name": {
61+
Type: schema.TypeString,
62+
Computed: true,
63+
},
5964
"role_name": {
6065
Type: schema.TypeString,
6166
Computed: true,
@@ -168,7 +173,7 @@ func dataSourceGithubTeamRead(d *schema.ResourceData, meta interface{}) error {
168173
}
169174
}
170175

171-
repositories_detailed = make([]interface{}, 0, resultsPerPage) //removed this from the loop
176+
repositories_detailed = make([]interface{}, 0, resultsPerPage) // removed this from the loop
172177

173178
for {
174179
repository, resp, err := client.Teams.ListTeamReposByID(ctx, orgId, team.GetID(), &options.ListOptions)
@@ -180,6 +185,7 @@ func dataSourceGithubTeamRead(d *schema.ResourceData, meta interface{}) error {
180185
repositories = append(repositories, v.GetName())
181186
repositories_detailed = append(repositories_detailed, map[string]interface{}{
182187
"repo_id": v.GetID(),
188+
"repo_name": v.GetName(),
183189
"role_name": v.GetRoleName(),
184190
})
185191
}

website/docs/d/organization_teams.html.markdown

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ ___
3636

3737
The `team` block consists of:
3838

39-
* `id` - the ID of the team.
40-
* `node_id` - the Node ID of the team.
41-
* `slug` - the slug of the team.
42-
* `name` - the team's full name.
43-
* `description` - the team's description.
44-
* `privacy` - the team's privacy type.
39+
* `id` - The ID of the team.
40+
* `node_id` - The Node ID of the team.
41+
* `slug` - The slug of the team.
42+
* `name` - The team's full name.
43+
* `description` - The team's description.
44+
* `privacy` - The team's privacy type.
4545
* `members` - List of team members. Not returned if `summary_only = true`
4646
* `repositories` - List of team repositories. Not returned if `summary_only = true`
47-
* `parent` - the parent team.
47+
* `parent_team_id` - The ID of the parent team, if there is one.
48+
* `parent_team_slug` - The slug of the parent team, if there is one.
49+
* `parent` - (**DEPRECATED**) The parent team, use `parent_team_id` or `parent_team_slug` instead.

website/docs/d/team.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ data "github_team" "example" {
3333
* `privacy` - the team's privacy type.
3434
* `permission` - the team's permission level.
3535
* `members` - List of team members (list of GitHub usernames). Not returned if `summary_only = true`
36-
* `repositories` - List of team repositories (list of repo names). Not returned if `summary_only = true`
37-
* `repositories_detailed` - List of team repositories (list of `repo_id` and [`role_name`](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/team_repository#permission)). Not returned if `summary_only = true`
36+
* `repositories` - (**DEPRECATED**) List of team repositories (list of repo names). Not returned if `summary_only = true`
37+
* `repositories_detailed` - List of team repositories (each item comprises of `repo_id`, `repo_name` & [`role_name`](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/team_repository#permission)). Not returned if `summary_only = true`

0 commit comments

Comments
 (0)