MCPcopy Create free account
hub / github.com/cli/cli / createRun

Function createRun

pkg/cmd/issue/artifact/create/create.go:285–355  ·  view source on GitHub ↗
(opts *CreateOptions)

Source from the content-addressed store, hash-verified

283}
284
285func createRun(opts *CreateOptions) error {
286 repo, err := opts.BaseRepo()
287 if err != nil {
288 return err
289 }
290 if err := shared.CheckHost(repo.RepoHost()); err != nil {
291 return err
292 }
293
294 // Every artifact is read and checked before any request, so a file that
295 // can't be used fails the whole command and nothing is created.
296 artifacts := make([]artifact, 0, len(opts.Sources))
297 for _, s := range opts.Sources {
298 a, err := readSource(s, opts.IO.In, opts.Type)
299 if err != nil {
300 return err
301 }
302 artifacts = append(artifacts, a)
303 }
304
305 c, err := opts.Client()
306 if err != nil {
307 return err
308 }
309
310 if len(opts.Assets) > 0 {
311 uploader, err := shared.NewUploader(c, repo, opts.IssueNumber, opts.HttpClient)
312 if err != nil {
313 return err
314 }
315 if err := attach(opts, uploader, artifacts); err != nil {
316 return err
317 }
318 } else if err := shared.CheckIssue(c, repo, opts.IssueNumber); err != nil {
319 return err
320 }
321
322 issueRef := fmt.Sprintf("%s#%d", ghrepo.FullName(repo), opts.IssueNumber)
323 cs := opts.IO.ColorScheme()
324 failed := false
325 for _, a := range artifacts {
326 result := shared.Result{Name: text.RemoveExcessiveWhitespace(a.name), Source: a.source.arg}
327 if a.skip {
328 shared.PrintFailure(opts.IO, result, createAction(a), a.attachErr)
329 failed = true
330 continue
331 }
332
333 created, err := c.Create(repo, opts.IssueNumber, a.artifactType, a.name, a.body)
334 if err != nil {
335 shared.PrintFailure(opts.IO, result, createAction(a), err)
336 failed = true
337 continue
338 }
339
340 result.Number = created.Number
341 result.Name = text.RemoveExcessiveWhitespace(created.Name)
342 message := fmt.Sprintf("Created artifact %d (%s) on %s", created.Number, result.Name, issueRef)

Callers 2

TestCreateRunFunction · 0.70
NewCmdCreateFunction · 0.70

Calls 15

CheckHostFunction · 0.92
NewUploaderFunction · 0.92
CheckIssueFunction · 0.92
FullNameFunction · 0.92
PrintFailureFunction · 0.92
PrintPartialFailureFunction · 0.92
PrintSuccessFunction · 0.92
readSourceFunction · 0.85
attachFunction · 0.85
createActionFunction · 0.85
ColorSchemeMethod · 0.80

Tested by 1

TestCreateRunFunction · 0.56