Skip to content

Commit ed6d93b

Browse files
committed
Update DS to use new SDK methods
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
1 parent e936e6a commit ed6d93b

2 files changed

Lines changed: 2 additions & 21 deletions

File tree

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/v82/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_repository_role_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
func TestAccGithubOrganizationRepositoryRoleDataSource(t *testing.T) {
1212
t.Run("queries an organization repository role", func(t *testing.T) {
1313
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
14-
roleName := fmt.Sprintf(`tf-acc-test-%s`, randomID)
14+
roleName := fmt.Sprintf(`%s%s`, testResourcePrefix, randomID)
1515

1616
config := fmt.Sprintf(`
1717
resource "github_organization_repository_role" "test" {

0 commit comments

Comments
 (0)