Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use min and max built-ins
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
  • Loading branch information
BagToad and Copilot committed Aug 26, 2026
commit aee884dbcf96be3e4ea1e03ff1f33ae0b1f1aa9e
5 changes: 1 addition & 4 deletions pkg/cmd/attestation/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,7 @@ func (c *LiveClient) buildRequestURL(params FetchParams) (safeurl.SafeURL, error
}
}

perPage := params.Limit
if perPage > maxLimitForFetch {
perPage = maxLimitForFetch
}
perPage := min(params.Limit, maxLimitForFetch)

// ref: https://github.com/cli/go-gh/blob/d32c104a9a25c9de3d7c7b07a43ae0091441c858/example_gh_test.go#L96
u.SetQuery("per_page", strconv.Itoa(perPage))
Expand Down
10 changes: 2 additions & 8 deletions pkg/cmd/extension/browse/browse.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,7 @@ func (el *extList) PageDown() {
}

func (el *extList) PageUp() {
i := el.ui.List.GetCurrentItem() - pagingOffset
if i < 0 {
i = 0
}
i := max(el.ui.List.GetCurrentItem()-pagingOffset, 0)
el.ui.List.SetCurrentItem(i)
}

Expand All @@ -266,10 +263,7 @@ func (el *extList) ScrollDown() {
}

func (el *extList) ScrollUp() {
i := el.ui.List.GetCurrentItem() - 1
if i < 0 {
i = 0
}
i := max(el.ui.List.GetCurrentItem()-1, 0)
el.ui.List.SetCurrentItem(i)
}

Expand Down
5 changes: 1 addition & 4 deletions pkg/cmd/gist/shared/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,7 @@ func ListGists(client *http.Client, hostname string, limit int, filter *regexp.R
}
}

perPage := limit
if perPage > maxPerPage {
perPage = maxPerPage
}
perPage := min(limit, maxPerPage)

variables := map[string]any{
"per_page": githubv4.Int(perPage),
Expand Down
7 changes: 0 additions & 7 deletions pkg/cmd/issue/list/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,3 @@ loop:

return &ic, nil
}

func min(a, b int) int {
if a < b {
return a
}
return b
}
7 changes: 0 additions & 7 deletions pkg/cmd/org/list/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,3 @@ loop:

return &listResult, nil
}

func min(a, b int) int {
if a < b {
return a
}
return b
}
7 changes: 0 additions & 7 deletions pkg/cmd/pr/list/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,3 @@ loop:

return &res, nil
}

func min(a, b int) int {
if a < b {
return a
}
return b
}
15 changes: 3 additions & 12 deletions pkg/cmd/project/shared/queries/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,10 +695,7 @@ func (c *Client) ProjectItems(o *Owner, number int32, limit int, queryStr string
}

// set first to the min of limit and LimitMax
first := LimitMax
if limit < first {
first = limit
}
first := min(limit, LimitMax)

