public void Set(string buildNamePrefix, GitRepository repository, GitRepositoryBuildStatus status)
        {
            var existingRepositoryStatus = Get(buildNamePrefix, repository);

            var buildStatusFile = Path.Combine(
                CliPaths.Build,
                status.GetUniqueName(buildNamePrefix)
                ) + ".json";

            if (File.Exists(buildStatusFile))
            {
                FileHelper.DeleteIfExists(buildStatusFile);
            }

            if (existingRepositoryStatus != null)
            {
                existingRepositoryStatus.MergeWith(status);

                using (var file = File.CreateText(buildStatusFile))
                {
                    new JsonSerializer {
                        Formatting = Formatting.Indented
                    }.Serialize(file, existingRepositoryStatus);
                }
            }
            else
            {
                using (var file = File.CreateText(buildStatusFile))
                {
                    new JsonSerializer {
                        Formatting = Formatting.Indented
                    }.Serialize(file, status);
                }
            }
        }
Пример #2
0
        public void GetUniqueName_Test()
        {
            var existingBuildStatus = new GitRepositoryBuildStatus("repo-1", "dev")
            {
                DependingRepositories = new List <GitRepositoryBuildStatus>()
                {
                    new GitRepositoryBuildStatus("repo-2", "dev")
                    {
                        DependingRepositories = new List <GitRepositoryBuildStatus>()
                        {
                            new GitRepositoryBuildStatus("repo-3", "dev")
                        }
                    },
                    new GitRepositoryBuildStatus("repo-4", "dev")
                }
            };

            existingBuildStatus.GetUniqueName("").ShouldBe("B25C935F97D7B3375530A96B392B7644");
            existingBuildStatus.GetUniqueName("production").ShouldBe("production_B25C935F97D7B3375530A96B392B7644");
        }