-
Notifications
You must be signed in to change notification settings - Fork 0
/
pullrequest.go
57 lines (50 loc) · 1.71 KB
/
pullrequest.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
package goscm
import (
"strconv"
)
type PullRequestContainer struct {
Page int `json:"page"`
PageTotal int `json:"pageTotal"`
Embedded struct {
PullRequests []PullRequest `json:"pullRequests"`
} `json:"_embedded"`
}
type PullRequest struct {
Id string `json:"id"`
Title string `json:"title"`
Description string `json:"description"`
Source string `json:"source"`
Target string `json:"target"`
Status string `json:"status"`
CreationDate string `json:"creationDate,omitempty"`
CloseDate string `json:"closeDate,omitempty"`
Labels []string `json:"labels"`
}
type PullRequestListFilter struct {
Status string `json:"status"`
Limit int `json:"limit"`
}
func (c *Client) NewPullRequestListFilter() *PullRequestListFilter {
filter := PullRequestListFilter{}
filter.Status = "OPEN"
filter.Limit = 10
return &filter
}
// ListPullRequests List all pull requests for repository
func (c *Client) ListPullRequests(namespace string, name string, filter *PullRequestListFilter) (PullRequestContainer, error) {
pullRequestContainer := PullRequestContainer{}
err := c.getJson("/api/v2/pull-requests/"+namespace+"/"+name+"?status="+filter.Status+"&pageSize="+strconv.FormatInt(int64(filter.Limit), 10), &pullRequestContainer, nil)
if err != nil {
return PullRequestContainer{}, err
}
return pullRequestContainer, nil
}
// GetPullRequest Get single pull request for repository
func (c *Client) GetPullRequest(namespace string, name string, id string) (PullRequest, error) {
pullRequest := PullRequest{}
err := c.getJson("/api/v2/pull-requests/"+namespace+"/"+name+"/"+id, &pullRequest, nil)
if err != nil {
return PullRequest{}, err
}
return pullRequest, err
}