Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ linters:
linters:
- unparam
text: always receives
- linters:
- staticcheck
text: "SA1019.*ByID.*deprecated"

issues:
max-issues-per-linter: 0
Expand Down
21 changes: 1 addition & 20 deletions github/data_source_github_organization_repository_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package github

import (
"context"
"fmt"
"strconv"

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

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

// TODO: Use this code when go-github is at v68+
// role, _, err := client.Organizations.GetCustomRepoRole(ctx, orgName, roleId)
// if err != nil {
// return diag.FromErr(err)
// }

roles, _, err := client.Organizations.ListCustomRepoRoles(ctx, orgName)
role, _, err := client.Organizations.GetCustomRepoRole(ctx, orgName, roleId)
if err != nil {
return diag.FromErr(err)
}

var role *github.CustomRepoRoles
for _, r := range roles.CustomRepoRoles {
if r.GetID() == roleId {
role = r
break
}
}
if role == nil {
return diag.FromErr(fmt.Errorf("custom organization repo role with ID %d not found", roleId))
}

r := map[string]any{
"role_id": role.GetID(),
"name": role.GetName(),
Expand Down
32 changes: 15 additions & 17 deletions github/data_source_github_organization_role_teams.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,21 @@ func dataSourceGithubOrganizationRoleTeams() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
// TODO: Add these fields when go-github is v68+
// See https://github.com/google/go-github/issues/3364
// "assignment": {
// Description: "Determines if the team has a direct, indirect, or mixed relationship to a role.",
// Type: schema.TypeString,
// Computed: true,
// },
// "parent_team_id": {
// Description: "The ID of the parent team if this is an indirect assignment.",
// Type: schema.TypeString,
// Computed: true,
// },
// "parent_team_slug": {
// Description: "The slug of the parent team if this is an indirect assignment.",
// Type: schema.TypeString,
// Computed: true,
// },
"assignment": {
Description: "Determines if the team has a direct, indirect, or mixed relationship to a role.",
Type: schema.TypeString,
Computed: true,
},
"parent_team_id": {
Description: "The ID of the parent team if this is an indirect assignment.",
Type: schema.TypeString,
Computed: true,
},
"parent_team_slug": {
Description: "The slug of the parent team if this is an indirect assignment.",
Type: schema.TypeString,
Computed: true,
},
},
},
},
Expand Down
32 changes: 15 additions & 17 deletions github/data_source_github_organization_role_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,21 @@ func dataSourceGithubOrganizationRoleUsers() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
// TODO: Add these fields when go-github is v68+
// See https://github.com/google/go-github/issues/3364
// "assignment": {
// Description: "Determines if the team has a direct, indirect, or mixed relationship to a role.",
// Type: schema.TypeString,
// Computed: true,
// },
// "parent_team_id": {
// Description: "The ID of the parent team if this is an indirect assignment.",
// Type: schema.TypeString,
// Computed: true,
// },
// "parent_team_slug": {
// Description: "The slug of the parent team if this is an indirect assignment.",
// Type: schema.TypeString,
// Computed: true,
// },
"assignment": {
Description: "Determines if the team has a direct, indirect, or mixed relationship to a role.",
Type: schema.TypeString,
Computed: true,
},
"parent_team_id": {
Description: "The ID of the parent team if this is an indirect assignment.",
Type: schema.TypeString,
Computed: true,
},
"parent_team_slug": {
Description: "The slug of the parent team if this is an indirect assignment.",
Type: schema.TypeString,
Computed: true,
},
},
},
},
Expand Down
37 changes: 9 additions & 28 deletions github/resource_github_organization_repository_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log"
"net/http"
"strconv"

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

// TODO: Use this code when go-github is v68+
// role, _, err := client.Organizations.GetCustomRepoRole(ctx, orgName, roleId)
// if err != nil {
// if ghErr, ok := err.(*github.ErrorResponse); ok {
// if ghErr.Response.StatusCode == http.StatusNotFound {
// log.Printf("[WARN] GitHub organization repository role (%s/%d) not found, removing from state", orgName, roleId)
// d.SetId("")
// return nil
// }
// }
// return err
// }

roles, _, err := client.Organizations.ListCustomRepoRoles(ctx, orgName)
role, _, err := client.Organizations.GetCustomRepoRole(ctx, orgName, roleId)
if err != nil {
return diag.FromErr(err)
}

var role *github.CustomRepoRoles
for _, r := range roles.CustomRepoRoles {
if r.GetID() == roleId {
role = r
break
if ghErr, ok := err.(*github.ErrorResponse); ok {
if ghErr.Response.StatusCode == http.StatusNotFound {
log.Printf("[WARN] GitHub organization repository role (%s/%d) not found, removing from state", orgName, roleId)
d.SetId("")
return nil
}
}
}

if role == nil {
log.Printf("[WARN] GitHub organization repository role (%s/%d) not found, removing from state", orgName, roleId)
d.SetId("")
return nil
return diag.FromErr(err)
}

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