|
4 | 4 | "context" |
5 | 5 | "fmt" |
6 | 6 | "log" |
| 7 | + "net/http" |
7 | 8 | "strconv" |
8 | 9 |
|
9 | 10 | "github.com/google/go-github/v81/github" |
@@ -99,36 +100,16 @@ func resourceGithubOrganizationRepositoryRoleRead(ctx context.Context, d *schema |
99 | 100 | return diag.FromErr(err) |
100 | 101 | } |
101 | 102 |
|
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) |
116 | 104 | 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 | + } |
125 | 111 | } |
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) |
132 | 113 | } |
133 | 114 |
|
134 | 115 | if err = d.Set("role_id", role.GetID()); err != nil { |
|
0 commit comments