fix: Prevent nil dereference in pr view. (#8566)
The API may return a `null` project, maybe related to "legacy projects". This is translated to a nil pointer in Go. When accessing `project.Column`, the nil pointer was dereferenced, causing a segmentation fault.
This commit is contained in:
parent
29bd9dc6eb
commit
7164f6e225
3 changed files with 46 additions and 0 deletions
33
pkg/cmd/pr/view/fixtures/prViewPreviewWithNilProject.json
Normal file
33
pkg/cmd/pr/view/fixtures/prViewPreviewWithNilProject.json
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
{
|
||||
"data": {
|
||||
"repository": {
|
||||
"pullRequest": {
|
||||
"number": 12,
|
||||
"title": "Blueberries are from a fork",
|
||||
"state": "MERGED",
|
||||
"body": "**blueberries taste good**",
|
||||
"url": "https://github.com/OWNER/REPO/pull/12",
|
||||
"author": {
|
||||
"login": "nobody"
|
||||
},
|
||||
"commits": {
|
||||
"totalCount": 12
|
||||
},
|
||||
"additions": 100,
|
||||
"deletions": 10,
|
||||
"baseRefName": "master",
|
||||
"headRefName": "blueberries",
|
||||
"headRepositoryOwner": {
|
||||
"login": "hubot"
|
||||
},
|
||||
"projectCards": {
|
||||
"nodes": [
|
||||
null
|
||||
],
|
||||
"totalCount": 1
|
||||
},
|
||||
"isCrossRepository": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -439,6 +439,9 @@ func prProjectList(pr api.PullRequest) string {
|
|||
|
||||
projectNames := make([]string, 0, len(pr.ProjectCards.Nodes))
|
||||
for _, project := range pr.ProjectCards.Nodes {
|
||||
if project == nil {
|
||||
continue
|
||||
}
|
||||
colName := project.Column.Name
|
||||
if colName == "" {
|
||||
colName = "Awaiting triage"
|
||||
|
|
|
|||
|
|
@ -333,6 +333,16 @@ func TestPRView_Preview_nontty(t *testing.T) {
|
|||
`auto-merge:\tenabled\thubot\tsquash\n`,
|
||||
},
|
||||
},
|
||||
"PR with nil project": {
|
||||
branch: "master",
|
||||
args: "12",
|
||||
fixtures: map[string]string{
|
||||
"PullRequestByNumber": "./fixtures/prViewPreviewWithNilProject.json",
|
||||
},
|
||||
expectedOutputs: []string{
|
||||
`projects:\t\n`,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range tests {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue