-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathtable_github_search_issue.go
More file actions
78 lines (65 loc) · 2.08 KB
/
Copy pathtable_github_search_issue.go
File metadata and controls
78 lines (65 loc) · 2.08 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
package github
import (
"context"
"github.com/shurcooL/githubv4"
"github.com/turbot/steampipe-plugin-github/github/models"
"github.com/turbot/steampipe-plugin-sdk/v6/plugin"
)
func gitHubSearchIssueColumns() []*plugin.Column {
return append(defaultSearchColumns(), gitHubMyIssueColumns()...)
}
func tableGitHubSearchIssue() *plugin.Table {
return &plugin.Table{
Name: "github_search_issue",
Description: "Find issues by state and keyword.",
List: &plugin.ListConfig{
KeyColumns: plugin.SingleColumn("query"),
Hydrate: tableGitHubSearchIssueList,
},
Columns: commonColumns(gitHubSearchIssueColumns()),
}
}
func tableGitHubSearchIssueList(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
quals := d.EqualsQuals
input := quals["query"].GetStringValue()
if input == "" {
return nil, nil
}
input += " is:issue"
var query struct {
RateLimit models.RateLimit
Search struct {
PageInfo models.PageInfo
Edges []models.SearchIssueResult
} `graphql:"search(type: ISSUE, first: $pageSize, after: $cursor, query: $query)"`
}
pageSize := adjustPageSize(100, d.QueryContext.Limit)
variables := map[string]interface{}{
"pageSize": githubv4.Int(pageSize),
"cursor": (*githubv4.String)(nil),
"query": githubv4.String(input),
}
appendIssueColumnIncludes(&variables, d.QueryContext.Columns)
appendUserInteractionAbilityForIssue(&variables, d.QueryContext.Columns, d)
client := connectV4(ctx, d)
for {
err := client.Query(ctx, &query, variables)
plugin.Logger(ctx).Debug(rateLimitLogString("github_search_issue", &query.RateLimit))
if err != nil {
plugin.Logger(ctx).Error("github_search_issue", "api_error", err)
return nil, err
}
for _, issue := range query.Search.Edges {
d.StreamListItem(ctx, issue)
// Context can be cancelled due to manual cancellation or the limit has been hit
if d.RowsRemaining(ctx) == 0 {
return nil, nil
}
}
if !query.Search.PageInfo.HasNextPage {
break
}
variables["cursor"] = githubv4.NewString(query.Search.PageInfo.EndCursor)
}
return nil, nil
}