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
--templatevalue that is a file path (!4032 (merged)) is still read locally, with or without-R. - An unknown name with
-Rfails withtemplate "<name>" not found in project <group/project>. A project without templates gets an empty picker, not an error. -RandGITLAB_REPOare resolved by one helper,cmdutils.RepoOverrideValue, whichApplyRepoOverridenow uses too.--templatehelp text updated on both commands, plus a-Rexample. Themr createexample for creating without a local clone no longer lists--templateas 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.
Related Issues
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_templateprefills the group-level template, which is not in the repository's.gitlab/issue_templates/.- The same with
GITLAB_REPO=gitlab-org/cliinstead of-R. -R gitlab-org/cli --template "Feature Request"(name with a space) from a directory outside any git clone.- No
-R,--template Bugstill uses the local file.
Unit tests:
cmdutils: remote list (sorted, de-duplicated, empty, API error) and remote load (escaped name with a space,.mdstripped, issue and MR types, 404 returns empty, API error, file path read locally without an API call), andRepoOverrideValue(flag, env, flag over env, unset, command without the flag).issue createandmr create:-RandGITLAB_REPOuse 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-Rlists and loads API templates.mr createruns 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/