Skip to content

Commit 9e8efec

Browse files
committed
feat: Refactor to use team slug in api
Signed-off-by: Steve Hipwell <steve.hipwell@gmail.com>
1 parent 12c208e commit 9e8efec

16 files changed

+806
-636
lines changed

.golangci.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ linters:
4242
linters:
4343
- unparam
4444
text: always receives
45-
- linters:
46-
- staticcheck
47-
text: "SA1019.*ByID.*deprecated"
4845

4946
issues:
5047
max-issues-per-linter: 0

github/data_source_github_organization_repository_role.go

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ package github
22

33
import (
44
"context"
5-
"fmt"
65
"strconv"
76

8-
"github.com/google/go-github/v81/github"
97
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
108
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
119
)
@@ -53,28 +51,11 @@ func dataSourceGithubOrganizationRepositoryRoleRead(ctx context.Context, d *sche
5351

5452
roleId := int64(d.Get("role_id").(int))
5553

56-
// TODO: Use this code when go-github is at v68+
57-
// role, _, err := client.Organizations.GetCustomRepoRole(ctx, orgName, roleId)
58-
// if err != nil {
59-
// return diag.FromErr(err)
60-
// }
61-
62-
roles, _, err := client.Organizations.ListCustomRepoRoles(ctx, orgName)
54+
role, _, err := client.Organizations.GetCustomRepoRole(ctx, orgName, roleId)
6355
if err != nil {
6456
return diag.FromErr(err)
6557
}
6658

67-
var role *github.CustomRepoRoles
68-
for _, r := range roles.CustomRepoRoles {
69-
if r.GetID() == roleId {
70-
role = r
71-
break
72-
}
73-
}
74-
if role == nil {
75-
return diag.FromErr(fmt.Errorf("custom organization repo role with ID %d not found", roleId))
76-
}
77-
7859
r := map[string]any{
7960
"role_id": role.GetID(),
8061
"name": role.GetName(),

github/data_source_github_organization_role_teams.go

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,21 @@ func dataSourceGithubOrganizationRoleTeams() *schema.Resource {
4848
Type: schema.TypeString,
4949
Computed: true,
5050
},
51-
// TODO: Add these fields when go-github is v68+
52-
// See https://github.com/google/go-github/issues/3364
53-
// "assignment": {
54-
// Description: "Determines if the team has a direct, indirect, or mixed relationship to a role.",
55-
// Type: schema.TypeString,
56-
// Computed: true,
57-
// },
58-
// "parent_team_id": {
59-
// Description: "The ID of the parent team if this is an indirect assignment.",
60-
// Type: schema.TypeString,
61-
// Computed: true,
62-
// },
63-
// "parent_team_slug": {
64-
// Description: "The slug of the parent team if this is an indirect assignment.",
65-
// Type: schema.TypeString,
66-
// Computed: true,
67-
// },
51+
"assignment": {
52+
Description: "Determines if the team has a direct, indirect, or mixed relationship to a role.",
53+
Type: schema.TypeString,
54+
Computed: true,
55+
},
56+
"parent_team_id": {
57+
Description: "The ID of the parent team if this is an indirect assignment.",
58+
Type: schema.TypeString,
59+
Computed: true,
60+
},
61+
"parent_team_slug": {
62+
Description: "The slug of the parent team if this is an indirect assignment.",
63+
Type: schema.TypeString,
64+
Computed: true,
65+
},
6866
},
6967
},
7068
},

github/data_source_github_organization_role_users.go

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,21 @@ func dataSourceGithubOrganizationRoleUsers() *schema.Resource {
3838
Type: schema.TypeString,
3939
Computed: true,
4040
},
41-
// TODO: Add these fields when go-github is v68+
42-
// See https://github.com/google/go-github/issues/3364
43-
// "assignment": {
44-
// Description: "Determines if the team has a direct, indirect, or mixed relationship to a role.",
45-
// Type: schema.TypeString,
46-
// Computed: true,
47-
// },
48-
// "parent_team_id": {
49-
// Description: "The ID of the parent team if this is an indirect assignment.",
50-
// Type: schema.TypeString,
51-
// Computed: true,
52-
// },
53-
// "parent_team_slug": {
54-
// Description: "The slug of the parent team if this is an indirect assignment.",
55-
// Type: schema.TypeString,
56-
// Computed: true,
57-
// },
41+
"assignment": {
42+
Description: "Determines if the team has a direct, indirect, or mixed relationship to a role.",
43+
Type: schema.TypeString,
44+
Computed: true,
45+
},
46+
"parent_team_id": {
47+
Description: "The ID of the parent team if this is an indirect assignment.",
48+
Type: schema.TypeString,
49+
Computed: true,
50+
},
51+
"parent_team_slug": {
52+
Description: "The slug of the parent team if this is an indirect assignment.",
53+
Type: schema.TypeString,
54+
Computed: true,
55+
},
5856
},
5957
},
6058
},

github/resource_github_organization_repository_role.go

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"log"
7+
"net/http"
78
"strconv"
89

910
"github.com/google/go-github/v81/github"
@@ -99,36 +100,16 @@ func resourceGithubOrganizationRepositoryRoleRead(ctx context.Context, d *schema
99100
return diag.FromErr(err)
100101
}
101102

102-
// TODO: Use this code when go-github is v68+
103-
// role, _, err := client.Organizations.GetCustomRepoRole(ctx, orgName, roleId)
104-
// if err != nil {
105-
// if ghErr, ok := err.(*github.ErrorResponse); ok {
106-
// if ghErr.Response.StatusCode == http.StatusNotFound {
107-
// log.Printf("[WARN] GitHub organization repository role (%s/%d) not found, removing from state", orgName, roleId)
108-
// d.SetId("")
109-
// return nil
110-
// }
111-
// }
112-
// return err
113-
// }
114-
115-
roles, _, err := client.Organizations.ListCustomRepoRoles(ctx, orgName)
103+
role, _, err := client.Organizations.GetCustomRepoRole(ctx, orgName, roleId)
116104
if err != nil {
117-
return diag.FromErr(err)
118-
}
119-
120-
var role *github.CustomRepoRoles
121-
for _, r := range roles.CustomRepoRoles {
122-
if r.GetID() == roleId {
123-
role = r
124-
break
105+
if ghErr, ok := err.(*github.ErrorResponse); ok {
106+
if ghErr.Response.StatusCode == http.StatusNotFound {
107+
log.Printf("[WARN] GitHub organization repository role (%s/%d) not found, removing from state", orgName, roleId)
108+
d.SetId("")
109+
return nil
110+
}
125111
}
126-
}
127-
128-
if role == nil {
129-
log.Printf("[WARN] GitHub organization repository role (%s/%d) not found, removing from state", orgName, roleId)
130-
d.SetId("")
131-
return nil
112+
return diag.FromErr(err)
132113
}
133114

134115
if err = d.Set("role_id", role.GetID()); err != nil {

0 commit comments

Comments
 (0)