-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenterprise_issues.go
More file actions
165 lines (152 loc) · 4.75 KB
/
Copy pathenterprise_issues.go
File metadata and controls
165 lines (152 loc) · 4.75 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
161
162
163
164
165
package gitcode
import (
"context"
"fmt"
"net/http"
)
type ListUserIssuesOptions struct {
ListOptions
Filter string `json:"filter,omitempty"`
State string `json:"state,omitempty"`
Labels string `json:"labels,omitempty"`
Sort string `json:"sort,omitempty"`
Direction string `json:"direction,omitempty"`
Since string `json:"since,omitempty"`
}
func (c *Client) ListUserIssues(ctx context.Context, opts ListUserIssuesOptions) ([]*Issue, error) {
var issues []*Issue
query := opts.toQuery()
if opts.Filter != "" {
query += "&filter=" + opts.Filter
}
if opts.State != "" {
query += "&state=" + opts.State
}
if opts.Labels != "" {
query += "&labels=" + opts.Labels
}
if opts.Sort != "" {
query += "&sort=" + opts.Sort
}
if opts.Direction != "" {
query += "&direction=" + opts.Direction
}
if opts.Since != "" {
query += "&since=" + opts.Since
}
err := c.doRequest(ctx, http.MethodGet, fmt.Sprintf("/user/issues?%s", query), nil, &issues)
if err != nil {
return nil, err
}
return issues, nil
}
func (c *Client) ListOrgIssues(ctx context.Context, org string, opts ListUserIssuesOptions) ([]*Issue, error) {
var issues []*Issue
query := opts.toQuery()
if opts.Filter != "" {
query += "&filter=" + opts.Filter
}
if opts.State != "" {
query += "&state=" + opts.State
}
if opts.Labels != "" {
query += "&labels=" + opts.Labels
}
if opts.Sort != "" {
query += "&sort=" + opts.Sort
}
if opts.Direction != "" {
query += "&direction=" + opts.Direction
}
err := c.doRequest(ctx, http.MethodGet, fmt.Sprintf("/orgs/%s/issues?%s", org, query), nil, &issues)
if err != nil {
return nil, err
}
return issues, nil
}
func (c *Client) ListRepoAllIssueComments(ctx context.Context, owner, repo string, opts ListOptions) ([]*IssueComment, error) {
var comments []*IssueComment
err := c.doRequest(ctx, http.MethodGet, fmt.Sprintf("/repos/%s/%s/issues/comments?%s", owner, repo, opts.toQuery()), nil, &comments)
if err != nil {
return nil, err
}
return comments, nil
}
func (c *Client) GetIssueComment(ctx context.Context, owner, repo string, commentID int64) (*IssueComment, error) {
var comment IssueComment
err := c.doRequest(ctx, http.MethodGet, fmt.Sprintf("/repos/%s/%s/issues/comments/%d", owner, repo, commentID), nil, &comment)
if err != nil {
return nil, err
}
return &comment, nil
}
type IssueOperateLog struct {
ID int64 `json:"id"`
Action string `json:"action"`
CreatedAt string `json:"created_at"`
User *User `json:"user"`
}
func (c *Client) GetIssueOperateLogs(ctx context.Context, owner, repo string, number int) ([]*IssueOperateLog, error) {
var logs []*IssueOperateLog
err := c.doRequest(ctx, http.MethodGet, fmt.Sprintf("/repos/%s/%s/issues/%d/operate_logs", owner, repo, number), nil, &logs)
if err != nil {
return nil, err
}
return logs, nil
}
func (c *Client) GetIssueLinkedPRs(ctx context.Context, owner, repo string, number int) ([]*PullRequest, error) {
var prs []*PullRequest
err := c.doRequest(ctx, http.MethodGet, fmt.Sprintf("/repos/%s/%s/issues/%d/pull_requests", owner, repo, number), nil, &prs)
if err != nil {
return nil, err
}
return prs, nil
}
func (c *Client) ListEnterpriseIssues(ctx context.Context, enterprise string, opts ListUserIssuesOptions) ([]*Issue, error) {
var issues []*Issue
query := opts.toQuery()
if opts.Filter != "" {
query += "&filter=" + opts.Filter
}
if opts.State != "" {
query += "&state=" + opts.State
}
if opts.Labels != "" {
query += "&labels=" + opts.Labels
}
if opts.Sort != "" {
query += "&sort=" + opts.Sort
}
if opts.Direction != "" {
query += "&direction=" + opts.Direction
}
err := c.doRequest(ctx, http.MethodGet, fmt.Sprintf("/enterprises/%s/issues?%s", enterprise, query), nil, &issues)
if err != nil {
return nil, err
}
return issues, nil
}
func (c *Client) GetEnterpriseIssue(ctx context.Context, enterprise string, number int) (*Issue, error) {
var issue Issue
err := c.doRequest(ctx, http.MethodGet, fmt.Sprintf("/enterprises/%s/issues/%d", enterprise, number), nil, &issue)
if err != nil {
return nil, err
}
return &issue, nil
}
func (c *Client) ListEnterpriseIssueComments(ctx context.Context, enterprise string, number int, opts ListOptions) ([]*IssueComment, error) {
var comments []*IssueComment
err := c.doRequest(ctx, http.MethodGet, fmt.Sprintf("/enterprises/%s/issues/%d/comments?%s", enterprise, number, opts.toQuery()), nil, &comments)
if err != nil {
return nil, err
}
return comments, nil
}
func (c *Client) ListEnterpriseIssueLabels(ctx context.Context, enterprise string, issueID int64) ([]*Label, error) {
var labels []*Label
err := c.doRequest(ctx, http.MethodGet, fmt.Sprintf("/enterprises/%s/issues/%d/labels", enterprise, issueID), nil, &labels)
if err != nil {
return nil, err
}
return labels, nil
}