From 6251840a2c356db470fe0474b232726edf8eabac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0smail=20=C3=87A=C4=9EDA=C5=9E?= Date: Thu, 5 Nov 2020 16:36:52 +0300 Subject: [PATCH] build repository if possible even abp-build-config.json doesn't exist in the root directory --- ...ileSystemDotNetProjectBuildConfigReader.cs | 56 +++++++++++++++++-- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Build/FileSystemDotNetProjectBuildConfigReader.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Build/FileSystemDotNetProjectBuildConfigReader.cs index 5aed3d0941..bb714f13aa 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Build/FileSystemDotNetProjectBuildConfigReader.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Build/FileSystemDotNetProjectBuildConfigReader.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Linq; +using System.Text.RegularExpressions; using LibGit2Sharp; using Volo.Abp.DependencyInjection; using Volo.Abp.Json; @@ -45,11 +46,58 @@ namespace Volo.Abp.Cli.Build return buildConfig; } - Console.WriteLine( - "There are more than 1 config (abp-build-config.json) file in the directory!" - ); + if (configFiles.Length > 1) + { + throw new Exception( + "There are more than 1 config (abp-build-config.json) file in the directory!" + ); + } + + // use current directory to get repository info + var gitFolderPath = string.Concat(directoryPath, @"\.git"); + if (!Directory.Exists(gitFolderPath)) + { + throw new Exception("There is no solution file (*.sln) and " + _buildConfigName + + " in the working directory and working directory is not a GIT repository !"); + } + + using (var repo = new Repository(string.Concat(directoryPath, @"\.git"))) + { + var repositoryName = GetRepositoryNameFromRepositoryInfo(repo); + + return new DotNetProjectBuildConfig + { + GitRepository = new GitRepository(repositoryName, repo.Head.FriendlyName, directoryPath) + }; + } + } + + private string GetRepositoryNameFromRepositoryInfo(Repository repository) + { + var remote = repository.Network.Remotes.FirstOrDefault(r => r.Name == "origin"); + if (remote == null) + { + throw new Exception("Remote origin is null for given repository !"); + } + + var remoteUrl = remote.Url; + + remoteUrl = Regex.Replace(remoteUrl, @"\.git$", ""); - throw new Exception("There is no solution file (*.sln) or " + _buildConfigName + " in the working directory !"); + remoteUrl = Regex.Replace(remoteUrl, "^git@", "https://"); + remoteUrl = Regex.Replace(remoteUrl, "^https:git@", "https://"); + remoteUrl = Regex.Replace(remoteUrl, ".com:", ".com/"); + + var remoteUri = new Uri(remoteUrl); + var pathSegments = remoteUri.AbsolutePath.Split("/", StringSplitOptions.RemoveEmptyEntries); + + if (pathSegments != null && pathSegments.Length >= 2) + { + var repo = pathSegments[1]; + return repo; + } + + throw new Exception("Couldn't find repository name using remote origin url !"); } private void SetBranchNames(GitRepository gitRepository)