-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
issue_statuses.go
42 lines (37 loc) · 867 Bytes
/
issue_statuses.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
package redmine
import (
"encoding/json"
"errors"
"strings"
)
type issueStatusesResult struct {
IssueStatuses []IssueStatus `json:"issue_statuses"`
}
type IssueStatus struct {
Id int `json:"id"`
Name string `json:"name"`
IsDefault bool `json:"is_default"`
IsClosed bool `json:"is_closed"`
}
func (c *Client) IssueStatuses() ([]IssueStatus, error) {
res, err := c.Get(c.endpoint + "/issue_statuses.json?key=" + c.apikey + c.getPaginationClause())
if err != nil {
return nil, err
}
defer res.Body.Close()
decoder := json.NewDecoder(res.Body)
var r issueStatusesResult
if res.StatusCode != 200 {
var er errorsResult
err = decoder.Decode(&er)
if err == nil {
err = errors.New(strings.Join(er.Errors, "\n"))
}
} else {
err = decoder.Decode(&r)
}
if err != nil {
return nil, err
}
return r.IssueStatuses, nil
}