feat(template): accept file paths for --template
Description
--template on glab issue create and glab mr create could only load templates from .gitlab/<type>/ in the current repository, because the value was always joined onto that directory. Teams that share templates across many repositories (which the GitLab web UI supports) could not use them from glab.
This MR adds the lookup order proposed in the issue:
- A bare name (no path separator) keeps the existing behavior: it resolves to
.gitlab/<type>/<name>.mdin the current repository, and the.mdextension stays optional. - A value that is absolute or contains a path separator is read as a file path, as given. A leading
~/is expanded to the home directory. No.mdis appended. - A missing file path is reported as an error (wrapping
fs.ErrNotExist) instead of the "not found in.gitlab/..." message, so a typo in a path is not reported as a missing repository template. - The path form does not need a git repository, so
git.ToplevelDir()is only called for bare names.
GitLab only reads description templates directly under .gitlab/<type>/, so a value with a separator could never have matched a valid repository template.
The --template help text and examples for both commands are updated, and docs/source/ is regenerated with make gen-docs.
Out of scope, as noted in the issue: templates served by the API for another repository (#798 (closed)) and group- or instance-level templates (#1044).
Related Issues
Closes #8369 (closed)
How has this been tested?
- New
TestLoadGitLabTemplateininternal/cmdutils/cmdutils_test.gocovers: bare name, bare name with.md, missing bare name, bare name outside a repository, absolute path outside a repository, relative path with a separator,~/path, path read verbatim without appending.md, and missing path. - New command tests:
TestIssueCreate_TemplateFilePath,TestIssueCreate_TemplateFilePathNotFound,TestNewCmdCreate_WithTemplateFilePath,TestNewCmdCreate_TemplateFilePathNotFound. Existing bare-name template tests are unchanged and still pass. make test-changed(changed packages and reverse deps): all passing.golangci-lint runon the touched packages: 0 issues.go run ./scripts/comment-overlap -threshold 1.0 -max-findings 0on the touched files: 0 findings.make gen-docsleaves the tree clean.
Manual check:
mkdir -p ~/team-templates
printf '## Summary\n' > ~/team-templates/bug.md
glab issue create -t "Test" --template ~/team-templates/bug.md --web