feat(template): load issue and MR templates from remote repository when --repo is set

What does this MR do?

When --repo is set, glab issue create --template and glab mr create --template now load templates from the target repository (on its default branch) through the API, instead of reading the local checkout.

This continues !3625 (closed), which was closed as stale. The review feedback from that MR is addressed here.

Changes

  • internal/cmdutils: new LoadGitLabTemplateRemote and ListGitLabTemplatesRemote helpers that use RepositoryFiles.GetRawFile and Repositories.ListTree against the project's default branch.
    • ctx is passed through to both helpers and on to the API calls with gitlab.WithContext(ctx).
    • A 404 is detected with gitlab.HasStatusCode(err, http.StatusNotFound).
    • Pointers use new(...) (for example Recursive: new(false)).
  • issue create and mr create switch to the remote helpers when --repo is set.
  • Tests: unit tests for the helpers, plus command-level tests via cmdtest.SetupCmdForTest for both commands covering local (no --repo), remote (--repo), and remote not-found.
  • Docs regenerated.

How to test

glab issue create --repo <group/project> --template <name>
glab mr create --repo <group/project> --template <name>
go test ./internal/cmdutils/ ./internal/commands/issue/create/ ./internal/commands/mr/create/

Closes #8175

Merge request reports

Loading
Loading