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:
parent
d7fb2dc914
commit
524bda1e14
5 changed files with 24 additions and 24 deletions
|
@ -47,12 +47,23 @@ type Issue struct {
|
||||||
// ListIssueOption list issue options
|
// ListIssueOption list issue options
|
||||||
type ListIssueOption struct {
|
type ListIssueOption struct {
|
||||||
Page int
|
Page int
|
||||||
// open, closed, all
|
State StateType
|
||||||
State string
|
|
||||||
Labels []string
|
Labels []string
|
||||||
KeyWord 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
|
// QueryEncode turns options into querystring argument
|
||||||
func (opt *ListIssueOption) QueryEncode() string {
|
func (opt *ListIssueOption) QueryEncode() string {
|
||||||
query := make(url.Values)
|
query := make(url.Values)
|
||||||
|
@ -60,7 +71,7 @@ func (opt *ListIssueOption) QueryEncode() string {
|
||||||
query.Add("page", fmt.Sprintf("%d", opt.Page))
|
query.Add("page", fmt.Sprintf("%d", opt.Page))
|
||||||
}
|
}
|
||||||
if len(opt.State) > 0 {
|
if len(opt.State) > 0 {
|
||||||
query.Add("state", opt.State)
|
query.Add("state", string(opt.State))
|
||||||
}
|
}
|
||||||
if len(opt.Labels) > 0 {
|
if len(opt.Labels) > 0 {
|
||||||
var lq string
|
var lq string
|
||||||
|
@ -134,7 +145,7 @@ type EditIssueOption struct {
|
||||||
Assignee *string `json:"assignee"`
|
Assignee *string `json:"assignee"`
|
||||||
Assignees []string `json:"assignees"`
|
Assignees []string `json:"assignees"`
|
||||||
Milestone *int64 `json:"milestone"`
|
Milestone *int64 `json:"milestone"`
|
||||||
State *string `json:"state"`
|
State *StateType `json:"state"`
|
||||||
Deadline *time.Time `json:"due_date"`
|
Deadline *time.Time `json:"due_date"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,18 +12,6 @@ import (
|
||||||
"time"
|
"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
|
// Milestone milestone is a collection of issues on one repository
|
||||||
type Milestone struct {
|
type Milestone struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
|
|
|
@ -86,9 +86,11 @@ func editIssues(t *testing.T, c *Client) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
body := "123 test and go"
|
body := "123 test and go"
|
||||||
|
state := StateClosed
|
||||||
issueNew, err := c.EditIssue(issue.Poster.UserName, issue.Repository.Name, issue.Index, EditIssueOption{
|
issueNew, err := c.EditIssue(issue.Poster.UserName, issue.Repository.Name, issue.Index, EditIssueOption{
|
||||||
Title: "Edited",
|
Title: "Edited",
|
||||||
Body: &body,
|
Body: &body,
|
||||||
|
State: &state,
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, issue.ID, issueNew.ID)
|
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{})
|
issues, err = c.ListRepoIssues("test01", "IssueTestsRepo", ListIssueOption{})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, issues, 4)
|
assert.Len(t, issues, 3)
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,8 +60,7 @@ type PullRequest struct {
|
||||||
// ListPullRequestsOptions options for listing pull requests
|
// ListPullRequestsOptions options for listing pull requests
|
||||||
type ListPullRequestsOptions struct {
|
type ListPullRequestsOptions struct {
|
||||||
Page int `json:"page"`
|
Page int `json:"page"`
|
||||||
// open, closed, all
|
State StateType `json:"state"`
|
||||||
State string `json:"state"`
|
|
||||||
// oldest, recentupdate, leastupdate, mostcomment, leastcomment, priority
|
// oldest, recentupdate, leastupdate, mostcomment, leastcomment, priority
|
||||||
Sort string `json:"sort"`
|
Sort string `json:"sort"`
|
||||||
Milestone int64 `json:"milestone"`
|
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))
|
query.Add("page", fmt.Sprintf("%d", opt.Page))
|
||||||
}
|
}
|
||||||
if len(opt.State) > 0 {
|
if len(opt.State) > 0 {
|
||||||
query.Add("state", opt.State)
|
query.Add("state", string(opt.State))
|
||||||
}
|
}
|
||||||
if len(opt.Sort) > 0 {
|
if len(opt.Sort) > 0 {
|
||||||
query.Add("sort", opt.Sort)
|
query.Add("sort", opt.Sort)
|
||||||
|
@ -129,7 +128,7 @@ type EditPullRequestOption struct {
|
||||||
Assignees []string `json:"assignees"`
|
Assignees []string `json:"assignees"`
|
||||||
Milestone int64 `json:"milestone"`
|
Milestone int64 `json:"milestone"`
|
||||||
Labels []int64 `json:"labels"`
|
Labels []int64 `json:"labels"`
|
||||||
State *string `json:"state"`
|
State *StateType `json:"state"`
|
||||||
Deadline *time.Time `json:"due_date"`
|
Deadline *time.Time `json:"due_date"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ func TestPull(t *testing.T) {
|
||||||
// ListRepoPullRequests list PRs of one repository
|
// ListRepoPullRequests list PRs of one repository
|
||||||
pulls, err := c.ListRepoPullRequests(user.UserName, repoName, ListPullRequestsOptions{
|
pulls, err := c.ListRepoPullRequests(user.UserName, repoName, ListPullRequestsOptions{
|
||||||
Page: 1,
|
Page: 1,
|
||||||
State: "all",
|
State: StateAll,
|
||||||
Sort: "leastupdate",
|
Sort: "leastupdate",
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
Loading…
Reference in a new issue