public GitLabLinkTask(ILogger <GitLabLinkTask> logger, ChangeLogConfiguration configuration, IGitRepository repository, IGitLabClientFactory clientFactory) { m_Logger = logger ?? throw new ArgumentNullException(nameof(logger)); m_Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); m_Repository = repository ?? throw new ArgumentNullException(nameof(repository)); m_ClientFactory = clientFactory ?? throw new ArgumentNullException(nameof(clientFactory)); }
public void EntryGroups_returns_entries_grouped_by_type_in_the_configured_order() { // ARRANGE var config = new ChangeLogConfiguration() { EntryTypes = new Dictionary <string, ChangeLogConfiguration.EntryTypeConfiguration>() { { "feat", new ChangeLogConfiguration.EntryTypeConfiguration() { DisplayName = "New Features", Priority = 100 } }, { "fix", new ChangeLogConfiguration.EntryTypeConfiguration() { DisplayName = "Bug Fixes", Priority = 90 } }, { "docs", new ChangeLogConfiguration.EntryTypeConfiguration() { DisplayName = "Documentation Updates", Priority = 80 } }, { "build", new ChangeLogConfiguration.EntryTypeConfiguration() { DisplayName = "Build System Changes", Priority = 70 } } } }; var changelog = GetSingleVersionChangeLog("1.2.3", entries: new[] { GetChangeLogEntry(type: "feat"), GetChangeLogEntry(type: "fix"), GetChangeLogEntry(type: "feat"), GetChangeLogEntry(type: "refactor"), GetChangeLogEntry(type: "docs"), }); var sut = new SingleVersionChangeLogViewModel(config, changelog); // ACT / ASSERT Assert.Collection( sut.EntryGroups, features => { Assert.Equal("New Features", features.DisplayName); Assert.Equal(2, features.Entries.Count()); }, bugfixes => { Assert.Equal("Bug Fixes", bugfixes.DisplayName); Assert.Single(bugfixes.Entries); }, docsChanges => { Assert.Equal("Documentation Updates", docsChanges.DisplayName); Assert.Single(docsChanges.Entries); }, refactorings => { Assert.Equal("refactor", refactorings.DisplayName); Assert.Single(refactorings.Entries); }); }
public async Task Run_removes_the_expected_changelog_entries(string versionRange) { // ARRANGE var config = new ChangeLogConfiguration() { VersionRange = versionRange }; var sut = new FilterVersionsTask(m_Logger, config); var version1ChangeLog = GetSingleVersionChangeLog("1.2.3", null); var version2ChangeLog = GetSingleVersionChangeLog("4.5.6", null); var changeLog = new ApplicationChangeLog() { version1ChangeLog, version2ChangeLog }; // ACT var result = await sut.RunAsync(changeLog); // ASSERT var remainingEntry = Assert.Single(changeLog.ChangeLogs); Assert.Equal(version2ChangeLog, remainingEntry); Assert.Equal(ChangeLogTaskResult.Success, result); }
public async Task Run_succeeds_if_the_current_version_already_exists_and_points_to_the_same_commit() { // ARRANGE var config = new ChangeLogConfiguration() { CurrentVersion = "1.2.3" }; var head = GetGitCommit(id: TestGitIds.Id1); m_RepositoryMock.Setup(x => x.Head).Returns(head); var changeLog = new ApplicationChangeLog() { GetSingleVersionChangeLog(version: "1.2.3", commitId: head.Id) }; var sut = new LoadCurrentVersionTask(m_Logger, config, m_RepositoryMock.Object); // ACT var result = await sut.RunAsync(changeLog); // ASSERT Assert.Equal(ChangeLogTaskResult.Success, result); var singleVersionChangeLog = Assert.Single(changeLog.ChangeLogs); Assert.Equal(NuGetVersion.Parse("1.2.3"), singleVersionChangeLog.Version.Version); }
public async Task Run_creates_the_output_directory_before_calling_the_template() { // ARRANGE using var temporaryDirectory = new TemporaryDirectory(); var outputDirectory = Path.Combine(temporaryDirectory, "dir1"); var configuration = new ChangeLogConfiguration() { OutputPath = Path.Combine(outputDirectory, "changelog.md") }; var templateMock = new Mock <ITemplate>(MockBehavior.Strict); templateMock.Setup(x => x.SaveChangeLog(It.IsAny <ApplicationChangeLog>(), It.IsAny <string>())); var sut = new RenderTemplateTask(m_Logger, configuration, templateMock.Object); // ACT var result = await sut.RunAsync(new ApplicationChangeLog()); // ASSERT Assert.Equal(ChangeLogTaskResult.Success, result); Assert.True(Directory.Exists(outputDirectory)); templateMock.Verify(x => x.SaveChangeLog(It.IsAny <ApplicationChangeLog>(), It.IsAny <string>()), Times.Once); templateMock.Verify(x => x.SaveChangeLog(It.IsAny <ApplicationChangeLog>(), configuration.OutputPath), Times.Once); }
public async Task Run_adds_expected_version_to_changelog() { // ARRANGE var config = new ChangeLogConfiguration() { CurrentVersion = "1.2.3" }; var head = GetGitCommit(id: TestGitIds.Id1); m_RepositoryMock.Setup(x => x.Head).Returns(head); var sut = new LoadCurrentVersionTask(m_Logger, config, m_RepositoryMock.Object); var changeLog = new ApplicationChangeLog(); // ACT var result = await sut.RunAsync(changeLog); // ASSERT Assert.Equal(ChangeLogTaskResult.Success, result); var addedVersion = Assert.Single(changeLog.Versions); Assert.Equal(NuGetVersion.Parse("1.2.3"), addedVersion.Version); Assert.Equal(head.Id, addedVersion.Commit); }
public async Task Run_fails_if_the_current_version_already_exists_and_points_to_a_different_commit() { // ARRANGE var config = new ChangeLogConfiguration() { CurrentVersion = "1.2.3" }; var head = GetGitCommit(id: TestGitIds.Id1); m_RepositoryMock.Setup(x => x.Head).Returns(head); var changeLog = new ApplicationChangeLog() { GetSingleVersionChangeLog(version: "1.2.3", commitId: TestGitIds.Id2) }; var sut = new LoadCurrentVersionTask(m_Logger, config, m_RepositoryMock.Object); // ACT var result = await sut.RunAsync(changeLog); // ASSERT Assert.Equal(ChangeLogTaskResult.Error, result); }
public void AddIntegrationTasks_adds_expected_tasks(ChangeLogConfiguration.IntegrationProvider integrationProvider) { // ARRANGE var configuration = new ChangeLogConfiguration(); configuration.Integrations.Provider = integrationProvider; using var container = BuildContainer(b => b.RegisterInstance(configuration)); var pipelineBuilderMock = new Mock <IChangeLogPipelineBuilder>(MockBehavior.Strict); pipelineBuilderMock.Setup(x => x.Container).Returns(container); pipelineBuilderMock.Setup(x => x.AddTask <GitHubLinkTask>()).Returns(pipelineBuilderMock.Object); pipelineBuilderMock.Setup(x => x.AddTask <GitLabLinkTask>()).Returns(pipelineBuilderMock.Object); // ACT pipelineBuilderMock.Object.AddIntegrationTasks(); // ASSERT pipelineBuilderMock.Verify( x => x.AddTask <GitHubLinkTask>(), integrationProvider == ChangeLogConfiguration.IntegrationProvider.GitHub ? Times.Once() : Times.Never() ); pipelineBuilderMock.Verify( x => x.AddTask <GitLabLinkTask>(), integrationProvider == ChangeLogConfiguration.IntegrationProvider.GitLab ? Times.Once() : Times.Never() ); }
public ChangeLogEntryViewModel(ChangeLogConfiguration configuration, ChangeLogEntry model) { m_Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); m_Model = model ?? throw new ArgumentNullException(nameof(model)); Footers = m_Model.Footers.Select(x => new ChangeLogEntryFooterViewModel(m_Configuration, x)).ToArray(); }
public void RegisterTemplate_can_register_a_template_for_every_supported_template_name(ChangeLogConfiguration.TemplateName templateName) { // ARRANGE var configuration = new ChangeLogConfiguration() { Template = new ChangeLogConfiguration.TemplateConfiguration() { Name = templateName } }; var containerBuilder = new ContainerBuilder(); containerBuilder.RegisterInstance(configuration).SingleInstance(); containerBuilder.RegisterInstance(NullLogger <DefaultTemplate> .Instance).As <ILogger <DefaultTemplate> >(); // ACT containerBuilder.RegisterTemplate(configuration.Template); // ASSERT var container = containerBuilder.Build(); var template = container.Resolve <ITemplate>(); Assert.NotNull(template); }
public LoadMessageOverridesFromFileSystemTask(ILogger <LoadMessageOverridesFromFileSystemTask> logger, ChangeLogConfiguration configuration, IGitRepository repository) : base(logger) { m_Logger = logger ?? throw new ArgumentNullException(nameof(logger)); m_Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); m_Repository = repository ?? throw new ArgumentNullException(nameof(repository)); m_OverrideMessages = new(LoadOverrideMessages); }
public async Task Run_does_not_add_any_versions_if_no_tag_patterns_are_specified() { // ARRANGE var tags = new GitTag[] { new GitTag("1.2.3-alpha", new GitId("01")), new GitTag("4.5.6", new GitId("02")) }; var repoMock = new Mock <IGitRepository>(MockBehavior.Strict); repoMock.Setup(x => x.GetTags()).Returns(tags); var config = new ChangeLogConfiguration() { TagPatterns = Array.Empty <string>() }; var sut = new LoadVersionsFromTagsTask(m_Logger, config, repoMock.Object); // ACT var changeLog = new ApplicationChangeLog(); var result = await sut.RunAsync(changeLog); // ASSERT Assert.NotNull(changeLog.Versions); Assert.Empty(changeLog.Versions); Assert.Equal(ChangeLogTaskResult.Skipped, result); }
public LoadVersionsFromTagsTask(ILogger <LoadVersionsFromTagsTask> logger, ChangeLogConfiguration configuration, IGitRepository repository) { m_Logger = logger ?? throw new ArgumentNullException(nameof(logger)); m_Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); m_Repository = repository ?? throw new ArgumentNullException(nameof(repository)); m_TagPatterns = m_Configuration.TagPatterns.Select(x => new Regex(x, s_RegexOptions)).ToArray(); }
public GitLabLinkTaskTest(ITestOutputHelper testOutputHelper) { m_Logger = new XunitLogger <GitLabLinkTask>(testOutputHelper); m_DefaultConfiguration = ChangeLogConfigurationLoader.GetDefaultConfiguration(); m_ClientFactoryMock = new(MockBehavior.Strict); m_ClientMock = new(); m_ClientFactoryMock.Setup(x => x.CreateClient(It.IsAny <string>())).Returns(m_ClientMock.Object); m_RepositoryMock = new Mock <IGitRepository>(MockBehavior.Strict); }
/// <summary> /// Gets the display name for the footer's name. /// </summary> /// <returns> /// Returns the display name for the footer's name as configured in <paramref name="configuration"/>. /// If no display name is configured for the scope, returns the footer name. /// </returns> public static string GetFooterDisplayName(this ChangeLogEntryFooter footer, ChangeLogConfiguration configuration) { var displayName = configuration.Footers .FirstOrDefault(c => !String.IsNullOrWhiteSpace(c.Name) && new CommitMessageFooterName(c.Name).Equals(footer.Name) )?.DisplayName; return(!String.IsNullOrWhiteSpace(displayName) ? displayName : footer.Name.Value); }
public void EntryGroups_returns_configured_groups() { // ARRANGE var config = new ChangeLogConfiguration() { EntryTypes = new[] { new ChangeLogConfiguration.EntryTypeConfiguration() { Type = "feat", DisplayName = "New Features" }, new ChangeLogConfiguration.EntryTypeConfiguration() { Type = "fix", DisplayName = "Bug Fixes" }, new ChangeLogConfiguration.EntryTypeConfiguration() { Type = "docs", DisplayName = "Documentation Updates" }, new ChangeLogConfiguration.EntryTypeConfiguration() { Type = "build", DisplayName = "Build System Changes" }, } }; var changelog = GetSingleVersionChangeLog("1.2.3", entries: new[] { GetChangeLogEntry(type: "feat"), GetChangeLogEntry(type: "feat"), GetChangeLogEntry(type: "docs"), GetChangeLogEntry(type: "refactor"), GetChangeLogEntry(type: "fix"), }); var sut = new SingleVersionChangeLogViewModel(config, changelog); // ACT / ASSERT Assert.Collection( sut.EntryGroups, features => { Assert.Equal("New Features", features.DisplayName); Assert.Equal(2, features.Entries.Count()); }, bugfixes => { Assert.Equal("Bug Fixes", bugfixes.DisplayName); Assert.Single(bugfixes.Entries); }, docsChanges => { Assert.Equal("Documentation Updates", docsChanges.DisplayName); Assert.Single(docsChanges.Entries); }); }
/// <summary> /// Gets the display name for the entry's scope. /// </summary> /// <returns> /// Returns the display name for the entry's scope as configured in <paramref name="configuration"/>. /// If the entry has no scope, returns null. /// If no display name is configured for the scope, returns the scope itself. /// </returns> public static string?GetScopeDisplayName(this ChangeLogEntry entry, ChangeLogConfiguration configuration) { if (String.IsNullOrEmpty(entry.Scope)) { return(null); } var displayName = configuration.Scopes.FirstOrDefault(scope => StringComparer.OrdinalIgnoreCase.Equals(scope.Name, entry.Scope))?.DisplayName; return(!String.IsNullOrWhiteSpace(displayName) ? displayName : entry.Scope); }
public void Repository_must_not_be_null() { // ARRANGE var config = new ChangeLogConfiguration(); // ACT var ex = Record.Exception(() => new LoadCurrentVersionTask(logger: m_Logger, configuration: config, repository: null !)); // ASSERT var argumentNullException = Assert.IsType <ArgumentNullException>(ex); Assert.Equal("repository", argumentNullException.ParamName); }
public async Task RunAsync_removes_entries_as_according_to_the_filter_configuration() { // ARRANGE var config = new ChangeLogConfiguration() { Filter = new ChangeLogConfiguration.FilterConfiguration() { Include = new[] { new ChangeLogConfiguration.FilterExpressionConfiguration() { Type = "build" }, new ChangeLogConfiguration.FilterExpressionConfiguration() { Type = "refactor" } }, Exclude = new[] { new ChangeLogConfiguration.FilterExpressionConfiguration() { Type = "build", Scope = "ignored-scope" } }, } }; var changeLog = GetSingleVersionChangeLog("1.2.3", entries: new[] { GetChangeLogEntry(type: "feat"), GetChangeLogEntry(type: "fix"), GetChangeLogEntry(type: "refactor"), GetChangeLogEntry(type: "build", scope: "ignored-scope"), GetChangeLogEntry(type: "build"), }); var sut = new FilterEntriesTask(m_Logger, config); // ACT var result = await sut.RunAsync(new ApplicationChangeLog() { changeLog }); // ASSERT Assert.Equal(ChangeLogTaskResult.Success, result); Assert.Equal(2, changeLog.AllEntries.Count()); Assert.All(changeLog.AllEntries, e => { Assert.True(e.Type == new CommitType("build") || e.Type == new CommitType("refactor")); Assert.Null(e.Scope); }); }
public void CreateClient_succeeds_if_no_access_token_is_configured(string accessToken) { // ARRANGE var configuration = new ChangeLogConfiguration(); configuration.Integrations.GitLab.AccessToken = accessToken; var sut = new GitLabClientFactory(configuration); // ACT var client = sut.CreateClient("gitlab.com"); // ASSERT Assert.NotNull(client); }
public void AllEntries_returns_entries_in_group_order() { // ARRANGE var config = new ChangeLogConfiguration() { EntryTypes = new Dictionary <string, ChangeLogConfiguration.EntryTypeConfiguration>() { { "fix", new ChangeLogConfiguration.EntryTypeConfiguration() { Priority = 10 } }, { "feat", new ChangeLogConfiguration.EntryTypeConfiguration() { Priority = 5 } }, { "refactor", new ChangeLogConfiguration.EntryTypeConfiguration() { Priority = 20 } } } }; var entries = new[] { GetChangeLogEntry(type: "fix"), GetChangeLogEntry(type: "feat"), GetChangeLogEntry(type: "feat"), GetChangeLogEntry(type: "fix"), GetChangeLogEntry(type: "refactor"), }; var expectedOrder = new[] { entries[4], entries[0], entries[3], entries[1], entries[2] }; var changelog = GetSingleVersionChangeLog("1.2.3", entries: entries); var sut = new SingleVersionChangeLogViewModel(config, changelog); // ACT / ASSERT var assertions = expectedOrder.Select <ChangeLogEntry, Action <ChangeLogEntryViewModel> >( expected => actual => { Assert.Equal(expected.Type, actual.Type); Assert.Equal(expected.Commit, actual.Commit); } ).ToArray(); Assert.Collection(sut.AllEntries, assertions); }
public void AllEntries_returns_changes_of_all_configured_types() { // ARRANGE var config = new ChangeLogConfiguration() { EntryTypes = new[] { new ChangeLogConfiguration.EntryTypeConfiguration() { Type = "feat", DisplayName = "New Features" }, new ChangeLogConfiguration.EntryTypeConfiguration() { Type = "fix", DisplayName = "Bug Fixes" }, new ChangeLogConfiguration.EntryTypeConfiguration() { Type = "docs", DisplayName = "Documentation Updates" }, new ChangeLogConfiguration.EntryTypeConfiguration() { Type = "build", DisplayName = "Build System Changes" }, } }; var entries = new[] { GetChangeLogEntry(type: "feat"), GetChangeLogEntry(type: "feat"), GetChangeLogEntry(type: "docs"), GetChangeLogEntry(type: "refactor"), GetChangeLogEntry(type: "fix"), }; var expectedOrder = new[] { entries[0], entries[1], entries[4], entries[2] }; var sut = new SingleVersionChangeLogViewModel(config, GetSingleVersionChangeLog("1.2.3", entries: entries)); // ACT / ASSERT var assertions = expectedOrder.Select <ChangeLogEntry, Action <ChangeLogEntry> >( expected => actual => Assert.Same(expected, actual) ).ToArray(); Assert.Collection(sut.AllEntries, assertions); }
public void When_normalization_is_enabled_normalized_text_is_rendered() { // ARRANGE var testData = new TestDataFactory(); var configuration = new ChangeLogConfiguration(); configuration.Template.GitLabRelease.NormalizeReferences = true; var footerValue = new CustomTextElement() { Text = "Text", Style = TextStyle.Code, NormalizedText = "NormalizedText", NormalizedStyle = TextStyle.None }; var changeLog = new ApplicationChangeLog() { testData.GetSingleVersionChangeLog("1.2.3", entries: new[]
public void EntryGroups_have_expected_display_names() { // ARRANGE var config = new ChangeLogConfiguration() { EntryTypes = new[] { new ChangeLogConfiguration.EntryTypeConfiguration() { Type = "feat", DisplayName = "New Features" }, new ChangeLogConfiguration.EntryTypeConfiguration() { Type = "fix", DisplayName = null }, new ChangeLogConfiguration.EntryTypeConfiguration() { Type = "docs", DisplayName = "" }, new ChangeLogConfiguration.EntryTypeConfiguration() { Type = "build", DisplayName = "\t" }, } }; var changelog = GetSingleVersionChangeLog("1.2.3", entries: new[] { GetChangeLogEntry(type: "feat"), GetChangeLogEntry(type: "fix"), GetChangeLogEntry(type: "docs"), GetChangeLogEntry(type: "build"), }); var sut = new SingleVersionChangeLogViewModel(config, changelog); // ACT / ASSERT // when no display name is configured, the change type is used as display name Assert.Collection( sut.EntryGroups, features => Assert.Equal("New Features", features.DisplayName), bugfixes => Assert.Equal("fix", bugfixes.DisplayName), docsChanges => Assert.Equal("docs", docsChanges.DisplayName), buildChanges => Assert.Equal("build", buildChanges.DisplayName)); }
public async Task Task_is_skipped_if_current_version_is_not_set(string currentVersion) { // ARRANGE var config = new ChangeLogConfiguration() { CurrentVersion = currentVersion }; var sut = new LoadCurrentVersionTask(m_Logger, config, m_RepositoryMock.Object); var changeLog = new ApplicationChangeLog(); // ACT var result = await sut.RunAsync(changeLog); // ASSERT Assert.Equal(ChangeLogTaskResult.Skipped, result); Assert.Empty(changeLog.Versions); }
public void CreateClient_adds_an_access_token_if_token_is_configured() { // ARRANGE var configuration = new ChangeLogConfiguration(); configuration.Integrations.GitHub.AccessToken = "some-access-token"; var sut = new GitHubClientFactory(configuration); // ACT var client = sut.CreateClient("github.com"); // ASSERT Assert.NotNull(client); var clientConcrete = Assert.IsType <GitHubClient>(client); Assert.Equal(AuthenticationType.Oauth, clientConcrete.Credentials.AuthenticationType); Assert.Null(clientConcrete.Credentials.Login); Assert.NotNull(clientConcrete.Credentials.Password); }
public void CreateClient_succeeds_if_no_access_token_is_configured(string accessToken) { // ARRANGE var configuration = new ChangeLogConfiguration(); configuration.Integrations.GitHub.AccessToken = accessToken; var sut = new GitHubClientFactory(configuration); // ACT var client = sut.CreateClient("github.com"); // ASSERT Assert.NotNull(client); var clientConcrete = Assert.IsType <GitHubClient>(client); Assert.Equal(AuthenticationType.Anonymous, clientConcrete.Credentials.AuthenticationType); Assert.Null(clientConcrete.Credentials.Login); Assert.Null(clientConcrete.Credentials.Password); }
public ScribanBaseTemplate(ChangeLogConfiguration configuration) { m_Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); m_Filesystem = new Lazy <IFileSystem>(() => { var fileSystem = GetTemplateFileSystem(); if (!String.IsNullOrEmpty(TemplateSettings.CustomDirectory)) { var physicalFileSystem = new PhysicalFileSystem(); var path = physicalFileSystem.ConvertPathFromInternal(TemplateSettings.CustomDirectory); var aggregateFileSystem = new AggregateFileSystem(fileSystem); aggregateFileSystem.AddFileSystem(physicalFileSystem.GetOrCreateSubFileSystem(path)); fileSystem = aggregateFileSystem; } return(fileSystem); }); }
public void RegisterTemplate_throws_InvalidTemplateConfigurationException_for_invalid_template_Swetting() { // ARRANGE var templateName = (ChangeLogConfiguration.TemplateName) Enum.GetValues(typeof(ChangeLogConfiguration.TemplateName)) .Cast <int>() .Max() + 2; var configuration = new ChangeLogConfiguration() { Template = new ChangeLogConfiguration.TemplateConfiguration() { Name = templateName } }; var containerBuilder = new ContainerBuilder(); // ACT / ASSERT Assert.Throws <InvalidTemplateConfigurationException>(() => containerBuilder.RegisterTemplate(configuration.Template)); }
public void GetScopeDisplayName_returns_scope_is_no_matching_configuration_is_found() { // ARRANGE var config = new ChangeLogConfiguration() { Scopes = new[] { new ChangeLogConfiguration.ScopeConfiguration() { Name = "someScope", DisplayName = "Scope Display Name" } } }; var changeLogEntry = GetChangeLogEntry(scope: "someScopeOther"); // ACT var displayName = changeLogEntry.GetScopeDisplayName(config); // ASSERT Assert.Equal("someScopeOther", displayName); }