ListIssues: add milestones filter (#327)

use string.Join

Code Format

add test case

add Milestones to ListIssueOption

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/327
Reviewed-by: Andrew Thornton <art27@cantab.net>
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
6543 2020-05-20 06:48:06 +00:00
parent 70863f4458
commit f224b4e50c
2 changed files with 28 additions and 14 deletions

View file

@ -56,10 +56,11 @@ type Issue struct {
// ListIssueOption list issue options
type ListIssueOption struct {
ListOptions
State StateType
Type IssueType
Labels []string
KeyWord string
State StateType
Type IssueType
Labels []string
Milestones []string
KeyWord string
}
// StateType issue state type
@ -89,24 +90,25 @@ const (
// QueryEncode turns options into querystring argument
func (opt *ListIssueOption) QueryEncode() string {
query := opt.getURLQuery()
if len(opt.State) > 0 {
query.Add("state", string(opt.State))
}
if len(opt.Labels) > 0 {
var lq string
for _, l := range opt.Labels {
if len(lq) > 0 {
lq += ","
}
lq += l
}
query.Add("labels", lq)
query.Add("labels", strings.Join(opt.Labels, ","))
}
if len(opt.KeyWord) > 0 {
query.Add("q", opt.KeyWord)
}
query.Add("type", string(opt.Type))
if len(opt.Milestones) > 0 {
query.Add("milestones", strings.Join(opt.Milestones, ","))
}
return query.Encode()
}

View file

@ -71,12 +71,12 @@ func listIssues(t *testing.T, c *Client) {
log.Println("== TestListIssues ==")
issues, err := c.ListRepoIssues("test01", "IssueTestsRepo", ListIssueOption{
Labels: []string{"Label2"},
Labels: []string{"Label1", "Label2"},
KeyWord: "",
State: "all",
})
assert.NoError(t, err)
assert.Len(t, issues, 2)
assert.Len(t, issues, 1)
issues, err = c.ListIssues(ListIssueOption{
Labels: []string{"Label2"},
@ -86,6 +86,18 @@ func listIssues(t *testing.T, c *Client) {
assert.NoError(t, err)
assert.Len(t, issues, 1)
issues, err = c.ListRepoIssues("test01", "IssueTestsRepo", ListIssueOption{
Milestones: []string{"mile1"},
State: "all",
})
assert.NoError(t, err)
assert.Len(t, issues, 3)
for i := range issues {
if assert.NotNil(t, issues[i].Milestone) {
assert.EqualValues(t, "mile1", issues[i].Milestone.Title)
}
}
issues, err = c.ListRepoIssues("test01", "IssueTestsRepo", ListIssueOption{})
assert.NoError(t, err)
assert.Len(t, issues, 3)