fix: prevent panic when processing null project items

The GraphQL API can return `null` nodes in the `projectItems`
connection, causing a runtime panic (nil pointer dereference) when the
CLI attempted to access fields on these nil nodes. This crash occurs
even with personal access tokens with full read access.

Adds a check to safely skip `nil` nodes in `ProjectsV2ItemsForIssue` and
`ProjectsV2ItemsForPullRequest`.

Signed-off-by: Chris Henzie <chrishenzie@google.com>
This commit is contained in:
Chris Henzie 2025-12-16 11:06:48 -08:00
parent 51dfeeaa72
commit 4a106c1acf

View file

@ -106,6 +106,9 @@ func ProjectsV2ItemsForIssue(client *Client, repo ghrepo.Interface, issue *Issue
return err
}
for _, projectItemNode := range query.Repository.Issue.ProjectItems.Nodes {
if projectItemNode == nil {
continue
}
items.Nodes = append(items.Nodes, &ProjectV2Item{
ID: projectItemNode.ID,
Project: ProjectV2ItemProject{
@ -175,6 +178,9 @@ func ProjectsV2ItemsForPullRequest(client *Client, repo ghrepo.Interface, pr *Pu
}
for _, projectItemNode := range query.Repository.PullRequest.ProjectItems.Nodes {
if projectItemNode == nil {
continue
}
items.Nodes = append(items.Nodes, &ProjectV2Item{
ID: projectItemNode.ID,
Project: ProjectV2ItemProject{