-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.go
More file actions
160 lines (150 loc) · 4.66 KB
/
Copy pathsearch.go
File metadata and controls
160 lines (150 loc) · 4.66 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
151
152
153
154
155
156
157
158
159
160
package gitcode
import (
"context"
"fmt"
"net/http"
"time"
)
type SearchRepositoriesOptions struct {
ListOptions
Query string `json:"q"`
Sort string `json:"sort,omitempty"`
Order string `json:"order,omitempty"`
Owner string `json:"owner,omitempty"`
Fork string `json:"fork,omitempty"`
Language string `json:"language,omitempty"`
}
type SearchRepositoryResult struct {
ID int64 `json:"id"`
FullName string `json:"full_name"`
HumanName string `json:"human_name"`
Path string `json:"path"`
Name string `json:"name"`
Description string `json:"description"`
SSHURLToRepo string `json:"ssh_url_to_repo"`
HTTPURLToRepo string `json:"http_url_to_repo"`
WebURL string `json:"web_url"`
ForksCount int `json:"forks_count"`
StargazersCount int `json:"stargazers_count"`
WatchersCount int `json:"watchers_count"`
DefaultBranch string `json:"default_branch"`
OpenIssuesCount int `json:"open_issues_count"`
Private bool `json:"private"`
Public bool `json:"public"`
Fork bool `json:"fork"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
PushedAt string `json:"pushed_at"`
Owner *User `json:"owner"`
Namespace *struct {
ID int64 `json:"id"`
Type string `json:"type"`
Name string `json:"name"`
Path string `json:"path"`
HTMLURL string `json:"html_url"`
} `json:"namespace"`
}
func (c *Client) SearchRepositories(ctx context.Context, opts SearchRepositoriesOptions) ([]*SearchRepositoryResult, error) {
var repos []*SearchRepositoryResult
query := fmt.Sprintf("q=%s&%s", opts.Query, opts.ListOptions.toQuery())
if opts.Sort != "" {
query += "&sort=" + opts.Sort
}
if opts.Order != "" {
query += "&order=" + opts.Order
}
if opts.Owner != "" {
query += "&owner=" + opts.Owner
}
if opts.Fork != "" {
query += "&fork=" + opts.Fork
}
if opts.Language != "" {
query += "&language=" + opts.Language
}
err := c.doRequest(ctx, http.MethodGet, fmt.Sprintf("/search/repositories?%s", query), nil, &repos)
if err != nil {
return nil, err
}
return repos, nil
}
type SearchIssuesOptions struct {
ListOptions
Query string `json:"q"`
Sort string `json:"sort,omitempty"`
Order string `json:"order,omitempty"`
Repo string `json:"repo,omitempty"`
State string `json:"state,omitempty"`
}
type SearchIssueResult struct {
ID int64 `json:"id"`
HTMLURL string `json:"html_url"`
Number string `json:"number"`
State string `json:"state"`
Title string `json:"title"`
Body string `json:"body"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Labels []*Label `json:"labels"`
Priority int `json:"priority"`
Comments int `json:"comments"`
Repository *struct {
ID int64 `json:"id"`
FullName string `json:"full_name"`
HumanName string `json:"human_name"`
Path string `json:"path"`
Name string `json:"name"`
URL string `json:"url"`
Owner *User `json:"owner"`
} `json:"repository"`
}
func (c *Client) SearchIssues(ctx context.Context, opts SearchIssuesOptions) ([]*SearchIssueResult, error) {
var issues []*SearchIssueResult
query := fmt.Sprintf("q=%s&%s", opts.Query, opts.ListOptions.toQuery())
if opts.Sort != "" {
query += "&sort=" + opts.Sort
}
if opts.Order != "" {
query += "&order=" + opts.Order
}
if opts.Repo != "" {
query += "&repo=" + opts.Repo
}
if opts.State != "" {
query += "&state=" + opts.State
}
err := c.doRequest(ctx, http.MethodGet, fmt.Sprintf("/search/issues?%s", query), nil, &issues)
if err != nil {
return nil, err
}
return issues, nil
}
type SearchUsersOptions struct {
ListOptions
Query string `json:"q"`
Sort string `json:"sort,omitempty"`
Order string `json:"order,omitempty"`
}
type SearchUserResult struct {
ID string `json:"id"`
Login string `json:"login"`
Name string `json:"name"`
AvatarURL string `json:"avatar_url"`
HTMLURL string `json:"html_url"`
CreatedAt time.Time `json:"created_at"`
}
func (c *Client) SearchUsers(ctx context.Context, opts SearchUsersOptions) ([]*SearchUserResult, error) {
var users []*SearchUserResult
query := fmt.Sprintf("q=%s&%s", opts.Query, opts.ListOptions.toQuery())
if opts.Sort != "" {
query += "&sort=" + opts.Sort
}
if opts.Order != "" {
query += "&order=" + opts.Order
}
err := c.doRequest(ctx, http.MethodGet, fmt.Sprintf("/search/users?%s", query), nil, &users)
if err != nil {
return nil, err
}
return users, nil
}