Skip to content

Commit 6acf74e

Browse files
authored
Merge pull request cli#12324 from chrishenzie/nil-ptr-deref
fix: prevent panic when processing null project items
2 parents baf6299 + 1117477 commit 6acf74e

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

api/queries_projects_v2.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ func ProjectsV2ItemsForIssue(client *Client, repo ghrepo.Interface, issue *Issue
106106
return err
107107
}
108108
for _, projectItemNode := range query.Repository.Issue.ProjectItems.Nodes {
109+
if projectItemNode == nil {
110+
continue
111+
}
109112
items.Nodes = append(items.Nodes, &ProjectV2Item{
110113
ID: projectItemNode.ID,
111114
Project: ProjectV2ItemProject{
@@ -175,6 +178,9 @@ func ProjectsV2ItemsForPullRequest(client *Client, repo ghrepo.Interface, pr *Pu
175178
}
176179

177180
for _, projectItemNode := range query.Repository.PullRequest.ProjectItems.Nodes {
181+
if projectItemNode == nil {
182+
continue
183+
}
178184
items.Nodes = append(items.Nodes, &ProjectV2Item{
179185
ID: projectItemNode.ID,
180186
Project: ProjectV2ItemProject{

api/queries_projects_v2_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,17 @@ func TestProjectsV2ItemsForIssue(t *testing.T) {
129129
},
130130
expectError: true,
131131
},
132+
{
133+
name: "skips null project items for issue",
134+
httpStubs: func(reg *httpmock.Registry) {
135+
reg.Register(
136+
httpmock.GraphQL(`query IssueProjectItems\b`),
137+
httpmock.GraphQLQuery(`{"data":{"repository":{"issue":{"projectItems":{"totalCount":1,"nodes":[null]}}}}}`,
138+
func(query string, inputs map[string]interface{}) {}),
139+
)
140+
},
141+
expectItems: ProjectItems{},
142+
},
132143
}
133144

134145
for _, tt := range tests {
@@ -186,6 +197,17 @@ func TestProjectsV2ItemsForPullRequest(t *testing.T) {
186197
},
187198
expectError: true,
188199
},
200+
{
201+
name: "skips null project items for pull request",
202+
httpStubs: func(reg *httpmock.Registry) {
203+
reg.Register(
204+
httpmock.GraphQL(`query PullRequestProjectItems\b`),
205+
httpmock.GraphQLQuery(`{"data":{"repository":{"pullRequest":{"projectItems":{"totalCount":1,"nodes":[null]}}}}}`,
206+
func(query string, inputs map[string]interface{}) {}),
207+
)
208+
},
209+
expectItems: ProjectItems{},
210+
},
189211
{
190212
name: "retrieves project items that have status columns",
191213
httpStubs: func(reg *httpmock.Registry) {

0 commit comments

Comments
 (0)