Add ListMilestoneOption to ListRepoMilestones (#244)
use StateType use PageSize adjut test since gitea bug got fixed (#gitea/10047) add TestMilestones add optional ListMilestoneOption format Add ListOptions struct (#249) same struct as in models/list_options.go add mising license header add ListOptions struct Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/249 Reviewed-by: Andrew Thornton <art27@cantab.net> Reviewed-by: lafriks <lafriks@noreply.gitea.io> [README] add import path (#239) add import path add import path to readme Changelog v0.11.0 (#235) Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/235 Reviewed-by: lafriks <lafriks@noreply.gitea.io> Reviewed-by: Andrew Thornton <art27@cantab.net> Reviewed-by: John Olheiser <john.olheiser@gmail.com> Add TestMyUser (#237) Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/237 Reviewed-by: lafriks <lafriks@noreply.gitea.io> Reviewed-by: Andrew Thornton <art27@cantab.net> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/239 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: John Olheiser <john.olheiser@gmail.com> Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/244 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
parent
0cf299db6f
commit
d96f9692df
3 changed files with 85 additions and 3 deletions
|
@ -117,8 +117,8 @@ func (c *Client) ListUserIssues(opt ListIssueOption) ([]*Issue, error) {
|
|||
// ListRepoIssues returns all issues for a given repository
|
||||
func (c *Client) ListRepoIssues(owner, repo string, opt ListIssueOption) ([]*Issue, error) {
|
||||
link, _ := url.Parse(fmt.Sprintf("/repos/%s/%s/issues", owner, repo))
|
||||
issues := make([]*Issue, 0, 10)
|
||||
link.RawQuery = opt.QueryEncode()
|
||||
issues := make([]*Issue, 0, 10)
|
||||
return issues, c.getParsedResponse("GET", link.String(), jsonHeader, nil, &issues)
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -35,10 +36,34 @@ type Milestone struct {
|
|||
Deadline *time.Time `json:"due_on"`
|
||||
}
|
||||
|
||||
// ListMilestoneOption list milestone options
|
||||
type ListMilestoneOption struct {
|
||||
ListOptions
|
||||
// open, closed, all
|
||||
State StateType
|
||||
}
|
||||
|
||||
// QueryEncode turns options into querystring argument
|
||||
func (opt *ListMilestoneOption) QueryEncode() string {
|
||||
query := make(url.Values)
|
||||
if opt.Page > 0 {
|
||||
query.Add("page", fmt.Sprintf("%d", opt.Page))
|
||||
}
|
||||
if opt.PageSize > 0 {
|
||||
query.Add("limit", fmt.Sprintf("%d", opt.PageSize))
|
||||
}
|
||||
if opt.State != "" {
|
||||
query.Add("state", string(opt.State))
|
||||
}
|
||||
return query.Encode()
|
||||
}
|
||||
|
||||
// ListRepoMilestones list all the milestones of one repository
|
||||
func (c *Client) ListRepoMilestones(owner, repo string) ([]*Milestone, error) {
|
||||
func (c *Client) ListRepoMilestones(owner, repo string, opt ListMilestoneOption) ([]*Milestone, error) {
|
||||
link, _ := url.Parse(fmt.Sprintf("/repos/%s/%s/milestones", owner, repo))
|
||||
link.RawQuery = opt.QueryEncode()
|
||||
milestones := make([]*Milestone, 0, 10)
|
||||
return milestones, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/milestones", owner, repo), nil, nil, &milestones)
|
||||
return milestones, c.getParsedResponse("GET", link.String(), nil, nil, &milestones)
|
||||
}
|
||||
|
||||
// GetMilestone get one milestone by repo name and milestone id
|
||||
|
|
57
gitea/issue_milestone_test.go
Normal file
57
gitea/issue_milestone_test.go
Normal file
|
@ -0,0 +1,57 @@
|
|||
// Copyright 2020 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package gitea
|
||||
|
||||
import (
|
||||
"log"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestMilestones(t *testing.T) {
|
||||
log.Println("== TestMilestones ==")
|
||||
c := newTestClient()
|
||||
|
||||
repo, _ := createTestRepo(t, "TestMilestones", c)
|
||||
now := time.Now()
|
||||
future := time.Unix(1896134400, 0) //2030-02-01
|
||||
closed := "closed"
|
||||
|
||||
// CreateMilestone 4x
|
||||
m1, err := c.CreateMilestone(repo.Owner.UserName, repo.Name, CreateMilestoneOption{Title: "v1.0", Description: "First Version", Deadline: &now})
|
||||
assert.NoError(t, err)
|
||||
_, err = c.CreateMilestone(repo.Owner.UserName, repo.Name, CreateMilestoneOption{Title: "v2.0", Description: "Second Version", Deadline: &future})
|
||||
assert.NoError(t, err)
|
||||
_, err = c.CreateMilestone(repo.Owner.UserName, repo.Name, CreateMilestoneOption{Title: "v3.0", Description: "Third Version", Deadline: nil})
|
||||
assert.NoError(t, err)
|
||||
m4, err := c.CreateMilestone(repo.Owner.UserName, repo.Name, CreateMilestoneOption{Title: "temp", Description: "part time milestone"})
|
||||
assert.NoError(t, err)
|
||||
|
||||
// EditMilestone
|
||||
m1, err = c.EditMilestone(repo.Owner.UserName, repo.Name, m1.ID, EditMilestoneOption{Description: &closed, State: &closed})
|
||||
assert.NoError(t, err)
|
||||
|
||||
// DeleteMilestone
|
||||
assert.NoError(t, c.DeleteMilestone(repo.Owner.UserName, repo.Name, m4.ID))
|
||||
|
||||
// ListRepoMilestones
|
||||
ml, err := c.ListRepoMilestones(repo.Owner.UserName, repo.Name, ListMilestoneOption{})
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, ml, 2)
|
||||
ml, err = c.ListRepoMilestones(repo.Owner.UserName, repo.Name, ListMilestoneOption{State: "closed"})
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, ml, 1)
|
||||
ml, err = c.ListRepoMilestones(repo.Owner.UserName, repo.Name, ListMilestoneOption{State: "all"})
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, ml, 3)
|
||||
|
||||
// GetMilestone
|
||||
_, err = c.GetMilestone(repo.Owner.UserName, repo.Name, m4.ID)
|
||||
assert.Error(t, err)
|
||||
m, err := c.GetMilestone(repo.Owner.UserName, repo.Name, m1.ID)
|
||||
assert.EqualValues(t, m1, m)
|
||||
}
|
Loading…
Reference in a new issue