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

Function preloadWorkflowNames

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

Source from the content-addressed store, hash-verified

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

Callers 1

GetRunsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected