@@ -2,8 +2,9 @@ package github
22
33import (
44 "context"
5+ "errors"
56 "fmt"
6- "log "
7+ "net/http "
78 "slices"
89 "strconv"
910
@@ -107,36 +108,20 @@ func resourceGithubOrganizationRepositoryRoleRead(ctx context.Context, d *schema
107108 return diag .FromErr (err )
108109 }
109110
110- // TODO: Use this code when go-github is v68+
111- // role, _, err := client.Organizations.GetCustomRepoRole(ctx, orgName, roleId)
112- // if err != nil {
113- // if ghErr, ok := err.(*github.ErrorResponse); ok {
114- // if ghErr.Response.StatusCode == http.StatusNotFound {
115- // log.Printf("[WARN] GitHub organization repository role (%s/%d) not found, removing from state", orgName, roleId)
116- // d.SetId("")
117- // return nil
118- // }
119- // }
120- // return err
121- // }
122-
123- roles , _ , err := client .Organizations .ListCustomRepoRoles (ctx , orgName )
111+ role , _ , err := client .Organizations .GetCustomRepoRole (ctx , orgName , roleId )
124112 if err != nil {
125- return diag .FromErr (err )
126- }
127-
128- var role * github.CustomRepoRoles
129- for _ , r := range roles .CustomRepoRoles {
130- if r .GetID () == roleId {
131- role = r
132- break
113+ var ghErr * github.ErrorResponse
114+ if errors .As (err , & ghErr ) {
115+ if ghErr .Response .StatusCode == http .StatusNotFound {
116+ tflog .Warn (ctx , "GitHub organization repository role not found, removing from state" , map [string ]any {
117+ "orgName" : orgName ,
118+ "roleId" : roleId ,
119+ })
120+ d .SetId ("" )
121+ return nil
122+ }
133123 }
134- }
135-
136- if role == nil {
137- log .Printf ("[WARN] GitHub organization repository role (%s/%d) not found, removing from state" , orgName , roleId )
138- d .SetId ("" )
139- return nil
124+ return diag .FromErr (err )
140125 }
141126
142127 if err = d .Set ("role_id" , role .GetID ()); err != nil {
0 commit comments