fix(discussion/client): change list return type to pointer
Signed-off-by: Babak K. Shandiz <babakks@github.com>
This commit is contained in:
parent
e6befd5efd
commit
2a46a9d733
5 changed files with 43 additions and 43 deletions
|
|
@ -9,8 +9,8 @@ import "github.com/cli/cli/v2/internal/ghrepo"
|
|||
|
||||
// DiscussionClient defines operations for interacting with the GitHub Discussions API.
|
||||
type DiscussionClient interface {
|
||||
List(repo ghrepo.Interface, filters ListFilters, after string, limit int) (DiscussionListResult, error)
|
||||
Search(repo ghrepo.Interface, filters SearchFilters, after string, limit int) (DiscussionListResult, error)
|
||||
List(repo ghrepo.Interface, filters ListFilters, after string, limit int) (*DiscussionListResult, error)
|
||||
Search(repo ghrepo.Interface, filters SearchFilters, after string, limit int) (*DiscussionListResult, error)
|
||||
GetByNumber(repo ghrepo.Interface, number int) (*Discussion, error)
|
||||
GetWithComments(repo ghrepo.Interface, number int, commentLimit int, order string) (*Discussion, error)
|
||||
ListCategories(repo ghrepo.Interface) ([]DiscussionCategory, error)
|
||||
|
|
|
|||
|
|
@ -131,9 +131,9 @@ const discussionFields = `
|
|||
createdAt updatedAt closedAt locked
|
||||
`
|
||||
|
||||
func (c *discussionClient) List(repo ghrepo.Interface, filters ListFilters, after string, limit int) (DiscussionListResult, error) {
|
||||
func (c *discussionClient) List(repo ghrepo.Interface, filters ListFilters, after string, limit int) (*DiscussionListResult, error) {
|
||||
if limit <= 0 {
|
||||
return DiscussionListResult{}, fmt.Errorf("limit argument must be positive: %v", limit)
|
||||
return nil, fmt.Errorf("limit argument must be positive: %v", limit)
|
||||
}
|
||||
|
||||
type response struct {
|
||||
|
|
@ -164,7 +164,7 @@ func (c *discussionClient) List(repo ghrepo.Interface, filters ListFilters, afte
|
|||
case OrderByUpdated:
|
||||
orderField = "UPDATED_AT"
|
||||
default:
|
||||
return DiscussionListResult{}, fmt.Errorf("unknown order-by field: %q", filters.OrderBy)
|
||||
return nil, fmt.Errorf("unknown order-by field: %q", filters.OrderBy)
|
||||
}
|
||||
}
|
||||
if filters.Direction != "" {
|
||||
|
|
@ -174,7 +174,7 @@ func (c *discussionClient) List(repo ghrepo.Interface, filters ListFilters, afte
|
|||
case OrderDirectionDesc:
|
||||
orderDir = "DESC"
|
||||
default:
|
||||
return DiscussionListResult{}, fmt.Errorf("unknown order direction: %q", filters.Direction)
|
||||
return nil, fmt.Errorf("unknown order direction: %q", filters.Direction)
|
||||
}
|
||||
}
|
||||
variables["orderBy"] = map[string]string{
|
||||
|
|
@ -193,7 +193,7 @@ func (c *discussionClient) List(repo ghrepo.Interface, filters ListFilters, afte
|
|||
case FilterStateClosed:
|
||||
variables["states"] = []string{"CLOSED"}
|
||||
default:
|
||||
return DiscussionListResult{}, fmt.Errorf("unknown state filter: %q; should be one of %q, %q", *filters.State, FilterStateOpen, FilterStateClosed)
|
||||
return nil, fmt.Errorf("unknown state filter: %q; should be one of %q, %q", *filters.State, FilterStateOpen, FilterStateClosed)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -249,11 +249,11 @@ func (c *discussionClient) List(repo ghrepo.Interface, filters ListFilters, afte
|
|||
|
||||
var data response
|
||||
if err := c.gql.GraphQL(repo.RepoHost(), query, variables, &data); err != nil {
|
||||
return DiscussionListResult{}, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if firstPage && !data.Repository.HasDiscussionsEnabled {
|
||||
return DiscussionListResult{}, fmt.Errorf("the '%s/%s' repository has discussions disabled", repo.RepoOwner(), repo.RepoName())
|
||||
return nil, fmt.Errorf("the '%s/%s' repository has discussions disabled", repo.RepoOwner(), repo.RepoName())
|
||||
}
|
||||
firstPage = false
|
||||
|
||||
|
|
@ -272,16 +272,16 @@ func (c *discussionClient) List(repo ghrepo.Interface, filters ListFilters, afte
|
|||
variables["after"] = data.Repository.Discussions.PageInfo.EndCursor
|
||||
}
|
||||
|
||||
return DiscussionListResult{
|
||||
return &DiscussionListResult{
|
||||
Discussions: discussions,
|
||||
TotalCount: totalCount,
|
||||
NextCursor: nextCursor,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *discussionClient) Search(repo ghrepo.Interface, filters SearchFilters, after string, limit int) (DiscussionListResult, error) {
|
||||
func (c *discussionClient) Search(repo ghrepo.Interface, filters SearchFilters, after string, limit int) (*DiscussionListResult, error) {
|
||||
if limit <= 0 {
|
||||
return DiscussionListResult{}, fmt.Errorf("limit argument must be positive: %v", limit)
|
||||
return nil, fmt.Errorf("limit argument must be positive: %v", limit)
|
||||
}
|
||||
|
||||
type response struct {
|
||||
|
|
@ -304,7 +304,7 @@ func (c *discussionClient) Search(repo ghrepo.Interface, filters SearchFilters,
|
|||
case FilterStateClosed:
|
||||
qualifiers = append(qualifiers, "state:closed")
|
||||
default:
|
||||
return DiscussionListResult{}, fmt.Errorf("unknown state filter: %q; should be one of %q, %q", *filters.State, FilterStateOpen, FilterStateClosed)
|
||||
return nil, fmt.Errorf("unknown state filter: %q; should be one of %q, %q", *filters.State, FilterStateOpen, FilterStateClosed)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -332,7 +332,7 @@ func (c *discussionClient) Search(repo ghrepo.Interface, filters SearchFilters,
|
|||
case OrderByCreated, OrderByUpdated:
|
||||
orderField = filters.OrderBy
|
||||
default:
|
||||
return DiscussionListResult{}, fmt.Errorf("unknown order-by field: %q", filters.OrderBy)
|
||||
return nil, fmt.Errorf("unknown order-by field: %q", filters.OrderBy)
|
||||
}
|
||||
}
|
||||
if filters.Direction != "" {
|
||||
|
|
@ -340,7 +340,7 @@ func (c *discussionClient) Search(repo ghrepo.Interface, filters SearchFilters,
|
|||
case OrderDirectionAsc, OrderDirectionDesc:
|
||||
orderDir = filters.Direction
|
||||
default:
|
||||
return DiscussionListResult{}, fmt.Errorf("unknown order direction: %q", filters.Direction)
|
||||
return nil, fmt.Errorf("unknown order direction: %q", filters.Direction)
|
||||
}
|
||||
}
|
||||
qualifiers = append(qualifiers, fmt.Sprintf("sort:%s-%s", orderField, orderDir))
|
||||
|
|
@ -380,7 +380,7 @@ func (c *discussionClient) Search(repo ghrepo.Interface, filters SearchFilters,
|
|||
|
||||
var data response
|
||||
if err := c.gql.GraphQL(repo.RepoHost(), query, variables, &data); err != nil {
|
||||
return DiscussionListResult{}, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
totalCount = data.Search.DiscussionCount
|
||||
|
|
@ -398,7 +398,7 @@ func (c *discussionClient) Search(repo ghrepo.Interface, filters SearchFilters,
|
|||
variables["after"] = data.Search.PageInfo.EndCursor
|
||||
}
|
||||
|
||||
return DiscussionListResult{
|
||||
return &DiscussionListResult{
|
||||
Discussions: discussions,
|
||||
TotalCount: totalCount,
|
||||
NextCursor: nextCursor,
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ var _ DiscussionClient = &DiscussionClientMock{}
|
|||
// GetWithCommentsFunc: func(repo ghrepo.Interface, number int, commentLimit int, order string) (*Discussion, error) {
|
||||
// panic("mock out the GetWithComments method")
|
||||
// },
|
||||
// ListFunc: func(repo ghrepo.Interface, filters ListFilters, after string, limit int) (DiscussionListResult, error) {
|
||||
// ListFunc: func(repo ghrepo.Interface, filters ListFilters, after string, limit int) (*DiscussionListResult, error) {
|
||||
// panic("mock out the List method")
|
||||
// },
|
||||
// ListCategoriesFunc: func(repo ghrepo.Interface) ([]DiscussionCategory, error) {
|
||||
|
|
@ -48,7 +48,7 @@ var _ DiscussionClient = &DiscussionClientMock{}
|
|||
// ReopenFunc: func(repo ghrepo.Interface, id string) (*Discussion, error) {
|
||||
// panic("mock out the Reopen method")
|
||||
// },
|
||||
// SearchFunc: func(repo ghrepo.Interface, filters SearchFilters, after string, limit int) (DiscussionListResult, error) {
|
||||
// SearchFunc: func(repo ghrepo.Interface, filters SearchFilters, after string, limit int) (*DiscussionListResult, error) {
|
||||
// panic("mock out the Search method")
|
||||
// },
|
||||
// UnlockFunc: func(repo ghrepo.Interface, id string) error {
|
||||
|
|
@ -83,7 +83,7 @@ type DiscussionClientMock struct {
|
|||
GetWithCommentsFunc func(repo ghrepo.Interface, number int, commentLimit int, order string) (*Discussion, error)
|
||||
|
||||
// ListFunc mocks the List method.
|
||||
ListFunc func(repo ghrepo.Interface, filters ListFilters, after string, limit int) (DiscussionListResult, error)
|
||||
ListFunc func(repo ghrepo.Interface, filters ListFilters, after string, limit int) (*DiscussionListResult, error)
|
||||
|
||||
// ListCategoriesFunc mocks the ListCategories method.
|
||||
ListCategoriesFunc func(repo ghrepo.Interface) ([]DiscussionCategory, error)
|
||||
|
|
@ -98,7 +98,7 @@ type DiscussionClientMock struct {
|
|||
ReopenFunc func(repo ghrepo.Interface, id string) (*Discussion, error)
|
||||
|
||||
// SearchFunc mocks the Search method.
|
||||
SearchFunc func(repo ghrepo.Interface, filters SearchFilters, after string, limit int) (DiscussionListResult, error)
|
||||
SearchFunc func(repo ghrepo.Interface, filters SearchFilters, after string, limit int) (*DiscussionListResult, error)
|
||||
|
||||
// UnlockFunc mocks the Unlock method.
|
||||
UnlockFunc func(repo ghrepo.Interface, id string) error
|
||||
|
|
@ -445,7 +445,7 @@ func (mock *DiscussionClientMock) GetWithCommentsCalls() []struct {
|
|||
}
|
||||
|
||||
// List calls ListFunc.
|
||||
func (mock *DiscussionClientMock) List(repo ghrepo.Interface, filters ListFilters, after string, limit int) (DiscussionListResult, error) {
|
||||
func (mock *DiscussionClientMock) List(repo ghrepo.Interface, filters ListFilters, after string, limit int) (*DiscussionListResult, error) {
|
||||
if mock.ListFunc == nil {
|
||||
panic("DiscussionClientMock.ListFunc: method is nil but DiscussionClient.List was just called")
|
||||
}
|
||||
|
|
@ -633,7 +633,7 @@ func (mock *DiscussionClientMock) ReopenCalls() []struct {
|
|||
}
|
||||
|
||||
// Search calls SearchFunc.
|
||||
func (mock *DiscussionClientMock) Search(repo ghrepo.Interface, filters SearchFilters, after string, limit int) (DiscussionListResult, error) {
|
||||
func (mock *DiscussionClientMock) Search(repo ghrepo.Interface, filters SearchFilters, after string, limit int) (*DiscussionListResult, error) {
|
||||
if mock.SearchFunc == nil {
|
||||
panic("DiscussionClientMock.SearchFunc: method is nil but DiscussionClient.Search was just called")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -181,7 +181,7 @@ func listRun(opts *ListOptions) error {
|
|||
|
||||
state := toFilterState(opts.State)
|
||||
|
||||
var result client.DiscussionListResult
|
||||
var result *client.DiscussionListResult
|
||||
|
||||
useSearch := opts.Author != "" || len(opts.Labels) > 0 || opts.Search != ""
|
||||
if useSearch {
|
||||
|
|
|
|||
|
|
@ -53,8 +53,8 @@ func sampleDiscussions() []client.Discussion {
|
|||
}
|
||||
}
|
||||
|
||||
func sampleResult() client.DiscussionListResult {
|
||||
return client.DiscussionListResult{
|
||||
func sampleResult() *client.DiscussionListResult {
|
||||
return &client.DiscussionListResult{
|
||||
Discussions: sampleDiscussions(),
|
||||
TotalCount: 2,
|
||||
}
|
||||
|
|
@ -74,7 +74,7 @@ func TestListRun_tty(t *testing.T) {
|
|||
ios.SetStderrTTY(true)
|
||||
|
||||
mockClient := &client.DiscussionClientMock{
|
||||
ListFunc: func(repo ghrepo.Interface, filters client.ListFilters, after string, limit int) (client.DiscussionListResult, error) {
|
||||
ListFunc: func(repo ghrepo.Interface, filters client.ListFilters, after string, limit int) (*client.DiscussionListResult, error) {
|
||||
return sampleResult(), nil
|
||||
},
|
||||
}
|
||||
|
|
@ -109,7 +109,7 @@ func TestListRun_nontty(t *testing.T) {
|
|||
ios.SetStdoutTTY(false)
|
||||
|
||||
mockClient := &client.DiscussionClientMock{
|
||||
ListFunc: func(repo ghrepo.Interface, filters client.ListFilters, after string, limit int) (client.DiscussionListResult, error) {
|
||||
ListFunc: func(repo ghrepo.Interface, filters client.ListFilters, after string, limit int) (*client.DiscussionListResult, error) {
|
||||
return sampleResult(), nil
|
||||
},
|
||||
}
|
||||
|
|
@ -139,8 +139,8 @@ func TestListRun_json(t *testing.T) {
|
|||
ios, _, stdout, _ := iostreams.Test()
|
||||
|
||||
mockClient := &client.DiscussionClientMock{
|
||||
ListFunc: func(repo ghrepo.Interface, filters client.ListFilters, after string, limit int) (client.DiscussionListResult, error) {
|
||||
return client.DiscussionListResult{
|
||||
ListFunc: func(repo ghrepo.Interface, filters client.ListFilters, after string, limit int) (*client.DiscussionListResult, error) {
|
||||
return &client.DiscussionListResult{
|
||||
Discussions: sampleDiscussions(),
|
||||
TotalCount: 2,
|
||||
NextCursor: "CURSOR123",
|
||||
|
|
@ -199,8 +199,8 @@ func TestListRun_noResults(t *testing.T) {
|
|||
ios.SetStdoutTTY(true)
|
||||
|
||||
mockClient := &client.DiscussionClientMock{
|
||||
ListFunc: func(repo ghrepo.Interface, filters client.ListFilters, after string, limit int) (client.DiscussionListResult, error) {
|
||||
return client.DiscussionListResult{}, nil
|
||||
ListFunc: func(repo ghrepo.Interface, filters client.ListFilters, after string, limit int) (*client.DiscussionListResult, error) {
|
||||
return &client.DiscussionListResult{}, nil
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -229,9 +229,9 @@ func TestListRun_categoryFilter(t *testing.T) {
|
|||
ListCategoriesFunc: func(repo ghrepo.Interface) ([]client.DiscussionCategory, error) {
|
||||
return sampleCategories(), nil
|
||||
},
|
||||
ListFunc: func(repo ghrepo.Interface, filters client.ListFilters, after string, limit int) (client.DiscussionListResult, error) {
|
||||
ListFunc: func(repo ghrepo.Interface, filters client.ListFilters, after string, limit int) (*client.DiscussionListResult, error) {
|
||||
assert.Equal(t, "CAT1", filters.CategoryID)
|
||||
return client.DiscussionListResult{
|
||||
return &client.DiscussionListResult{
|
||||
Discussions: sampleDiscussions()[:1],
|
||||
TotalCount: 1,
|
||||
}, nil
|
||||
|
|
@ -286,9 +286,9 @@ func TestListRun_authorFilter(t *testing.T) {
|
|||
ios.SetStdoutTTY(true)
|
||||
|
||||
mockClient := &client.DiscussionClientMock{
|
||||
SearchFunc: func(repo ghrepo.Interface, filters client.SearchFilters, after string, limit int) (client.DiscussionListResult, error) {
|
||||
SearchFunc: func(repo ghrepo.Interface, filters client.SearchFilters, after string, limit int) (*client.DiscussionListResult, error) {
|
||||
assert.Equal(t, "monalisa", filters.Author)
|
||||
return client.DiscussionListResult{
|
||||
return &client.DiscussionListResult{
|
||||
Discussions: sampleDiscussions()[:1],
|
||||
TotalCount: 1,
|
||||
}, nil
|
||||
|
|
@ -317,9 +317,9 @@ func TestListRun_labelFilter(t *testing.T) {
|
|||
ios.SetStdoutTTY(true)
|
||||
|
||||
mockClient := &client.DiscussionClientMock{
|
||||
SearchFunc: func(repo ghrepo.Interface, filters client.SearchFilters, after string, limit int) (client.DiscussionListResult, error) {
|
||||
SearchFunc: func(repo ghrepo.Interface, filters client.SearchFilters, after string, limit int) (*client.DiscussionListResult, error) {
|
||||
assert.Equal(t, []string{"bug", "docs"}, filters.Labels)
|
||||
return client.DiscussionListResult{
|
||||
return &client.DiscussionListResult{
|
||||
Discussions: sampleDiscussions()[:1],
|
||||
TotalCount: 1,
|
||||
}, nil
|
||||
|
|
@ -348,9 +348,9 @@ func TestListRun_searchFilter(t *testing.T) {
|
|||
ios.SetStdoutTTY(true)
|
||||
|
||||
mockClient := &client.DiscussionClientMock{
|
||||
SearchFunc: func(repo ghrepo.Interface, filters client.SearchFilters, after string, limit int) (client.DiscussionListResult, error) {
|
||||
SearchFunc: func(repo ghrepo.Interface, filters client.SearchFilters, after string, limit int) (*client.DiscussionListResult, error) {
|
||||
assert.Equal(t, "some keywords", filters.Keywords)
|
||||
return client.DiscussionListResult{
|
||||
return &client.DiscussionListResult{
|
||||
Discussions: sampleDiscussions()[:1],
|
||||
TotalCount: 1,
|
||||
}, nil
|
||||
|
|
@ -379,7 +379,7 @@ func TestListRun_afterCursor(t *testing.T) {
|
|||
ios.SetStdoutTTY(true)
|
||||
|
||||
mockClient := &client.DiscussionClientMock{
|
||||
ListFunc: func(repo ghrepo.Interface, filters client.ListFilters, after string, limit int) (client.DiscussionListResult, error) {
|
||||
ListFunc: func(repo ghrepo.Interface, filters client.ListFilters, after string, limit int) (*client.DiscussionListResult, error) {
|
||||
assert.Equal(t, "CURSOR_ABC", after)
|
||||
return sampleResult(), nil
|
||||
},
|
||||
|
|
@ -582,8 +582,8 @@ func TestListRun_closedState(t *testing.T) {
|
|||
}
|
||||
|
||||
mockClient := &client.DiscussionClientMock{
|
||||
ListFunc: func(repo ghrepo.Interface, filters client.ListFilters, after string, limit int) (client.DiscussionListResult, error) {
|
||||
return client.DiscussionListResult{
|
||||
ListFunc: func(repo ghrepo.Interface, filters client.ListFilters, after string, limit int) (*client.DiscussionListResult, error) {
|
||||
return &client.DiscussionListResult{
|
||||
Discussions: closed,
|
||||
TotalCount: 1,
|
||||
}, nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue