fix(mr): handle nil references in mr list

Description

glab mr list panics with a nil pointer dereference when the API returns "references": null for a merge request.

Now the full reference column is left blank for that row. The row still shows !<iid>, the title, and the branch names.

Closes #8624 (closed)

How has this been tested?

I built glab from main and from this branch. I ran both against a small local stub server that returns one merge request with "references": null.

Built from main, it panics (exit code 2):

$ glab mr list -R 127.0.0.1:8624/OWNER/REPO
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0xf97ef2]

goroutine 1 [running]:
gitlab.com/gitlab-org/cli/internal/commands/mr/mrutils.DisplayAllMRs(0x24c25197c1a0, {0x24c2517194f0, 0x1, 0x24c251c22000?})
	.../internal/commands/mr/mrutils/mrutils.go:135 +0x372

Built from this branch, it prints the table (exit code 0):

$ glab mr list -R 127.0.0.1:8624/OWNER/REPO
Showing 1 open merge request on OWNER/REPO. (Page 1)

!76		test mr with nil references	(main) ← (feature-branch)

I added a test for the table output and one for the full glab mr list output when references is null:

$ GOFLAGS=-p=2 go test -count=1 -v -run 'TestMergeRequestList_NilReferences|Test_DisplayAllMRs_nilReferences' ./internal/commands/mr/list/ ./internal/commands/mr/mrutils/
=== RUN   TestMergeRequestList_NilReferences
--- PASS: TestMergeRequestList_NilReferences (0.00s)
PASS
ok  	gitlab.com/gitlab-org/cli/internal/commands/mr/list	0.020s
=== RUN   Test_DisplayAllMRs_nilReferences
--- PASS: Test_DisplayAllMRs_nilReferences (0.00s)
PASS
ok  	gitlab.com/gitlab-org/cli/internal/commands/mr/mrutils	0.022s

Both tests panic without the fix.

gofmt and go vet printed nothing. The rest runs in the pipeline.

Implemented with AI assistance; I reviewed and tested the changes.

Edited by Hamza Hassanain

Merge request reports

Loading
Loading