コード例 #1
0
        private static async Task <int> RunAsync(CommandLineParameters commandlineParameters)
        {
            var loggerOptions = commandlineParameters.Verbose
                ? new SimpleConsoleLoggerConfiguration(LogLevel.Debug, true, true)
                : new SimpleConsoleLoggerConfiguration(LogLevel.Information, false, true);

            // for validation of command line parameters, directly create a console logger
            // bypassing the DI container because we need to validate the parameters
            // before setting up DI
            var logger = new SimpleConsoleLogger(loggerOptions, "");

            if (!ValidateCommandlineParameters(commandlineParameters, logger))
            {
                return(1);
            }

            var configurationFilePath = !String.IsNullOrEmpty(commandlineParameters.ConfigurationFilePath)
                ? commandlineParameters.ConfigurationFilePath
                : Path.Combine(commandlineParameters.RepositoryPath, s_DefaultConfigurationFileName);

            var configuration = ChangeLogConfigurationLoader.GetConfiguration(configurationFilePath, commandlineParameters);

            using (var gitRepository = new GitRepository(configuration.RepositoryPath))
            {
                var containerBuilder = new ContainerBuilder();

                containerBuilder.RegisterType <ConfigurationValidator>();
                containerBuilder.RegisterInstance(configuration).SingleInstance();
                containerBuilder.RegisterInstance(gitRepository).SingleInstance().As <IGitRepository>();

                containerBuilder.RegisterLogging(loggerOptions);

                containerBuilder.RegisterType <ChangeLogPipeline>();

                containerBuilder.RegisterType <LoadCurrentVersionTask>();
                containerBuilder.RegisterType <LoadVersionsFromTagsTask>();
                containerBuilder.RegisterType <ParseCommitsTask>();
                containerBuilder.RegisterType <FilterVersionsTask>();
                containerBuilder.RegisterType <FilterEntriesTask>();
                containerBuilder.RegisterType <RenderTemplateTask>();

                containerBuilder.RegisterIntegrations();

                try
                {
                    containerBuilder.RegisterTemplate(configuration.Template);
                }
                catch (InvalidTemplateConfigurationException ex)
                {
                    logger.LogCritical($"Failed to load template: {ex.Message}");
                    return(1);
                }

                using (var container = containerBuilder.Build())
                {
                    var configurationValidator = container.Resolve <ConfigurationValidator>();

                    if (!configurationValidator.Validate(configuration))
                    {
                        logger.LogCritical($"Validation of configuration failed");
                        return(1);
                    }

                    // Note: The order of the tasks added here is important.
                    // E.g. In order for commits for versions loaded correctly, ParseCommitsTask needs to run before FilterVersionsTask
                    var pipeline = new ChangeLogPipelineBuilder(container)
                                   .AddTask <LoadCurrentVersionTask>()
                                   .AddTask <LoadVersionsFromTagsTask>()
                                   .AddTask <ParseCommitsTask>()
                                   .AddTask <FilterVersionsTask>()
                                   .AddTask <FilterEntriesTask>()
                                   .AddIntegrationTasks()
                                   .AddTask <RenderTemplateTask>()
                                   .Build();

                    var result = await pipeline.RunAsync();

                    return(result.Success ? 0 : 1);
                }
            }
        }
