in commands/issue/create/issue_create.go [63:163]
func NewCmdCreate(f *cmdutils.Factory) *cobra.Command {
opts := &CreateOpts{
IO: f.IO,
Remotes: f.Remotes,
Config: f.Config,
}
issueCreateCmd := &cobra.Command{
Use: "create [flags]",
Short: `Create an issue.`,
Long: ``,
Aliases: []string{"new"},
Example: heredoc.Doc(`
- glab issue create
- glab issue new
- glab issue create -m release-2.0.0 -t "we need this feature" --label important
- glab issue new -t "Fix CVE-YYYY-XXXX" -l security --linked-mr 123
- glab issue create -m release-1.0.1 -t "security fix" --label security --web --recover
`),
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
var err error
// support `-R, --repo` override
//
// NOTE: it is important to assign the BaseRepo and HTTPClient in RunE because
// they are overridden in a PersistentRun hook (when `-R, --repo` is specified)
// which runs before RunE is executed
opts.BaseRepo = f.BaseRepo
opts.HTTPClient = f.HttpClient
apiClient, err := opts.HTTPClient()
if err != nil {
return err
}
repo, err := opts.BaseRepo()
if err != nil {
return err
}
hasTitle := cmd.Flags().Changed("title")
hasDescription := cmd.Flags().Changed("description")
// disable interactive mode if title and description are explicitly defined
opts.IsInteractive = !(hasTitle && hasDescription)
if opts.IsInteractive && !opts.IO.PromptEnabled() {
return &cmdutils.FlagError{Err: errors.New("'--title' and '--description' required for non-interactive mode.")}
}
// Remove this once --yes does more than just skip the prompts that --web happen to skip
// by design
if opts.Yes && opts.Web {
return &cmdutils.FlagError{Err: errors.New("'--web' already skips all prompts currently skipped by '--yes'.")}
}
opts.BaseProject, err = api.GetProject(apiClient, repo.FullName())
if err != nil {
return err
}
if !opts.BaseProject.IssuesEnabled { //nolint:staticcheck
fmt.Fprintf(opts.IO.StdErr, "Issues are disabled for project %q or require project membership. ", opts.BaseProject.PathWithNamespace)
fmt.Fprintf(opts.IO.StdErr, "Make sure issues are enabled for the %q project, and if required, you are a member of the project.\n",
opts.BaseProject.PathWithNamespace)
return cmdutils.SilentError
}
if err := createRun(opts); err != nil {
// always save options to file
recoverErr := createRecoverSaveFile(repo.FullName(), opts)
if recoverErr != nil {
fmt.Fprintf(opts.IO.StdErr, "Could not create recovery file: %v", recoverErr)
}
return err
}
return nil
},
}
issueCreateCmd.Flags().StringVarP(&opts.Title, "title", "t", "", "Issue title.")
issueCreateCmd.Flags().StringVarP(&opts.Description, "description", "d", "", "Issue description.")
issueCreateCmd.Flags().StringSliceVarP(&opts.Labels, "label", "l", []string{}, "Add label by name. Multiple labels should be comma-separated.")
issueCreateCmd.Flags().StringSliceVarP(&opts.Assignees, "assignee", "a", []string{}, "Assign issue to people by their `usernames`.")
issueCreateCmd.Flags().StringVarP(&opts.MilestoneFlag, "milestone", "m", "", "The global ID or title of a milestone to assign.")
issueCreateCmd.Flags().BoolVarP(&opts.IsConfidential, "confidential", "c", false, "Set an issue to be confidential. (default false)")
issueCreateCmd.Flags().IntVarP(&opts.LinkedMR, "linked-mr", "", 0, "The IID of a merge request in which to resolve all issues.")
issueCreateCmd.Flags().IntVarP(&opts.Weight, "weight", "w", 0, "Issue weight. Valid values are greater than or equal to 0.")
issueCreateCmd.Flags().BoolVarP(&opts.NoEditor, "no-editor", "", false, "Don't open editor to enter a description. If set to true, uses prompt. (default false)")
issueCreateCmd.Flags().BoolVarP(&opts.Yes, "yes", "y", false, "Don't prompt for confirmation to submit the issue.")
issueCreateCmd.Flags().BoolVar(&opts.Web, "web", false, "Continue issue creation with web interface.")
issueCreateCmd.Flags().IntSliceVarP(&opts.LinkedIssues, "linked-issues", "", []int{}, "The IIDs of issues that this issue links to.")
issueCreateCmd.Flags().StringVarP(&opts.IssueLinkType, "link-type", "", "relates_to", "Type for the issue link")
issueCreateCmd.Flags().StringVarP(&opts.TimeEstimate, "time-estimate", "e", "", "Set time estimate for the issue.")
issueCreateCmd.Flags().StringVarP(&opts.TimeSpent, "time-spent", "s", "", "Set time spent for the issue.")
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().IntVarP(&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.")
return issueCreateCmd
}