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:
parent
70863f4458
commit
f224b4e50c
2 changed files with 28 additions and 14 deletions
|
@ -56,10 +56,11 @@ type Issue struct {
|
||||||
// ListIssueOption list issue options
|
// ListIssueOption list issue options
|
||||||
type ListIssueOption struct {
|
type ListIssueOption struct {
|
||||||
ListOptions
|
ListOptions
|
||||||
State StateType
|
State StateType
|
||||||
Type IssueType
|
Type IssueType
|
||||||
Labels []string
|
Labels []string
|
||||||
KeyWord string
|
Milestones []string
|
||||||
|
KeyWord string
|
||||||
}
|
}
|
||||||
|
|
||||||
// StateType issue state type
|
// StateType issue state type
|
||||||
|
@ -89,24 +90,25 @@ const (
|
||||||
// QueryEncode turns options into querystring argument
|
// QueryEncode turns options into querystring argument
|
||||||
func (opt *ListIssueOption) QueryEncode() string {
|
func (opt *ListIssueOption) QueryEncode() string {
|
||||||
query := opt.getURLQuery()
|
query := opt.getURLQuery()
|
||||||
|
|
||||||
if len(opt.State) > 0 {
|
if len(opt.State) > 0 {
|
||||||
query.Add("state", string(opt.State))
|
query.Add("state", string(opt.State))
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(opt.Labels) > 0 {
|
if len(opt.Labels) > 0 {
|
||||||
var lq string
|
query.Add("labels", strings.Join(opt.Labels, ","))
|
||||||
for _, l := range opt.Labels {
|
|
||||||
if len(lq) > 0 {
|
|
||||||
lq += ","
|
|
||||||
}
|
|
||||||
lq += l
|
|
||||||
}
|
|
||||||
query.Add("labels", lq)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(opt.KeyWord) > 0 {
|
if len(opt.KeyWord) > 0 {
|
||||||
query.Add("q", opt.KeyWord)
|
query.Add("q", opt.KeyWord)
|
||||||
}
|
}
|
||||||
|
|
||||||
query.Add("type", string(opt.Type))
|
query.Add("type", string(opt.Type))
|
||||||
|
|
||||||
|
if len(opt.Milestones) > 0 {
|
||||||
|
query.Add("milestones", strings.Join(opt.Milestones, ","))
|
||||||
|
}
|
||||||
|
|
||||||
return query.Encode()
|
return query.Encode()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,12 +71,12 @@ func listIssues(t *testing.T, c *Client) {
|
||||||
log.Println("== TestListIssues ==")
|
log.Println("== TestListIssues ==")
|
||||||
|
|
||||||
issues, err := c.ListRepoIssues("test01", "IssueTestsRepo", ListIssueOption{
|
issues, err := c.ListRepoIssues("test01", "IssueTestsRepo", ListIssueOption{
|
||||||
Labels: []string{"Label2"},
|
Labels: []string{"Label1", "Label2"},
|
||||||
KeyWord: "",
|
KeyWord: "",
|
||||||
State: "all",
|
State: "all",
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, issues, 2)
|
assert.Len(t, issues, 1)
|
||||||
|
|
||||||
issues, err = c.ListIssues(ListIssueOption{
|
issues, err = c.ListIssues(ListIssueOption{
|
||||||
Labels: []string{"Label2"},
|
Labels: []string{"Label2"},
|
||||||
|
@ -86,6 +86,18 @@ func listIssues(t *testing.T, c *Client) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, issues, 1)
|
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{})
|
issues, err = c.ListRepoIssues("test01", "IssueTestsRepo", ListIssueOption{})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, issues, 3)
|
assert.Len(t, issues, 3)
|
||||||
|
|
Loading…
Reference in a new issue