MCPcopy Index your code
hub / github.com/cli/cli / createRun

Function createRun

pkg/cmd/discussion/create/create.go:98–199  ·  view source on GitHub ↗
(opts *CreateOptions)

Source from the content-addressed store, hash-verified

96}
97
98func createRun(opts *CreateOptions) error {
99 repo, err := opts.BaseRepo()
100 if err != nil {
101 return err
102 }
103
104 c, err := opts.Client()
105 if err != nil {
106 return err
107 }
108
109 opts.IO.StartProgressIndicator()
110 categories, err := c.ListCategories(repo)
111 opts.IO.StopProgressIndicator()
112 if err != nil {
113 return err
114 }
115
116 if opts.Title == "" {
117 opts.Title, err = opts.Prompter.Input("Discussion title", "")
118 if err != nil {
119 return err
120 }
121 if strings.TrimSpace(opts.Title) == "" {
122 return fmt.Errorf("title cannot be blank")
123 }
124 }
125
126 var category *client.DiscussionCategory
127 if opts.Category != "" {
128 category, err = shared.MatchCategory(opts.Category, categories)
129 if err != nil {
130 return err
131 }
132 } else {
133 names := make([]string, len(categories))
134 for i, cat := range categories {
135 names[i] = cat.Name
136 }
137 idx, err := opts.Prompter.Select("Discussion category", "", names)
138 if err != nil {
139 return err
140 }
141 category = &categories[idx]
142 }
143
144 if opts.BodyFile != "" {
145 bodyBytes, err := cmdutil.ReadFile(opts.BodyFile, opts.IO.In)
146 if err != nil {
147 return err
148 }
149 opts.Body = string(bodyBytes)
150 }
151
152 if opts.Body == "" {
153 opts.Body, err = opts.Prompter.MarkdownEditor("Discussion body", "", false)
154 if err != nil {
155 return err

Callers 2

TestCreateRunFunction · 0.70
NewCmdCreateFunction · 0.70

Calls 14

MatchCategoryFunction · 0.92
ReadFileFunction · 0.92
ResolveLabelsFunction · 0.92
BaseRepoMethod · 0.65
ListCategoriesMethod · 0.65
StopProgressIndicatorMethod · 0.65
InputMethod · 0.65
ErrorfMethod · 0.65
SelectMethod · 0.65
MarkdownEditorMethod · 0.65
ListLabelsMethod · 0.65

Tested by 1

TestCreateRunFunction · 0.56