Add ListIssueCommentOptions for optional param #243
|
@ -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 New Issue
Block a user