Browse Source

build repository if possible even abp-build-config.json doesn't exist in the root directory

pull/6096/head
İsmail ÇAĞDAŞ 6 years ago
parent
commit
6251840a2c
  1. 56
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Build/FileSystemDotNetProjectBuildConfigReader.cs

56
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Build/FileSystemDotNetProjectBuildConfigReader.cs

@ -1,6 +1,7 @@
using System; using System;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions;
using LibGit2Sharp; using LibGit2Sharp;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.Json; using Volo.Abp.Json;
@ -45,11 +46,58 @@ namespace Volo.Abp.Cli.Build
return buildConfig; return buildConfig;
} }
Console.WriteLine( if (configFiles.Length > 1)
"There are more than 1 config (abp-build-config.json) file in the directory!" {
); 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) private void SetBranchNames(GitRepository gitRepository)

Loading…
Cancel
Save