Beispiel #1
0
        public async Task Task_fails_if_multiple_files_in_the_override_directory_resolve_to_the_same_commit()
        {
            // ARRANGE
            using var overrideDirectory = new TemporaryDirectory();

            var config = ChangeLogConfigurationLoader.GetDefaultConfiguration();
            {
                config.MessageOverrides.SourceDirectoryPath = overrideDirectory;
            }

            var commit1 = GetGitCommit(id: TestGitIds.Id1, commitMessage: "Original Message 1");
            var commit2 = GetGitCommit(id: TestGitIds.Id2, commitMessage: "Original Message 2");

            var repo = new Mock <IGitRepository>(MockBehavior.Strict);
            {
                repo.SetupTryGetCommit();
                repo.SetupTryGetCommit(commit1);
                repo.SetupTryGetCommit(commit2);
            }

            var versionChangeLog = GetSingleVersionChangeLog("1.2.3", TestGitIds.Id1);

            {
                versionChangeLog.Add(commit1);
                versionChangeLog.Add(commit2);
            }

            overrideDirectory.AddFile(commit2.Id.ToString(abbreviate: true), "Overridden Message 2.1");
            overrideDirectory.AddFile(commit2.Id.ToString(abbreviate: false), "Overridden Message 2.2");

            var sut = new LoadMessageOverridesFromFileSystemTask(m_Logger, config, repo.Object);

            // ACT
            var result = await sut.RunAsync(new ApplicationChangeLog()
            {
                versionChangeLog
            });

            // ASSERT
            Assert.Equal(ChangeLogTaskResult.Error, result);
            Assert.Collection(
                versionChangeLog.AllCommits,
                c => Assert.Equal(commit1, c),
                c => Assert.Equal(commit2, c)
                );
        }
Beispiel #2
0
        public async Task The_expected_configuration_file_is_used(string[] configurationFilesOnDisk, string?configurationFileParameter, string expectedConfigurationFile)
        {
            // ARRANGE
            using var temporaryDirectory = new TemporaryDirectory();

            var git = new GitWrapper(temporaryDirectory, m_TestOutputHelper);
            await git.InitAsync();

            await git.ConfigAsync("user.name", "Example");

            await git.ConfigAsync("user.email", "*****@*****.**");

            // Create all configuration files with distinct output path settings
            var outputNames = new Dictionary <string, string>();

            foreach (var configurationFilePath in configurationFilesOnDisk)
            {
                var outputName = $"{Guid.NewGuid()}.md";
                temporaryDirectory.AddFile(
                    configurationFilePath,
                    $@"{{ ""changelog"" : {{ ""outputPath"" : ""{outputName}"" }} }}"
                    );

                outputNames.Add(configurationFilePath, outputName);
            }

            // Determine the expected output path (based on the output path we can determine which configuration file was used).
            // If none of the configuration file is expected to be used (expectedConfigurationFile is null), expect the changelog to be written to the default location
            var expectedOutputPath = expectedConfigurationFile is null
                ? Path.Combine(temporaryDirectory, "changelog.md")
                : Path.Combine(temporaryDirectory, outputNames[expectedConfigurationFile]);

            var args = new List <string>()
            {
                "--verbose"
            };

            // When specified, append the configurationFilePath commandline parameter
            if (configurationFileParameter is not null)
            {
                args.Add("--configurationFilePath");
                args.Add(configurationFileParameter);
            }

            // ACT
            var result = await RunApplicationAsync(
                args : args,
                workingDirectory : temporaryDirectory,
                commandId : $"{nameof(The_expected_configuration_file_is_used)}([{String.Join(",", configurationFilesOnDisk)}], \"{configurationFileParameter}\", \"{expectedConfigurationFile}\")"
                );

            // ASSERT
            Assert.Equal(0, result.ExitCode);
            Assert.True(File.Exists(expectedOutputPath));
        }
Beispiel #3
0
        public async Task Task_replaces_commit_messages_with_messages_from_the_configured_directory(string?sourceDirectoryPath)
        {
            // ARRANGE
            using var repositoryDirectory = new TemporaryDirectory();

            var config = ChangeLogConfigurationLoader.GetDefaultConfiguration();
            {
                config.RepositoryPath = repositoryDirectory;

                if (sourceDirectoryPath is not null)
                {
                    config.MessageOverrides.SourceDirectoryPath = sourceDirectoryPath;
                }
            }


            var commit1 = GetGitCommit(id: TestGitIds.Id1, commitMessage: "Original Message 1");
            var commit2 = GetGitCommit(id: TestGitIds.Id2, commitMessage: "Original Message 2");

            var repo = new Mock <IGitRepository>(MockBehavior.Strict);
            {
                repo.SetupTryGetCommit();
                repo.SetupTryGetCommit(commit1);
                repo.SetupTryGetCommit(commit2);
            }

            var versionChangeLog = GetSingleVersionChangeLog("1.2.3", TestGitIds.Id1);

            {
                versionChangeLog.Add(commit1);
                versionChangeLog.Add(commit2);
            }

            repositoryDirectory.AddFile(
                $"{sourceDirectoryPath ?? ".config/changelog/message-overrides"}/{commit2.Id.ToString(abbreviate: false)}",
                "Overridden Message 2");

            var sut = new LoadMessageOverridesFromFileSystemTask(m_Logger, config, repo.Object);

            // ACT
            var result = await sut.RunAsync(new ApplicationChangeLog()
            {
                versionChangeLog
            });

            // ASSERT
            Assert.Equal(ChangeLogTaskResult.Success, result);
            Assert.Collection(
                versionChangeLog.AllCommits,
                c => Assert.Equal(commit1, c),
                c => Assert.Equal(commit2.WithCommitMessage("Overridden Message 2"), c)
                );
        }
Beispiel #4
0
        public async Task Task_ignores_files_in_the_override_directory_if_the_commit_cannot_be_resolved()
        {
            // ARRANGE
            using var overrideDirectory = new TemporaryDirectory();

            var config = ChangeLogConfigurationLoader.GetDefaultConfiguration();
            {
                config.MessageOverrides.SourceDirectoryPath = overrideDirectory;
            }

            var commit1 = GetGitCommit(id: TestGitIds.Id1, commitMessage: "Original Message 1");
            var commit2 = GetGitCommit(id: TestGitIds.Id2, commitMessage: "Original Message 2");

            var repo = new Mock <IGitRepository>(MockBehavior.Strict);
            {
                repo.SetupTryGetCommit();
                repo.SetupTryGetCommit(commit1);
                repo.SetupTryGetCommit(commit2);
            }

            var versionChangeLog = GetSingleVersionChangeLog("1.2.3", TestGitIds.Id1);

            {
                versionChangeLog.Add(commit1);
                versionChangeLog.Add(commit2);
            }

            overrideDirectory.AddFile("not-a-commit-id", "Some content");

            var sut = new LoadMessageOverridesFromFileSystemTask(m_Logger, config, repo.Object);

            // ACT
            var result = await sut.RunAsync(new ApplicationChangeLog()
            {
                versionChangeLog
            });

            // ASSERT
            Assert.Equal(ChangeLogTaskResult.Success, result);
            Assert.Collection(
                versionChangeLog.AllCommits,
                c => Assert.Equal(commit1, c),
                c => Assert.Equal(commit2, c)
                );
        }