-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusers.go
More file actions
152 lines (136 loc) · 3.78 KB
/
Copy pathusers.go
File metadata and controls
152 lines (136 loc) · 3.78 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
package gitcode
import (
"context"
"fmt"
"net/http"
"time"
)
type Email struct {
Email string `json:"email"`
State string `json:"state"`
}
func (c *Client) ListEmails(ctx context.Context) ([]*Email, error) {
var emails []*Email
err := c.doRequest(ctx, http.MethodGet, "/emails", nil, &emails)
if err != nil {
return nil, err
}
return emails, nil
}
type SSHKey struct {
ID int64 `json:"id"`
Title string `json:"title"`
Key string `json:"key"`
CreatedAt time.Time `json:"created_at"`
URL string `json:"url"`
}
type CreateSSHKeyOptions struct {
Title string `json:"title"`
Key string `json:"key"`
}
func (c *Client) ListSSHKeys(ctx context.Context, opts ListOptions) ([]*SSHKey, error) {
var keys []*SSHKey
err := c.doRequest(ctx, http.MethodGet, fmt.Sprintf("/user/keys?%s", opts.toQuery()), nil, &keys)
if err != nil {
return nil, err
}
return keys, nil
}
func (c *Client) GetSSHKey(ctx context.Context, id int64) (*SSHKey, error) {
var key SSHKey
err := c.doRequest(ctx, http.MethodGet, fmt.Sprintf("/user/keys/%d", id), nil, &key)
if err != nil {
return nil, err
}
return &key, nil
}
func (c *Client) CreateSSHKey(ctx context.Context, opts CreateSSHKeyOptions) (*SSHKey, error) {
var key SSHKey
err := c.doRequest(ctx, http.MethodPost, "/user/keys", opts, &key)
if err != nil {
return nil, err
}
return &key, nil
}
func (c *Client) DeleteSSHKey(ctx context.Context, id int64) error {
return c.doRequest(ctx, http.MethodDelete, fmt.Sprintf("/user/keys/%d", id), nil, nil)
}
type UserEvent struct {
Action int `json:"action"`
ActionName string `json:"action_name"`
AuthorID int64 `json:"author_id"`
AuthorUsername string `json:"author_username"`
ProjectID int64 `json:"project_id"`
ProjectName string `json:"project_name"`
CreatedAt string `json:"created_at"`
PushData *struct {
CommitCount int `json:"commit_count"`
Action string `json:"action"`
RefType string `json:"ref_type"`
Ref string `json:"ref"`
CommitFrom string `json:"commit_from"`
CommitTo string `json:"commit_to"`
CommitTitle string `json:"commit_title"`
} `json:"push_data"`
}
type UserEventsResponse struct {
Events map[string][]*UserEvent `json:"events"`
Next string `json:"next"`
}
func (c *Client) GetUserEvents(ctx context.Context, username, year, next string) (*UserEventsResponse, error) {
var resp UserEventsResponse
query := ""
if year != "" {
query += "year=" + year
}
if next != "" {
if query != "" {
query += "&"
}
query += "next=" + next
}
path := fmt.Sprintf("/users/%s/events", username)
if query != "" {
path += "?" + query
}
err := c.doRequest(ctx, http.MethodGet, path, nil, &resp)
if err != nil {
return nil, err
}
return &resp, nil
}
type ListStarredReposOptions struct {
ListOptions
Sort string `json:"sort,omitempty"`
Direction string `json:"direction,omitempty"`
}
func (c *Client) ListStarredRepositories(ctx context.Context, opts ListStarredReposOptions) ([]*Repository, error) {
var repos []*Repository
query := opts.toQuery()
if opts.Sort != "" {
query += "&sort=" + opts.Sort
}
if opts.Direction != "" {
query += "&direction=" + opts.Direction
}
err := c.doRequest(ctx, http.MethodGet, fmt.Sprintf("/user/starred?%s", query), nil, &repos)
if err != nil {
return nil, err
}
return repos, nil
}
type Namespace struct {
ID int64 `json:"id"`
Path string `json:"path"`
Name string `json:"name"`
HTMLURL string `json:"html_url"`
Type string `json:"type"`
}
func (c *Client) GetNamespace(ctx context.Context, path string) (*Namespace, error) {
var ns Namespace
err := c.doRequest(ctx, http.MethodGet, fmt.Sprintf("/user/namespace?path=%s", path), nil, &ns)
if err != nil {
return nil, err
}
return &ns, nil
}