-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathtable_github_search_topic.go
More file actions
87 lines (72 loc) · 2.95 KB
/
Copy pathtable_github_search_topic.go
File metadata and controls
87 lines (72 loc) · 2.95 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
package github
import (
"context"
"github.com/google/go-github/v55/github"
"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 tableGitHubSearchTopic() *plugin.Table {
return &plugin.Table{
Name: "github_search_topic",
Description: "Find topics via various criteria.",
List: &plugin.ListConfig{
KeyColumns: plugin.SingleColumn("query"),
Hydrate: tableGitHubSearchTopicList,
},
Columns: commonColumns([]*plugin.Column{
{Name: "name", Type: proto.ColumnType_STRING, Description: "The name of the topic."},
{Name: "query", Type: proto.ColumnType_STRING, Transform: transform.FromQual("query"), Description: "The query used to match the topic."},
{Name: "created_at", Type: proto.ColumnType_TIMESTAMP, Transform: transform.FromField("CreatedAt").Transform(convertTimestamp), Description: "The timestamp when the topic was created."},
{Name: "created_by", Type: proto.ColumnType_STRING, Description: "The creator of the topic."},
{Name: "curated", Type: proto.ColumnType_BOOL, Default: false, Description: "Whether the topic is curated."},
{Name: "description", Type: proto.ColumnType_STRING, Description: "The description of the topic."},
{Name: "display_name", Type: proto.ColumnType_STRING, Description: "The display name of the topic."},
{Name: "featured", Type: proto.ColumnType_BOOL, Default: false, Description: "Whether the topic is featured."},
{Name: "score", Type: proto.ColumnType_DOUBLE, Description: "The score of the topic."},
{Name: "short_description", Type: proto.ColumnType_STRING, Description: "The short description of the topic."},
{Name: "updated_at", Type: proto.ColumnType_TIMESTAMP, Description: "The timestamp when the topic was updated."},
}),
}
}
func tableGitHubSearchTopicList(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
logger := plugin.Logger(ctx)
logger.Trace("tableGitHubSearchTopicList")
quals := d.EqualsQuals
query := quals["query"].GetStringValue()
if query == "" {
return nil, nil
}
opt := &github.SearchOptions{
ListOptions: github.ListOptions{PerPage: 100},
TextMatch: true,
}
client := connect(ctx, d)
// Reduce the basic request limit down if the user has only requested a small number of rows
limit := d.QueryContext.Limit
if limit != nil {
if *limit < int64(opt.PerPage) {
opt.PerPage = int(*limit)
}
}
for {
result, resp, err := client.Search.Topics(ctx, query, opt)
if err != nil {
logger.Error("tableGitHubSearchTopicList", "error_RetryHydrate", err)
return nil, err
}
topics := result.Topics
for _, i := range topics {
d.StreamListItem(ctx, i)
// Context can be cancelled due to manual cancellation or the limit has been hit
if d.RowsRemaining(ctx) == 0 {
return nil, nil
}
}
if resp.NextPage == 0 {
break
}
opt.Page = resp.NextPage
}
return nil, nil
}