(project *models.Project, withLastPipeline bool)
| 450 | } |
| 451 | |
| 452 | func makeProjectOutput(project *models.Project, withLastPipeline bool) (*models.ApiOutputProject, errors.Error) { |
| 453 | projectOutput := &models.ApiOutputProject{} |
| 454 | projectOutput.Project = *project |
| 455 | // load project metrics |
| 456 | projectMetrics := make([]models.ProjectMetricSetting, 0) |
| 457 | err := db.All(&projectMetrics, dal.Where("project_name = ?", projectOutput.Name)) |
| 458 | if err != nil { |
| 459 | return nil, errors.Default.Wrap(err, "failed to load project metrics") |
| 460 | } |
| 461 | // convert metric to api output |
| 462 | if len(projectMetrics) > 0 { |
| 463 | baseMetrics := make([]*models.BaseMetric, len(projectMetrics)) |
| 464 | for i, projectMetric := range projectMetrics { |
| 465 | baseMetric := projectMetric.BaseMetric |
| 466 | baseMetrics[i] = &baseMetric |
| 467 | } |
| 468 | projectOutput.Metrics = baseMetrics |
| 469 | } |
| 470 | |
| 471 | // load blueprint |
| 472 | projectOutput.Blueprint, err = GetBlueprintByProjectName(projectOutput.Name) |
| 473 | if err != nil { |
| 474 | return nil, errors.Default.Wrap(err, "Error to get blueprint by project") |
| 475 | } |
| 476 | if projectOutput.Blueprint != nil { |
| 477 | if err := SanitizeBlueprint(projectOutput.Blueprint); err != nil { |
| 478 | return nil, errors.Convert(err) |
| 479 | } |
| 480 | } |
| 481 | if withLastPipeline { |
| 482 | if projectOutput.Blueprint == nil { |
| 483 | logger.Warn(fmt.Errorf("blueprint is nil"), "want to get latest pipeline, but blueprint is nil") |
| 484 | } else { |
| 485 | pipelines, pipelinesCount, err := GetPipelines(&PipelineQuery{ |
| 486 | BlueprintId: projectOutput.Blueprint.ID, |
| 487 | Pagination: Pagination{ |
| 488 | PageSize: 1, |
| 489 | Page: 1, |
| 490 | }, |
| 491 | }, true) |
| 492 | if err != nil { |
| 493 | logger.Error(err, "GetPipelines, blueprint id: %d", projectOutput.Blueprint.ID) |
| 494 | return nil, errors.Default.Wrap(err, "Error to get pipeline by blueprint id") |
| 495 | } |
| 496 | if pipelinesCount > 0 { |
| 497 | projectOutput.LastPipeline = pipelines[0] |
| 498 | } |
| 499 | } |
| 500 | } |
| 501 | return projectOutput, err |
| 502 | } |
no test coverage detected