<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sriracha.Deploy.Data.Dto;
using Sriracha.Deploy.Data.Repository;

namespace Sriracha.Deploy.Data.Impl
{
	public class BuildManager: IBuildManager
	{
		private readonly IFileRepository _fileRepository;
		private readonly IBuildRepository _buildRepository;
		private readonly IProjectRepository _projectRepository;

		public BuildManager(IBuildRepository buildRepository, IFileRepository fileRepository, IProjectRepository projectRepository)
		{
			this._fileRepository = DIHelper.VerifyParameter(fileRepository);
			this._buildRepository = DIHelper.VerifyParameter(buildRepository);
			this._projectRepository = DIHelper.VerifyParameter(projectRepository);
		}

		public IEnumerable<DeployBuild> GetBuildList(string projectId = null, string branchId = null, string componentId = null)
		{
			return this._buildRepository.GetBuildList(projectId, branchId, componentId);
		}

		public DeployBuild CreateBuild(string projectId, string componentId, string branchId, string fileName, byte[] fileData, string version)
		{
			var project = _projectRepository.TryGetProject(projectId);
			if(project == null)
			{
				project = _projectRepository.GetProjectByName(projectId);
			}
			var branch = _projectRepository.GetBranch(project, branchId);
			var component = _projectRepository.GetComponent(project, componentId);
			var file = this._fileRepository.CreateFile(fileName, fileData);
			return this._buildRepository.CreateBuild(projectId, project.ProjectName, componentId, component.ComponentName, branchId, branch.BranchName, file.Id, version);
		}

		public DeployBuild GetBuild(string buildId)
		{
			return this._buildRepository.GetBuild(buildId);
		}

		public DeployBuild CreateBuild(string projectId, string componentId, string branchId, string fileId, string version)
		{
			var project = _projectRepository.TryGetProject(projectId);
			if (project == null)
			{
				project = _projectRepository.TryGetProjectByName(projectId);
			}
			if(project == null)
			{
				project = _projectRepository.CreateProject(projectId);
			}
			var branch = _projectRepository.TryGetBranch(project, branchId);
			if(branch == null)
			{
				branch = _projectRepository.TryGetBranchByName(project, branchId);
			}
			if(branch == null)
			{
				branch = _projectRepository.CreateBranch(project.Id, branchId);
			}
			var component = _projectRepository.TryGetComponent(project, componentId);
			if(component == null)
			{
				component = _projectRepository.TryGetComponentByName(project, componentId);
			}
			if(component == null)
			{
				component = _projectRepository.CreateComponent(project.Id, componentId);
			}
			return this._buildRepository.CreateBuild(projectId, project.ProjectName, component.Id, component.ComponentName, branch.Id, branch.BranchName, fileId, version);
		}

		public DeployBuild UpdateBuild(string buildId, string projectId, string componentId, string branchId, string fileId, string version)
		{
			var project = _projectRepository.GetProject(projectId);
			var branch = _projectRepository.GetBranch(project, branchId);
			var component = _projectRepository.GetComponent(project, componentId);
			return this._buildRepository.UpdateBuild(buildId, projectId, project.ProjectName, componentId, component.ComponentName, branchId, branch.BranchName, fileId, version);
		}

		public void DeleteBuild(string buildId)
		{
			this._buildRepository.DeleteBuild(buildId);
		}
	}
}<commit_msg>Fix for autocreating project<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sriracha.Deploy.Data.Dto;
using Sriracha.Deploy.Data.Repository;

namespace Sriracha.Deploy.Data.Impl
{
	public class BuildManager: IBuildManager
	{
		private readonly IFileRepository _fileRepository;
		private readonly IBuildRepository _buildRepository;
		private readonly IProjectRepository _projectRepository;

		public BuildManager(IBuildRepository buildRepository, IFileRepository fileRepository, IProjectRepository projectRepository)
		{
			this._fileRepository = DIHelper.VerifyParameter(fileRepository);
			this._buildRepository = DIHelper.VerifyParameter(buildRepository);
			this._projectRepository = DIHelper.VerifyParameter(projectRepository);
		}

		public IEnumerable<DeployBuild> GetBuildList(string projectId = null, string branchId = null, string componentId = null)
		{
			return this._buildRepository.GetBuildList(projectId, branchId, componentId);
		}

		public DeployBuild CreateBuild(string projectId, string componentId, string branchId, string fileName, byte[] fileData, string version)
		{
			var project = _projectRepository.TryGetProject(projectId);
			if(project == null)
			{
				project = _projectRepository.GetProjectByName(projectId);
			}
			var branch = _projectRepository.GetBranch(project, branchId);
			var component = _projectRepository.GetComponent(project, componentId);
			var file = this._fileRepository.CreateFile(fileName, fileData);
			return this._buildRepository.CreateBuild(projectId, project.ProjectName, componentId, component.ComponentName, branchId, branch.BranchName, file.Id, version);
		}

		public DeployBuild GetBuild(string buildId)
		{
			return this._buildRepository.GetBuild(buildId);
		}

		public DeployBuild CreateBuild(string projectId, string componentId, string branchId, string fileId, string version)
		{
			var project = _projectRepository.TryGetProject(projectId);
			if (project == null)
			{
				project = _projectRepository.TryGetProjectByName(projectId);
			}
			if(project == null)
			{
				project = _projectRepository.CreateProject(projectId);
			}
			var branch = _projectRepository.TryGetBranch(project, branchId);
			if(branch == null)
			{
				branch = _projectRepository.TryGetBranchByName(project, branchId);
			}
			if(branch == null)
			{
				branch = _projectRepository.CreateBranch(project.Id, branchId);
			}
			var component = _projectRepository.TryGetComponent(project, componentId);
			if(component == null)
			{
				component = _projectRepository.TryGetComponentByName(project, componentId);
			}
			if(component == null)
			{
				component = _projectRepository.CreateComponent(project.Id, componentId);
			}
			return this._buildRepository.CreateBuild(project.Id, project.ProjectName, component.Id, component.ComponentName, branch.Id, branch.BranchName, fileId, version);
		}

		public DeployBuild UpdateBuild(string buildId, string projectId, string componentId, string branchId, string fileId, string version)
		{
			var project = _projectRepository.GetProject(projectId);
			var branch = _projectRepository.GetBranch(project, branchId);
			var component = _projectRepository.GetComponent(project, componentId);
			return this._buildRepository.UpdateBuild(buildId, projectId, project.ProjectName, componentId, component.ComponentName, branchId, branch.BranchName, fileId, version);
		}

		public void DeleteBuild(string buildId)
		{
			this._buildRepository.DeleteBuild(buildId);
		}
	}
}
{'fraction_non_alphanumeric': 0.08815152378239818, 'fraction_numerical': 0.0, 'mean_word_length': 5.496762257169288, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4542106', 'n_tokens_mistral': 2166, 'n_tokens_neox': 1931, 'n_words': 417}