MCPcopy
hub / github.com/cli/cli / preloadWorkflowNames

Function preloadWorkflowNames

pkg/cmd/run/shared/shared.go:436–471  ·  view source on GitHub ↗
(client *api.Client, repo ghrepo.Interface, runs []Run)

Source from the content-addressed store, hash-verified

434}
435
436func preloadWorkflowNames(client *api.Client, repo ghrepo.Interface, runs []Run) error {
437 workflows, err := workflowShared.GetWorkflows(client, repo, 0)
438 if err != nil {
439 return err
440 }
441
442 workflowMap := map[int64]string{}
443 for _, wf := range workflows {
444 workflowMap[wf.ID] = wf.Name
445 }
446
447 for i, run := range runs {
448 if _, ok := workflowMap[run.WorkflowID]; !ok {
449 // Look up workflow by ID because it may have been deleted
450 workflow, err := workflowShared.GetWorkflow(client, repo, run.WorkflowID)
451 // If the error is an httpError and it is a 404, this is likely a
452 // organization or enterprise ruleset workflow. The user does not
453 // have permissions to view the details of the workflow, so we cannot
454 // look it up directly without receiving a 404, but it is nonetheless
455 // in the workflow run list. To handle this, we set the workflow name
456 // to an empty string.
457 // Deciding to put this here instead of in GetWorkflow to allow
458 // the caller to decide what a 404 means.
459 if httpErr, ok := err.(api.HTTPError); ok && httpErr.StatusCode == 404 {
460 workflowMap[run.WorkflowID] = ""
461 continue
462 }
463 if err != nil {
464 return err
465 }
466 workflowMap[run.WorkflowID] = workflow.Name
467 }
468 runs[i].workflowName = workflowMap[run.WorkflowID]
469 }
470 return nil
471}
472
473type JobsPayload struct {
474 TotalCount int `json:"total_count"`

Callers 1

GetRunsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected