Add ListIssueCommentOptions for optional param (#243)
Merge branch 'master' into impruve-ListXIssueComments Remove ListUserIssues() ... (#262) Merge branch 'master' into rm-ListUserIssues correct version (#257) Merge branch 'master' into targed-version Extend Issue Struct (#258) fix extend IssueTest add Repository to Issue struct Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/258 Reviewed-by: Andrew Thornton <art27@cantab.net> Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Merge branch 'master' into targed-version format code (#245) fix if test is to fast remove lgtm bot config (gitea handle this now) format code Add GetIssueComment (#216) Merge branch 'master' into update-comment-api Fix & Refactor UserApp Functions (#247) Merge branch 'master' into refactor-user-app Add SearchRepo API Call (#254) Merge branch 'master' into search_repo IssueSubscribtion: Check http Status responce (#242) Merge branch 'master' into impruve-issueWatch Refactor RepoWatch (#241) Merge branch 'master' into refactor-repoWatch 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> Merge branch 'master' into refactor-repoWatch 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> add TEST fix GetMyWatchedRepos [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> refactor RepoWatch * add CheckRepoWatch * add GetMyWatchedRepos * minimize func_options on GetWatchedRepos * WatchRepo return nil/error * UnWatchRepo return nil/error Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/241 Reviewed-by: Andrew Thornton <art27@cantab.net> Reviewed-by: Andrew Thornton <art27@cantab.net> Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Merge branch 'master' into impruve-issueWatch 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-au... Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: spawn2kill <spawn2kill@noreply.gitea.io> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/243 Reviewed-by: Andrew Thornton <art27@cantab.net> Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
parent
16c2690af4
commit
617741019e
3 changed files with 29 additions and 13 deletions
|
@ -56,13 +56,6 @@ type ListIssueOption struct {
|
|||
// QueryEncode turns options into querystring argument
|
||||
func (opt *ListIssueOption) QueryEncode() string {
|
||||
query := make(url.Values)
|
||||
if opt.Page > 0 {
|
||||
query.Add("page", fmt.Sprintf("%d", opt.Page))
|
||||
}
|
||||
if len(opt.State) > 0 {
|
||||
query.Add("state", opt.State)
|
||||
}
|
||||
|
||||
if opt.Page > 0 {
|
||||
query.Add("page", fmt.Sprintf("%d", opt.Page))
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -25,16 +26,38 @@ type Comment struct {
|
|||
Updated time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// ListIssueCommentOptions list comment options
|
||||
type ListIssueCommentOptions struct {
|
||||
Since time.Time
|
||||
Before time.Time
|
||||
}
|
||||
|
||||
// QueryEncode turns options into querystring argument
|
||||
func (opt *ListIssueCommentOptions) QueryEncode() string {
|
||||
query := make(url.Values)
|
||||
if !opt.Since.IsZero() {
|
||||
query.Add("since", opt.Since.Format(time.RFC3339))
|
||||
}
|
||||
if !opt.Before.IsZero() {
|
||||
query.Add("before", opt.Before.Format(time.RFC3339))
|
||||
}
|
||||
return query.Encode()
|
||||
}
|
||||
|
||||
// ListIssueComments list comments on an issue.
|
||||
func (c *Client) ListIssueComments(owner, repo string, index int64) ([]*Comment, error) {
|
||||
func (c *Client) ListIssueComments(owner, repo string, index int64, opt ListIssueCommentOptions) ([]*Comment, error) {
|
||||
link, _ := url.Parse(fmt.Sprintf("/repos/%s/%s/issues/%d/comments", owner, repo, index))
|
||||
link.RawQuery = opt.QueryEncode()
|
||||
comments := make([]*Comment, 0, 10)
|
||||
return comments, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/comments", owner, repo, index), nil, nil, &comments)
|
||||
return comments, c.getParsedResponse("GET", link.String(), nil, nil, &comments)
|
||||
}
|
||||
|
||||
// ListRepoIssueComments list comments for a given repo.
|
||||
func (c *Client) ListRepoIssueComments(owner, repo string) ([]*Comment, error) {
|
||||
func (c *Client) ListRepoIssueComments(owner, repo string, opt ListIssueCommentOptions) ([]*Comment, error) {
|
||||
link, _ := url.Parse(fmt.Sprintf("/repos/%s/%s/issues/comments", owner, repo))
|
||||
link.RawQuery = opt.QueryEncode()
|
||||
comments := make([]*Comment, 0, 10)
|
||||
return comments, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/comments", owner, repo), nil, nil, &comments)
|
||||
return comments, c.getParsedResponse("GET", link.String(), nil, nil, &comments)
|
||||
}
|
||||
|
||||
// GetIssueComment get a comment for a given repo by id.
|
||||
|
|
|
@ -51,12 +51,12 @@ func TestIssueComment(t *testing.T) {
|
|||
assert.NoError(t, c.AdminDeleteUser(tUser3.UserName))
|
||||
|
||||
// ListRepoIssueComments
|
||||
comments, err := c.ListRepoIssueComments(user.UserName, repo.Name)
|
||||
comments, err := c.ListRepoIssueComments(user.UserName, repo.Name, ListIssueCommentOptions{})
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, comments, 7)
|
||||
|
||||
// ListIssueComments
|
||||
comments, err = c.ListIssueComments(user.UserName, repo.Name, 2)
|
||||
comments, err = c.ListIssueComments(user.UserName, repo.Name, 2, ListIssueCommentOptions{})
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, comments, 3)
|
||||
|
||||
|
|
Loading…
Reference in a new issue