Use StateType (#265)

use StateType

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/265
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-by: lafriks <lafriks@noreply.gitea.io>
This commit is contained in:
6543 2020-02-04 07:58:46 +00:00 committed by lafriks
parent d7fb2dc914
commit 524bda1e14
5 changed files with 24 additions and 24 deletions

View File

@ -46,13 +46,24 @@ type Issue struct {
// ListIssueOption list issue options
type ListIssueOption struct {
Page int
// open, closed, all
State string
Page int
State StateType
Labels []string
KeyWord string
}
// StateType issue state type
type StateType string
const (
// StateOpen pr is opend
StateOpen StateType = "open"
// StateClosed pr is closed
StateClosed StateType = "closed"
// StateAll is all
StateAll StateType = "all"
)
// QueryEncode turns options into querystring argument
func (opt *ListIssueOption) QueryEncode() string {
query := make(url.Values)
@ -60,7 +71,7 @@ func (opt *ListIssueOption) QueryEncode() string {
query.Add("page", fmt.Sprintf("%d", opt.Page))
}
if len(opt.State) > 0 {
query.Add("state", opt.State)
query.Add("state", string(opt.State))
}
if len(opt.Labels) > 0 {
var lq string
@ -134,7 +145,7 @@ type EditIssueOption struct {
Assignee *string `json:"assignee"`
Assignees []string `json:"assignees"`
Milestone *int64 `json:"milestone"`
State *string `json:"state"`
State *StateType `json:"state"`
Deadline *time.Time `json:"due_date"`
}

View File

@ -12,18 +12,6 @@ import (
"time"
)
// StateType issue state type
type StateType string
const (
// StateOpen pr is opend
StateOpen StateType = "open"
// StateClosed pr is closed
StateClosed StateType = "closed"
// StateAll is all
StateAll StateType = "all"
)
// Milestone milestone is a collection of issues on one repository
type Milestone struct {
ID int64 `json:"id"`

View File

@ -86,9 +86,11 @@ func editIssues(t *testing.T, c *Client) {
assert.NoError(t, err)
body := "123 test and go"
state := StateClosed
issueNew, err := c.EditIssue(issue.Poster.UserName, issue.Repository.Name, issue.Index, EditIssueOption{
Title: "Edited",
Body: &body,
State: &state,
})
assert.NoError(t, err)
assert.EqualValues(t, issue.ID, issueNew.ID)
@ -117,5 +119,5 @@ func listIssues(t *testing.T, c *Client) {
issues, err = c.ListRepoIssues("test01", "IssueTestsRepo", ListIssueOption{})
assert.NoError(t, err)
assert.Len(t, issues, 4)
assert.Len(t, issues, 3)
}

View File

@ -59,9 +59,8 @@ type PullRequest struct {
// ListPullRequestsOptions options for listing pull requests
type ListPullRequestsOptions struct {
Page int `json:"page"`
// open, closed, all
State string `json:"state"`
Page int `json:"page"`
State StateType `json:"state"`
// oldest, recentupdate, leastupdate, mostcomment, leastcomment, priority
Sort string `json:"sort"`
Milestone int64 `json:"milestone"`
@ -78,7 +77,7 @@ func (c *Client) ListRepoPullRequests(owner, repo string, opt ListPullRequestsOp
query.Add("page", fmt.Sprintf("%d", opt.Page))
}
if len(opt.State) > 0 {
query.Add("state", opt.State)
query.Add("state", string(opt.State))
}
if len(opt.Sort) > 0 {
query.Add("sort", opt.Sort)
@ -129,7 +128,7 @@ type EditPullRequestOption struct {
Assignees []string `json:"assignees"`
Milestone int64 `json:"milestone"`
Labels []int64 `json:"labels"`
State *string `json:"state"`
State *StateType `json:"state"`
Deadline *time.Time `json:"due_date"`
}

View File

@ -26,7 +26,7 @@ func TestPull(t *testing.T) {
// ListRepoPullRequests list PRs of one repository
pulls, err := c.ListRepoPullRequests(user.UserName, repoName, ListPullRequestsOptions{
Page: 1,
State: "all",
State: StateAll,
Sort: "leastupdate",
})
assert.NoError(t, err)