/// <summary> /// Downloads data from CiDataProvider for given project /// </summary> /// <param name="projectId"></param> /// <returns>All pipelines</returns> public async Task UpdateCiDataForProjectAsync(int projectId) { var project = await GetProjectByIdAsync(projectId); if (project == null) { return; } PipelinesMerger merger = new PipelinesMerger(); var dataProvider = _ciDataProviderFactory.CreateForProviderName(project.DataProviderName); var staticBranchesNamesDb = await _staticBranchPanelRepository.GetBranchNamesFromStaticPanelsForProject(projectId); var staticBranchesPipelines = await Task.WhenAll(staticBranchesNamesDb.Select(b => dataProvider.FetchPipeLineByBranch(project.ApiHostUrl, project.ApiAuthenticationToken, project.ApiProjectId, b))); var targetPipelineNumber = project.PipelinesNumber - project.Pipelines.Count; await DownloadNewestPipelinesNotInBrancNameList(dataProvider, project, targetPipelineNumber, staticBranchesNamesDb, merger); ////Merge var mergeResult = merger.MergePipelines(project.Pipelines, staticBranchesPipelines, project.PipelinesNumber); await SaveMergedInDB(mergeResult, project); _logger.LogInformation($"Updated cidata for project: {project.Id}"); }
private async Task InsertPipelineToDB(Pipeline pipeline, Project project) { var staticBranchesNamesDb = await _staticBranchPanelRepository.GetBranchNamesFromStaticPanelsForProject(project.Id); PipelinesMerger merger = new PipelinesMerger(); List <Pipeline> projectPipelines = new List <Pipeline>(project.Pipelines); merger.AddPipelinesPageAtEnd(new List <Pipeline>() { pipeline }); var staticPipelines = project.Pipelines.Where(p => staticBranchesNamesDb.Contains(p.Ref)); var mergeResult = merger.MergePipelines(project.Pipelines, staticPipelines, project.PipelinesNumber); await SaveMergedInDB(mergeResult, project); }