fix(issue): avoid panic when viewing a closed issue with no closer

Summary

glab issue view panics with a nil pointer dereference when the target issue is closed but the API returns closed_by: null. This happens for older issues (e.g. gitlab-org/gitlab#1) and for issues closed by a since-deleted user.

The crash site is in printTTYIssuePreview:

if opts.issue.State == "closed" {
    opts.io.LogInfof("Closed by: %s %s\n", opts.issue.ClosedBy.Username, issueTimeAgo)
}

ClosedBy is *gitlab.IssueCloser, and the API can legitimately return nil for it. issueTimeAgo was also the wrong value entirely — it was derived from opts.issue.CreatedAt, not ClosedAt, so the rendered "Closed by: X 10 years ago" line was misleading even in the non-panic case.

Fix:

  • Guard the "Closed by" line on ClosedBy != nil.
  • Use ClosedAt for the time-ago value when it is available; drop the time entirely when it is not (rather than fall back to a wrong-but-non-nil CreatedAt).

Reproducer

glab issue view --repo gitlab-org/gitlab 1

Before this MR: panics with nil pointer dereference at internal/commands/issuable/view/issuable_view.go:227. After this MR: renders normally with no "Closed by:" line.

Test plan

  • go test ./internal/commands/issuable/view/... passes.
  • New Test_printTTYIssuePreview_closed covers nil ClosedBy, populated ClosedBy + ClosedAt, and populated ClosedBy with nil ClosedAt.
  • Manually verified glab issue view --repo gitlab-org/gitlab 1 no longer panics.

Closes #8384 (closed)

Merge request reports

Loading