Ejemplo n.º 1
0
        private static void MergeNewFileRepositoryToConfig(BuildJsonConfig config)
        {
            GitDetail repoInfoFromBaseDirectory = GitUtility.GetGitDetail(Path.Combine(Environment.CurrentDirectory, config.BaseDirectory));

            if (repoInfoFromBaseDirectory?.LocalWorkingDirectory != null)
            {
                config.GlobalMetadata["baseRepositoryDirectory"] = repoInfoFromBaseDirectory.LocalWorkingDirectory;
            }

            if (repoInfoFromBaseDirectory != null && repoInfoFromBaseDirectory.RelativePath != null)
            {
                repoInfoFromBaseDirectory.RelativePath = Path.Combine(repoInfoFromBaseDirectory.RelativePath, DocAsCode.Constants.DefaultOverwriteFolderName);
            }
            object newFileRepository;

            if (config.GlobalMetadata.TryGetValue("newFileRepository", out newFileRepository))
            {
                GitDetail repoInfo = null;
                try
                {
                    repoInfo = JObject.FromObject(newFileRepository).ToObject <GitDetail>();
                }
                catch (Exception e)
                {
                    throw new DocumentException($"Unable to convert newFileRepository to GitDetail in globalMetadata: {e.Message}", e);
                }
                if (repoInfoFromBaseDirectory != null)
                {
                    if (repoInfo.RelativePath == null)
                    {
                        repoInfo.RelativePath = repoInfoFromBaseDirectory.RelativePath;
                    }
                    if (repoInfo.RemoteBranch == null)
                    {
                        repoInfo.RemoteBranch = repoInfoFromBaseDirectory.RemoteBranch;
                    }
                    if (repoInfo.RemoteRepositoryUrl == null)
                    {
                        repoInfo.RemoteRepositoryUrl = repoInfoFromBaseDirectory.RemoteRepositoryUrl;
                    }
                }
                config.GlobalMetadata["newFileRepository"] = repoInfo;
            }
            else
            {
                config.GlobalMetadata["newFileRepository"] = repoInfoFromBaseDirectory;
            }
        }
Ejemplo n.º 2
0
        private static void MergeGitContributeToConfig(BuildJsonConfig config)
        {
            GitDetail repoInfoFromBaseDirectory = GitUtility.GetGitDetail(Path.Combine(Directory.GetCurrentDirectory(), config.BaseDirectory));

            if (repoInfoFromBaseDirectory?.RelativePath != null)
            {
                repoInfoFromBaseDirectory.RelativePath = Path.Combine(repoInfoFromBaseDirectory.RelativePath, DocAsCode.Constants.DefaultOverwriteFolderName);
            }
            object gitRespositoryOpenToPublicContributors;

            if (config.GlobalMetadata.TryGetValue("_gitContribute", out gitRespositoryOpenToPublicContributors))
            {
                GitDetail repoInfo;
                try
                {
                    repoInfo = JObject.FromObject(gitRespositoryOpenToPublicContributors).ToObject <GitDetail>();
                }
                catch (Exception e)
                {
                    throw new DocumentException($"Unable to convert _gitContribute to GitDetail in globalMetadata: {e.Message}", e);
                }
                if (repoInfoFromBaseDirectory != null)
                {
                    if (repoInfo.RelativePath == null)
                    {
                        repoInfo.RelativePath = repoInfoFromBaseDirectory.RelativePath;
                    }
                    if (repoInfo.RemoteBranch == null)
                    {
                        repoInfo.RemoteBranch = repoInfoFromBaseDirectory.RemoteBranch;
                    }
                    if (repoInfo.RemoteRepositoryUrl == null)
                    {
                        repoInfo.RemoteRepositoryUrl = repoInfoFromBaseDirectory.RemoteRepositoryUrl;
                    }
                }
                config.GlobalMetadata["_gitContribute"] = repoInfo;
            }
            else
            {
                config.GlobalMetadata["_gitContribute"] = repoInfoFromBaseDirectory;
            }
        }