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