-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_issue.go
85 lines (75 loc) · 2.46 KB
/
api_issue.go
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
package redmine
import (
"encoding/json"
"fmt"
)
type Issue struct {
ID int `json:"id"`
Project IdName `json:"project"`
Tracker IdName `json:"tracker"`
Status IdName `json:"status"`
Priority IdName `json:"priority"`
Author IdName `json:"author"`
AssignedTo *IdName `json:"assigned_to"`
FixedVersion *IdName `json:"fixed_version"`
Parent *IdName `json:"parent"`
Subject string `json:"subject"`
Description string `json:"description"`
StartDate *string `json:"start_date"`
DueDate *string `json:"due_date"`
DoneRatio int `json:"done_ratio"`
IsPrivate bool `json:"is_private"`
EstimatedHours *float64 `json:"estimated_hours"`
TotalEstimatedHours *float64 `json:"total_estimated_hours"`
SpentHours float64 `json:"spent_hours"`
TotalSpentHours float64 `json:"total_spent_hours"`
CustomFields []CustomField `json:"custom_fields"`
CreatedOn string `json:"created_on"`
UpdatedOn string `json:"updated_on"`
ClosedOn *string `json:"closed_on"`
}
func (c *Client) GetIssueByID(id int, opts ...ReqOption) (*Issue, error) {
endpoint := fmt.Sprintf("/issues/%d.json", id)
o := reqOptions(opts...)
respBodyBytes, err := c.getRequest(endpoint, o.query)
if err != nil {
return nil, err
}
resp := struct {
Issue Issue `json:"issue"`
}{}
if err := json.Unmarshal(respBodyBytes, &resp); err != nil {
return nil, fmt.Errorf("json unmarshal error: %v", err)
}
return &resp.Issue, nil
}
func (c *Client) GetIssues(opts ...ReqOption) ([]*Issue, error) {
endpoint := "/issues.json"
o := reqOptions(opts...)
items := []*Issue{}
filter := &listFilter{query: o.query}
for ; ; filter.nextPage() {
respBodyBytes, err := c.getRequest(endpoint, filter.encode())
if err != nil {
return nil, err
}
resp := struct {
listResponseAttrs
Issues []*Issue `json:"issues"`
}{}
if err := json.Unmarshal(respBodyBytes, &resp); err != nil {
return nil, fmt.Errorf("json unmarshal error: %v", err)
}
if len(resp.Issues) == 0 {
goto end
}
for _, item := range resp.Issues {
items = append(items, item)
if o.limit > 0 && len(items) >= o.limit {
goto end
}
}
}
end:
return items, nil
}