variables := map[string]any{
"firstItems": githubv4.Int(first),
Expand Down Expand Up @@ -1087,10 +1084,7 @@ func (c *Client) ProjectFields(o *Owner, number int32, limit int) (*Project, err
}

// set first to the min of limit and LimitMax
first := LimitMax
if limit < first {
first = limit
}
first := min(limit, LimitMax)
variables := map[string]any{
"firstItems": githubv4.Int(LimitMax),
"afterItems": (*githubv4.String)(nil),
Expand Down Expand Up @@ -1561,10 +1555,7 @@ func (c *Client) Projects(login string, t OwnerType, limit int, fields bool) (Pr
}

// set first to the min of limit and LimitMax
first := LimitMax
if limit < first {
first = limit
}
first := min(limit, LimitMax)

variables := map[string]any{
"first": githubv4.Int(first),
Expand Down
10 changes: 2 additions & 8 deletions pkg/cmd/release/list/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,7 @@ func fetchReleases(httpClient *http.Client, repo ghrepo.Interface, limit int, ex
} `graphql:"repository(owner: $owner, name: $name)"`
}

perPage := limit
if limit > 100 {
perPage = 100
}
perPage := min(limit, 100)

variables := map[string]any{
"owner": githubv4.String(repo.RepoOwner()),
Expand Down Expand Up @@ -157,10 +154,7 @@ func fetchReleasesWithoutImmutableReleases(httpClient *http.Client, repo ghrepo.
} `graphql:"repository(owner: $owner, name: $name)"`
}

perPage := limit
if limit > 100 {
perPage = 100
}
perPage := min(limit, 100)

variables := map[string]any{
"owner": githubv4.String(repo.RepoOwner()),
Expand Down
10 changes: 2 additions & 8 deletions pkg/cmd/repo/list/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ func listRepos(client *http.Client, hostname string, limit int, owner string, fi
return searchRepos(client, hostname, limit, owner, filter)
}

perPage := limit
if perPage > 100 {
perPage = 100
}
perPage := min(limit, 100)

variables := map[string]any{
"perPage": githubv4.Int(perPage),
Expand Down Expand Up @@ -138,10 +135,7 @@ func searchRepos(client *http.Client, hostname string, limit int, owner string,
}
}`, api.RepositoryGraphQL(filter.Fields))

perPage := limit
if perPage > 100 {
perPage = 100
}
perPage := min(limit, 100)

variables := map[string]any{
"query": githubv4.String(searchQuery(owner, filter)),
Expand Down
7 changes: 0 additions & 7 deletions pkg/cmd/ruleset/shared/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,6 @@ func listRulesets(httpClient *http.Client, query string, variables map[string]an
return &res, nil
}

func min(a, b int) int {
if a < b {
return a
}
return b
}

func rulesetsQuery(org bool) string {
if org {
return orgGraphQLHeader + sharedGraphQLBody
Expand Down
5 changes: 1 addition & 4 deletions pkg/cmd/run/shared/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,7 @@ func GetRuns(client *api.Client, repo ghrepo.Interface, opts *FilterOptions, lim
}
}

perPage := limit
if limit > 100 {
perPage = 100
}
perPage := min(limit, 100)
u.SetQuery("per_page", strconv.Itoa(perPage))
u.SetQuery("exclude_pull_requests", "true") // significantly reduces payload size

Expand Down
10 changes: 2 additions & 8 deletions pkg/cmd/skills/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -726,10 +726,7 @@ func selectSkillsWithSelector(opts *InstallOptions, skills []discovery.Skill, ca
sel.fetchDescriptions()
}

labelWidth := opts.IO.TerminalWidth() - multiSelectLabelMargin
if labelWidth < 1 {
labelWidth = 1
}
labelWidth := max(opts.IO.TerminalWidth()-multiSelectLabelMargin, 1)

selected, err := opts.Prompter.MultiSelectWithSearch(
"Select skill(s) to install:",
Expand Down Expand Up @@ -780,10 +777,7 @@ func listAvailableSkills(opts *InstallOptions, skills []discovery.Skill, sel ski
}

tw := opts.IO.TerminalWidth()
descWidth := tw - 40
if descWidth < 20 {
descWidth = 20
}
descWidth := max(tw-40, 20)
isTTY := opts.IO.IsStdoutTTY()

table := tableprinter.New(opts.IO, tableprinter.WithHeader("SKILL", "DESCRIPTION"))
Expand Down
25 changes: 5 additions & 20 deletions pkg/cmd/skills/search/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,7 @@ func noResults(opts *SearchOptions, msg string) error {
// potentially a repo fetch (stars), so keeping this small matters for
// performance. Pre-ranking ensures the best candidates are at the top.
func truncateForProcessing(skills []skillResult, page, limit int) []skillResult {
maxToProcess := page * limit * 3
if maxToProcess < limit*3 {
maxToProcess = limit * 3
}
maxToProcess := max(page*limit*3, limit*3)
Comment thread
BagToad marked this conversation as resolved.
Outdated
if len(skills) > maxToProcess {
return skills[:maxToProcess]
}
Expand Down Expand Up @@ -421,10 +418,7 @@ func paginate(skills []skillResult, page, limit int) ([]skillResult, int) {
if start >= total {
return nil, totalPages
}
end := start + limit
if end > total {
end = total
}
end := min(start+limit, total)
return skills[start:end], totalPages
}

Expand Down Expand Up @@ -494,10 +488,7 @@ func renderResults(opts *SearchOptions, skills []skillResult, totalPages int) er
func renderTable(io *iostreams.IOStreams, skills []skillResult) error {
isTTY := io.IsStdoutTTY()
tw := io.TerminalWidth()
descWidth := tw - 70
if descWidth < 20 {
descWidth = 20
}
descWidth := max(tw-70, 20)

table := tableprinter.New(io, tableprinter.WithHeader("REPOSITORY", "SKILL", "DESCRIPTION", "STARS"))
for _, s := range skills {
Expand All @@ -524,10 +515,7 @@ func promptInstall(opts *SearchOptions, skills []skillResult) error {
// Reserve space for the checkbox UI prefix ("[ ] ") and the description
// indent ("\n " = 7 chars), then use the remaining terminal width.
tw := opts.IO.TerminalWidth()
descWidth := tw - 11
if descWidth < 30 {
descWidth = 30
}
descWidth := max(tw-11, 30)

options := make([]string, len(skills))
for i, s := range skills {
Expand Down Expand Up @@ -758,10 +746,7 @@ func fetchPrimaryPages(client *api.Client, host, query string, displayPage, disp
// good buffer for typical filter rates while staying well within
// the rate-limit budget.
needed := displayPage * displayLimit * 3
numPages := (needed + searchPageSize - 1) / searchPageSize
if numPages < 1 {
numPages = 1
}
numPages := max((needed+searchPageSize-1)/searchPageSize, 1)
maxAPIPages := maxResults / searchPageSize
if numPages > maxAPIPages {
numPages = maxAPIPages
Expand Down
7 changes: 0 additions & 7 deletions pkg/search/searcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,3 @@ func nextPage(link string) (page int) {
}
return 0
}

func min(a, b int) int {
if a < b {
return a
}
return b
}