-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathtable_github_team.go
More file actions
150 lines (131 loc) · 8.05 KB
/
Copy pathtable_github_team.go
File metadata and controls
150 lines (131 loc) · 8.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package github
import (
"context"
"strings"
"github.com/shurcooL/githubv4"
"github.com/turbot/steampipe-plugin-github/github/models"
"github.com/turbot/steampipe-plugin-sdk/v6/grpc/proto"
"github.com/turbot/steampipe-plugin-sdk/v6/plugin"
"github.com/turbot/steampipe-plugin-sdk/v6/plugin/transform"
)
func gitHubTeamColumns() []*plugin.Column {
return []*plugin.Column{
{Name: "organization", Type: proto.ColumnType_STRING, Description: "The organization the team is associated with.", Transform: transform.FromField("Organization.Login")},
{Name: "slug", Type: proto.ColumnType_STRING, Description: "The team slug name."},
{Name: "name", Type: proto.ColumnType_STRING, Description: "The name of the team."},
{Name: "id", Type: proto.ColumnType_INT, Description: "The ID of the team.", Transform: transform.FromField("Id")},
{Name: "node_id", Type: proto.ColumnType_STRING, Description: "The node id of the team.", Transform: transform.FromField("NodeId")},
{Name: "description", Type: proto.ColumnType_STRING, Description: "The description of the team.", Transform: transform.FromValue(), Hydrate: teamHydrateDescription},
{Name: "created_at", Type: proto.ColumnType_TIMESTAMP, Description: "Timestamp when team was created.", Transform: transform.FromValue(), Hydrate: teamHydrateCreatedAt},
{Name: "updated_at", Type: proto.ColumnType_TIMESTAMP, Description: "Timestamp when team was last updated.", Transform: transform.FromValue(), Hydrate: teamHydrateUpdatedAt},
{Name: "combined_slug", Type: proto.ColumnType_STRING, Description: "The slug corresponding to the organization and the team.", Transform: transform.FromValue(), Hydrate: teamHydrateCombinedSlug},
{Name: "parent_team", Type: proto.ColumnType_JSON, Description: "The teams parent team.", Transform: transform.FromValue().NullIfZero(), Hydrate: teamHydrateParentTeam},
{Name: "privacy", Type: proto.ColumnType_STRING, Description: "The privacy setting of the team (VISIBLE or SECRET).", Transform: transform.FromValue(), Hydrate: teamHydratePrivacy},
{Name: "ancestors_total_count", Type: proto.ColumnType_INT, Description: "Count of ancestors this team has.", Transform: transform.FromValue(), Hydrate: teamHydrateAncestorsTotalCount},
{Name: "child_teams_total_count", Type: proto.ColumnType_INT, Description: "Count of children teams this team has.", Transform: transform.FromValue(), Hydrate: teamHydrateChildTeamsTotalCount},
{Name: "invitations_total_count", Type: proto.ColumnType_INT, Description: "Count of outstanding team member invitations for the team.", Transform: transform.FromValue(), Hydrate: teamHydrateInvitationsTotalCount},
{Name: "members_total_count", Type: proto.ColumnType_INT, Description: "Count of team members.", Transform: transform.FromValue(), Hydrate: teamHydrateMembersTotalCount},
{Name: "projects_v2_total_count", Type: proto.ColumnType_INT, Description: "Count of the teams v2 projects.", Transform: transform.FromValue(), Hydrate: teamHydrateProjectsV2TotalCount},
{Name: "repositories_total_count", Type: proto.ColumnType_INT, Description: "Count of repositories the team has.", Transform: transform.FromValue(), Hydrate: teamHydrateRepositoriesTotalCount},
{Name: "url", Type: proto.ColumnType_STRING, Description: "URL for the team page in GitHub.", Transform: transform.FromValue(), Hydrate: teamHydrateUrl},
{Name: "avatar_url", Type: proto.ColumnType_STRING, Description: "URL for teams avatar.", Transform: transform.FromValue(), Hydrate: teamHydrateAvatarUrl},
{Name: "edit_team_url", Type: proto.ColumnType_STRING, Description: "URL for editing this team.", Transform: transform.FromValue(), Hydrate: teamHydrateEditTeamUrl},
{Name: "members_url", Type: proto.ColumnType_STRING, Description: "URL for team members.", Transform: transform.FromValue(), Hydrate: teamHydrateMembersUrl},
{Name: "new_team_url", Type: proto.ColumnType_STRING, Description: "The HTTP URL creating a new team.", Transform: transform.FromValue(), Hydrate: teamHydrateNewTeamUrl},
{Name: "repositories_url", Type: proto.ColumnType_STRING, Description: "URL for team repositories.", Transform: transform.FromValue(), Hydrate: teamHydrateRepositoriesUrl},
{Name: "teams_url", Type: proto.ColumnType_STRING, Description: "URL for this team's teams.", Transform: transform.FromValue(), Hydrate: teamHydrateTeamsUrl},
{Name: "can_administer", Type: proto.ColumnType_BOOL, Description: "If true, current user can administer the team.", Transform: transform.FromValue(), Hydrate: teamHydrateCanAdminister},
{Name: "can_subscribe", Type: proto.ColumnType_BOOL, Description: "If true, current user can subscribe to the team.", Transform: transform.FromValue(), Hydrate: teamHydrateCanSubscribe},
{Name: "subscription", Type: proto.ColumnType_STRING, Description: "Subscription status of the current user to the team.", Transform: transform.FromValue(), Hydrate: teamHydrateSubscription},
}
}
func tableGitHubTeam() *plugin.Table {
return &plugin.Table{
Name: "github_team",
Description: "GitHub Teams in a given organization. GitHub Teams are groups of organization members that reflect your company or group's structure with cascading access permissions and mentions.",
List: &plugin.ListConfig{
KeyColumns: plugin.SingleColumn("organization"),
ShouldIgnoreError: isNotFoundError([]string{"404"}),
Hydrate: tableGitHubTeamList,
},
Get: &plugin.GetConfig{
KeyColumns: plugin.AllColumns([]string{"organization", "slug"}),
ShouldIgnoreError: isNotFoundError([]string{"404"}),
Hydrate: tableGitHubTeamGet,
},
Columns: commonColumns(gitHubTeamColumns()),
}
}
func tableGitHubTeamList(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
org := d.EqualsQuals["organization"].GetStringValue()
pageSize := adjustPageSize(100, d.QueryContext.Limit)
var query struct {
RateLimit models.RateLimit
Organization struct {
Teams struct {
TotalCount int
PageInfo struct {
EndCursor githubv4.String
HasNextPage bool
}
Nodes []models.TeamWithCounts
} `graphql:"teams(first: $pageSize, after: $cursor)"`
} `graphql:"organization(login: $login)"`
}
variables := map[string]interface{}{
"login": githubv4.String(org),
"pageSize": githubv4.Int(pageSize),
"cursor": (*githubv4.String)(nil),
}
appendTeamColumnIncludes(&variables, d.QueryContext.Columns)
client := connectV4(ctx, d)
for {
err := client.Query(ctx, &query, variables)
plugin.Logger(ctx).Debug(rateLimitLogString("github_team", &query.RateLimit))
if err != nil {
plugin.Logger(ctx).Error("github_team", "api_error", err)
if strings.Contains(err.Error(), "Could not resolve to an Organization with the login of") {
return nil, nil
}
return nil, err
}
for _, team := range query.Organization.Teams.Nodes {
d.StreamListItem(ctx, team)
// Context can be cancelled due to manual cancellation or the limit has been hit
if d.RowsRemaining(ctx) == 0 {
return nil, nil
}
}
if !query.Organization.Teams.PageInfo.HasNextPage {
break
}
variables["cursor"] = githubv4.NewString(query.Organization.Teams.PageInfo.EndCursor)
}
return nil, nil
}
func tableGitHubTeamGet(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
org := d.EqualsQuals["organization"].GetStringValue()
slug := d.EqualsQuals["slug"].GetStringValue()
var query struct {
RateLimit models.RateLimit
Organization struct {
Team models.TeamWithCounts `graphql:"team(slug: $slug)"`
} `graphql:"organization(login: $login)"`
}
variables := map[string]interface{}{
"login": githubv4.String(org),
"slug": githubv4.String(slug),
}
appendTeamColumnIncludes(&variables, d.QueryContext.Columns)
client := connectV4(ctx, d)
err := client.Query(ctx, &query, variables)
plugin.Logger(ctx).Debug(rateLimitLogString("github_team", &query.RateLimit))
if err != nil {
plugin.Logger(ctx).Error("github_team", "api_error", err)
if strings.Contains(err.Error(), "Could not resolve to an Organization with the login of") {
return nil, nil
}
return nil, err
}
return query.Organization.Team, nil
}