Skip to content

'gh issue view --comments' re-fetches first page of comments unnecessarily #12606

@kyyril

Description

@kyyril

Description

When running gh issue view --comments, the command first fetches the issue details including the first 100 comments. Then, it calls preloadIssueComments to fetch any additional comments if they exist.

Currently, preloadIssueComments in pkg/cmd/issue/view/http.go has a logic flaw:

  1. It checks if issue.Comments.PageInfo.HasNextPage is true.
  2. If it is false (meaning all comments were already fetched in the first request), it clears issue.Comments.Nodes and proceeds to re-fetch them anyway!
	if issue.Comments.PageInfo.HasNextPage {
		variables["endCursor"] = githubv4.String(issue.Comments.PageInfo.EndCursor)
	} else {
		issue.Comments.Nodes = issue.Comments.Nodes[0:0] // This clears existing comments!
	}

This is inefficient as it makes a redundant second request even when all comments are already available.

Expected Behavior

If issue.Comments.PageInfo.HasNextPage is false, preloadIssueComments should return immediately.
If it is true, it should start fetching from the endCursor and append to the existing nodes.

Proposed Fix

Modify preloadIssueComments to return early if no more pages exist, and avoid clearing existing nodes when more pages do exist.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggh-issuerelating to the gh issue commandneeds-triageneeds to be reviewedp3Affects a small number of users or is largely cosmetic

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions