From 2b794ed99213b7b11ca8bdccb22b604ab19dba3d Mon Sep 17 00:00:00 2001 From: "Babak K. Shandiz" Date: Fri, 24 Apr 2026 14:21:24 +0100 Subject: [PATCH] refactor(discussion/client): remove redundant "first" variable init The fetch loop already assigns "first" on each iteration, so the initial assignment in the variables map is dead code. Remove it from both List and Search. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- pkg/cmd/discussion/client/client_impl.go | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/pkg/cmd/discussion/client/client_impl.go b/pkg/cmd/discussion/client/client_impl.go index c14d22a77..d3f8e817b 100644 --- a/pkg/cmd/discussion/client/client_impl.go +++ b/pkg/cmd/discussion/client/client_impl.go @@ -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,7 +211,7 @@ func (c *discussionClient) List(repo ghrepo.Interface, filters ListFilters, afte remaining := limit for { - variables["first"] = githubv4.Int(min(remaining, 100)) + variables["first"] = githubv4.Int(min(remaining, maxPageSize)) if err := c.gql.Query(repo.RepoHost(), "DiscussionList", &query, variables); err != nil { return nil, err } @@ -319,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 != "" { @@ -337,7 +328,7 @@ func (c *discussionClient) Search(repo ghrepo.Interface, filters SearchFilters, remaining := limit for { - variables["first"] = githubv4.Int(min(remaining, 100)) + variables["first"] = githubv4.Int(min(remaining, maxPageSize)) if err := c.gql.Query(repo.RepoHost(), "DiscussionListSearch", &query, variables); err != nil { return nil, err }