public static ICollection <Changelog> ParseChangelogsCache(this string filePath)
        {
            ChangelogParser?        parser = ChangelogParserProvider.GetParser(Path.GetExtension(filePath));
            ICollection <Changelog> cache;

            if (parser == null)
            {
                throw new InvalidOperationException($"{filePath} is not convertible!");
            }

            try
            {
                Console.PrintInfo($"{ChangelogGeneratorResources.PARSING_CACHE_FILE} {filePath}");
                cache = parser.ParseCache(File.ReadAllText(filePath));
            }
            catch (Exception e)
            {
                Console.PrintError($"{ChangelogGeneratorResources.PARSING_ERROR} {e.InnerException?.Message}");
                Console.PrintException(e);

                throw;
            }

            return(cache);
        }
        public static void SaveCache(this string filePath, ICollection <Changelog> cache)
        {
            ChangelogParser?parser = ChangelogParserProvider.GetParser(Path.GetExtension(filePath));

            if (parser == null)
            {
                throw new InvalidOperationException($"{filePath} is not convertible!");
            }

            Console.PrintInfo($"{ChangelogGeneratorResources.SAVING_CACHE}");
            string result = parser.SerializeCache(cache);

            File.WriteAllText(filePath, result);
        }
Ejemplo n.º 3
0
        private bool ValidatePrefixes(ICollection <Changelog> changelogs)
        {
            var fail = false;

            foreach (Change change in from changelog in changelogs
                     from change in changelog.Changes
                     where !_settings.ValidPrefixes.Contains(change.Prefix)
                     select change)
            {
                Console.PrintError($"{ChangelogGeneratorResources.INVALID_PREFIX} {change.Prefix}");
                fail = true;
            }

            return(!fail);
        }
Ejemplo n.º 4
0
        public int Run()
        {
            IDictionary <string, Changelog> fileToChangelog = _settings.ChangelogsFolder.ParseChangelogs();
            ICollection <string>            parsedFiles     = fileToChangelog.Keys;
            ICollection <Changelog>         changelogs      = Changelog.Merge(fileToChangelog.Values);

            if (!changelogs.Any())
            {
                Console.PrintInfo($"{ChangelogGeneratorResources.NO_NEW_CHANGELOGS}");

                return(0);
            }

            if (!ValidatePrefixes(changelogs))
            {
                return(-1);
            }

            Console.PrintInfo($"{ChangelogGeneratorResources.NEW_CHANGELOGS} {changelogs.Count}");

            List <Changelog> cache = _settings.ChangelogsCache.ParseChangelogsCache()
                                     .ToList();

            int originalCacheSize = cache.Count;

            cache.AddRange(changelogs);

            ICollection <Changelog> resultCache = Changelog.Merge(cache)
                                                  .OrderByDescending(c => c.Date)
                                                  .ToList();

            Console.PrintInfo(
                $"{ChangelogGeneratorResources.CHANGELOGS_DELTA} {resultCache.Count - originalCacheSize}");

            if (!_settings.DryRun)
            {
                if (_settings.GenerateHtml)
                {
                    Console.PrintInfo($"{ChangelogGeneratorResources.SAVING_HTML} {_settings.HtmlChangelog}");
                    SaveHtml(resultCache);
                }

                _settings.ChangelogsCache.SaveCache(resultCache);
                DeleteFiles(parsedFiles);
            }

            return(0);
        }
        private static IDictionary <string, Changelog> ParseChangelogsInternal(
            IEnumerable <string> files,
            StatusContext context)
        {
            var changelogs = new Dictionary <string, Changelog>();

            foreach (var file in files)
            {
                string          extension = Path.GetExtension(file);
                ChangelogParser?parser    = ChangelogParserProvider.GetParser(extension);

                if (parser == null)
                {
                    continue;
                }

                Changelog changelog;

                try
                {
                    context.Status($"{ChangelogGeneratorResources.PARSING_FILE} {file}");
                    changelog = parser.Parse(File.ReadAllText(file));
                    Console.PrintInfo($"{ChangelogGeneratorResources.FILE_PARSED} {file}");
                }
                catch (Exception e)
                {
                    Console.PrintError($"{ChangelogGeneratorResources.PARSING_ERROR} {e.InnerException?.Message}");
                    Console.PrintException(e);

                    continue;
                }

                changelogs.Add(file, changelog);
            }

            return(changelogs);
        }