diff --git a/docs/source/issue/create.md b/docs/source/issue/create.md index 429300702de9eb4799d1093bd5391850513273fe..d91f6cf5b13e2c913c4a3563e3b047c8207f08ee 100644 --- a/docs/source/issue/create.md +++ b/docs/source/issue/create.md @@ -48,6 +48,7 @@ $ glab issue create -m release-1.0.1 -t "security fix" --label security --web -- -m, --milestone string The global ID or title of a milestone to assign. --no-editor Don't open editor to enter a description. If set to true, uses prompt. (default false) --recover Save the options to a file if the issue fails to be created. If the file exists, the options will be loaded from the recovery file. (EXPERIMENTAL) + --template string Use a specific issue template by name. -e, --time-estimate string Set time estimate for the issue. -s, --time-spent string Set time spent for the issue. -t, --title string Issue title. diff --git a/internal/commands/issue/create/issue_create.go b/internal/commands/issue/create/issue_create.go index 38f0bebff56d31f90767aaec7785b22e9d84e9de..f025a29a0515e29e1c99e4cc089c0fd857967a34 100644 --- a/internal/commands/issue/create/issue_create.go +++ b/internal/commands/issue/create/issue_create.go @@ -52,6 +52,7 @@ type options struct { DueDate string `json:"due_date,omitempty"` MilestoneFlag string `json:"milestone_flag"` + Template string `json:"template,omitempty"` IsConfidential bool `json:"is_confidential,omitempty"` @@ -163,6 +164,7 @@ func NewCmdCreate(f cmdutils.Factory) *cobra.Command { issueCreateCmd.Flags().BoolVar(&opts.recover, "recover", false, "Save the options to a file if the issue fails to be created. If the file exists, the options will be loaded from the recovery file. (EXPERIMENTAL)") issueCreateCmd.Flags().Int64VarP(&opts.EpicID, "epic", "", 0, "ID of the epic to add the issue to.") issueCreateCmd.Flags().StringVarP(&opts.DueDate, "due-date", "", "", "A date in 'YYYY-MM-DD' format.") + issueCreateCmd.Flags().StringVarP(&opts.Template, "template", "", "", "Use a specific issue template by name.") return issueCreateCmd } @@ -201,9 +203,20 @@ var createRun = func(opts *options) error { } } + if opts.Template != "" { + templateContents, err = cmdutils.LoadGitLabTemplate(cmdutils.IssueTemplate, opts.Template) + if err != nil { + return fmt.Errorf("failed to load template %q: %w", opts.Template, err) + } + // If description is empty, use template contents + if opts.Description == "" { + opts.Description = templateContents + } + } + if opts.isInteractive { // Step 1: Template selection (if not using --no-editor and description is empty) - if opts.Description == "" && !opts.noEditor { + if opts.Description == "" && !opts.noEditor && opts.Template == "" { templateNames, err := cmdutils.ListGitLabTemplates(cmdutils.IssueTemplate) if err != nil { return fmt.Errorf("error getting templates: %w", err)