コード例 #2
0
        private static async Task <int> RunAsync(CommandLineParameters commandlineParameters)
        {
            var loggerOptions = commandlineParameters.Verbose
                ? new SimpleConsoleLoggerConfiguration(LogLevel.Debug, true, true)
                : new SimpleConsoleLoggerConfiguration(LogLevel.Information, false, true);

            // for validation of command line parameters, directly create a console logger
            // bypassing the DI container because we need to validate the parameters
            // before setting up DI
            var logger = new SimpleConsoleLogger(loggerOptions, "");

            if (!ValidateCommandlineParameters(commandlineParameters, logger))
            {
                return(1);
            }

            if (!TryGetRepositoryPath(commandlineParameters, logger, out var repositoryPath))
            {
                return(1);
            }

            if (!TryOpenRepository(repositoryPath, logger, out var gitRepository))
            {
                return(1);
            }

            var configurationFilePath = GetConfigurationFilePath(commandlineParameters, repositoryPath);

            if (File.Exists(configurationFilePath))
            {
                logger.LogDebug($"Using configuration file '{configurationFilePath}'");
            }
            else
            {
                logger.LogDebug("Continuing without loading a configuration file, because no configuration file was wound");
            }


            // pass repository path to configuration loader to make it available through the configuration system
            var dynamicSettings = new DynamicallyDeterminedSettings()
            {
                RepositoryPath = repositoryPath
            };

            var configuration = ChangeLogConfigurationLoader.GetConfiguration(configurationFilePath, commandlineParameters, dynamicSettings);

            using (gitRepository)
            {
                var containerBuilder = new ContainerBuilder();

                containerBuilder.RegisterType <ConfigurationValidator>();
                containerBuilder.RegisterInstance(configuration).SingleInstance();
                containerBuilder.RegisterInstance(gitRepository).SingleInstance().As <IGitRepository>();

                containerBuilder.RegisterLogging(loggerOptions);

                containerBuilder.RegisterType <ChangeLogPipeline>();

                containerBuilder.RegisterType <LoadCurrentVersionTask>();
                containerBuilder.RegisterType <LoadVersionsFromTagsTask>();
                containerBuilder.RegisterType <LoadCommitsTask>();
                containerBuilder.RegisterType <LoadMessageOverridesFromGitNotesTask>();
                containerBuilder.RegisterType <LoadMessageOverridesFromFileSystemTask>();
                containerBuilder.RegisterType <ParseCommitsTask>();
                containerBuilder.RegisterType <ParseCommitReferencesTask>();
                containerBuilder.RegisterType <FilterVersionsTask>();
                containerBuilder.RegisterType <FilterEntriesTask>();
                containerBuilder.RegisterType <ResolveEntryReferencesTask>();
                containerBuilder.RegisterType <AddCommitFooterTask>();
                containerBuilder.RegisterType <ParseWebLinksTask>();
                containerBuilder.RegisterType <RenderTemplateTask>();

                containerBuilder.RegisterIntegrations();

                try
                {
                    containerBuilder.RegisterTemplate(configuration.Template);
                }
                catch (InvalidTemplateConfigurationException ex)
                {
                    logger.LogError($"Failed to load template: {ex.Message}");
                    return(1);
                }

                using (var container = containerBuilder.Build())
                {
                    var configurationValidator = container.Resolve <ConfigurationValidator>();
                    var validationResult       = configurationValidator.Validate(configuration);

                    if (!validationResult.IsValid)
                    {
                        foreach (var error in validationResult.Errors)
                        {
                            logger.LogError($"Invalid configuration: {error.ErrorMessage}");
                        }

                        logger.LogError($"Validation of configuration failed");
                        return(1);
                    }

                    var pipeline = new ChangeLogPipelineBuilder(container)
                                   .AddTask <LoadCurrentVersionTask>()
                                   .AddTask <LoadVersionsFromTagsTask>()
                                   .AddTask <LoadCommitsTask>()
                                   .AddTaskIf <LoadMessageOverridesFromGitNotesTask>(
                        configuration.MessageOverrides.Enabled && configuration.MessageOverrides.Provider == ChangeLogConfiguration.MessageOverrideProvider.GitNotes
                        )
                                   .AddTaskIf <LoadMessageOverridesFromFileSystemTask>(
                        configuration.MessageOverrides.Enabled && configuration.MessageOverrides.Provider == ChangeLogConfiguration.MessageOverrideProvider.FileSystem
                        )
                                   .AddTask <ParseCommitsTask>()
                                   .AddTask <ParseCommitReferencesTask>()
                                   .AddTask <ParseWebLinksTask>()
                                   .AddTask <FilterVersionsTask>()
                                   .AddTask <FilterEntriesTask>()
                                   .AddTask <ResolveEntryReferencesTask>()
                                   .AddTask <AddCommitFooterTask>()
                                   .AddIntegrationTasks()
                                   .AddTask <RenderTemplateTask>()
                                   .Build();

                    var result = await pipeline.RunAsync();

                    return(result.Success ? 0 : 1);
                }
            }
        }