fix(template): Load templates from the --repo project

When the repository is overridden with -R/--repo or GITLAB_REPO, glab issue create and glab mr create now list and load templates of that project through the project templates API, as proposed in the triage on #798 (closed). Without an override nothing changes - templates still come from .gitlab/<type>/ of the local checkout.

  • --template <name> and the interactive picker (including -d -) both use the target project.
  • The API serves the project's default branch, and also returns templates inherited from groups, so the picker can show more than the project's own .gitlab/ folder - same as the web UI.
  • A --template value that is a file path (!4032 (merged)) is still read locally, with or without -R.
  • An unknown name with -R fails with template "<name>" not found in project <group/project>. A project without templates gets an empty picker, not an error.
  • -R and GITLAB_REPO are resolved by one helper, cmdutils.RepoOverrideValue, which ApplyRepoOverride now uses too.
  • --template help text updated on both commands, plus a -R example. The mr create example for creating without a local clone no longer lists --template as unsupported, since it now works there.

Scope follows the discussion on the issue: the API is used only when the repository is overridden, and #1044 (always using it) stays separate.

Resolves #798 (closed)

Related to #8175 and #1063 (closed) (closed), which describe the same problem. !4000 (closed) tried it through the repository tree API and was closed; this version uses the templates API instead, which also covers group templates and returns an empty list for projects without templates.

How has this been tested?

Reproduced on main first: from a clone of gitlab-org/cli, glab issue create -R <other-project> -t T --template Bug --web prefilled the other project's new-issue form with gitlab-org/cli's local Bug.md.

With this branch, the same command against a project that has no issue templates fails with template "Bug" not found in project <other-project>.

Also checked with --web against gitlab-org/cli:

  • -R gitlab-org/cli --template interlock_template prefills the group-level template, which is not in the repository's .gitlab/issue_templates/.
  • The same with GITLAB_REPO=gitlab-org/cli instead of -R.
  • -R gitlab-org/cli --template "Feature Request" (name with a space) from a directory outside any git clone.
  • No -R, --template Bug still uses the local file.

Unit tests:

  • cmdutils: remote list (sorted, de-duplicated, empty, API error) and remote load (escaped name with a space, .md stripped, issue and MR types, 404 returns empty, API error, file path read locally without an API call), and RepoOverrideValue (flag, env, flag over env, unset, command without the flag).
  • issue create and mr create: -R and GITLAB_REPO use the API template even when a local template with the same name exists, the not-found error names the project, and the interactive picker with -R lists and loads API templates. mr create runs without a local clone in these tests. The existing local-template tests are unchanged.
go test ./internal/cmdutils/ ./internal/commands/issue/create/ ./internal/commands/mr/create/

Screenshots (if appropriate):

Merge request reports

Loading
Loading