MCPcopy
hub / github.com/cli/cli / createRun

Function createRun

pkg/cmd/agent-task/create/create.go:123–195  ·  view source on GitHub ↗
(opts *CreateOptions)

Source from the content-addressed store, hash-verified

121}
122
123func createRun(opts *CreateOptions) error {
124 repo, err := opts.BaseRepo()
125 if err != nil || repo == nil {
126 // Not printing the error that came back from BaseRepo() here because we want
127 // something clear, human friendly, and actionable.
128 return fmt.Errorf("a repository is required; re-run in a repository or supply one with --repo owner/name")
129 }
130
131 if opts.ProblemStatement == "" {
132 if opts.ProblemStatementFile != "" {
133 fileContent, err := cmdutil.ReadFile(opts.ProblemStatementFile, opts.IO.In)
134 if err != nil {
135 return fmt.Errorf("could not read task description file: %w", err)
136 }
137
138 trimmed := strings.TrimSpace(string(fileContent))
139 if trimmed == "" {
140 return errors.New("task description file cannot be empty")
141 }
142
143 opts.ProblemStatement = trimmed
144 } else {
145 desc, err := opts.Prompter.MarkdownEditor("Enter the task description", opts.ProblemStatement, false)
146 if err != nil {
147 return err
148 }
149
150 trimmed := strings.TrimSpace(string(desc))
151 if trimmed == "" {
152 return errors.New("a task description is required")
153 }
154
155 opts.ProblemStatement = trimmed
156 }
157 }
158
159 client, err := opts.CapiClient()
160 if err != nil {
161 return err
162 }
163
164 ctx := context.Background()
165 opts.IO.StartProgressIndicatorWithLabel(fmt.Sprintf("Creating agent task in %s/%s...", repo.RepoOwner(), repo.RepoName()))
166 defer opts.IO.StopProgressIndicator()
167
168 job, err := client.CreateJob(ctx, repo.RepoOwner(), repo.RepoName(), opts.ProblemStatement, opts.BaseBranch, opts.CustomAgent)
169 if err != nil {
170 return err
171 }
172
173 if opts.Follow {
174 opts.IO.StopProgressIndicator()
175 fmt.Fprintf(opts.IO.Out, "Displaying session logs for job %s. Press Ctrl+C to stop.\n", job.ID)
176 return followLogs(opts, client, job.SessionID)
177 }
178
179 sessionURL, err := fetchJobSessionURL(ctx, client, repo, job, opts.BackOff)
180 opts.IO.StopProgressIndicator()

Callers 2

Test_createRunFunction · 0.70
NewCmdCreateFunction · 0.70

Calls 11

ReadFileFunction · 0.92
followLogsFunction · 0.85
fetchJobSessionURLFunction · 0.85
BaseRepoMethod · 0.65
ErrorfMethod · 0.65
MarkdownEditorMethod · 0.65
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
StopProgressIndicatorMethod · 0.65
CreateJobMethod · 0.65

Tested by 1

Test_createRunFunction · 0.56