Merge pull request #13252 from maxbeizer/tests/discussion-client-httpmock

test(discussion): add httpmock unit tests for DiscussionClient
This commit is contained in:
Babak K. Shandiz 2026-04-24 14:31:47 +01:00 committed by GitHub
commit d7276c7ef9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 1013 additions and 12 deletions

View file

@ -11,6 +11,9 @@ import (
"github.com/shurcooL/githubv4"
)
// maxPageSize is the maximum number of items per page allowed by the GitHub GraphQL API.
const maxPageSize = 100
type discussionClient struct {
gql *api.Client
}
@ -171,15 +174,9 @@ func (c *discussionClient) List(repo ghrepo.Interface, filters ListFilters, afte
}
}
perPage := limit
if perPage > 100 {
perPage = 100
}
variables := map[string]interface{}{
"owner": githubv4.String(repo.RepoOwner()),
"name": githubv4.String(repo.RepoName()),
"first": githubv4.Int(perPage),
"after": (*githubv4.String)(nil),
"orderBy": githubv4.DiscussionOrder{Field: orderField, Direction: orderDir},
"categoryId": (*githubv4.ID)(nil),
@ -214,6 +211,7 @@ func (c *discussionClient) List(repo ghrepo.Interface, filters ListFilters, afte
remaining := limit
for {
variables["first"] = githubv4.Int(min(remaining, maxPageSize))
if err := c.gql.Query(repo.RepoHost(), "DiscussionList", &query, variables); err != nil {
return nil, err
}
@ -318,14 +316,8 @@ func (c *discussionClient) Search(repo ghrepo.Interface, filters SearchFilters,
searchQuery += " " + filters.Keywords
}
perPage := limit
if perPage > 100 {
perPage = 100
}
variables := map[string]interface{}{
"query": githubv4.String(searchQuery),
"first": githubv4.Int(perPage),
"after": (*githubv4.String)(nil),
}
if after != "" {
@ -336,6 +328,7 @@ func (c *discussionClient) Search(repo ghrepo.Interface, filters SearchFilters,
remaining := limit
for {
variables["first"] = githubv4.Int(min(remaining, maxPageSize))
if err := c.gql.Query(repo.RepoHost(), "DiscussionListSearch", &query, variables); err != nil {
return nil, err
}

File diff suppressed because it is too large Load diff