Exemplo n.º 1
0
        static int Main(string[] args)
        {
            GitReleaseNotesEnvironment.Log = new ConsoleLog();

            var modelBindingDefinition = Configuration.Configure<GitReleaseNotesArguments>();

            if (args.Any(a => a == "/?" || a == "?" || a.Equals("/help", StringComparison.InvariantCultureIgnoreCase)))
            {
                var help = new HelpProvider().GenerateModelHelp(modelBindingDefinition);
                var f = new ConsoleHelpFormatter();
                f.WriteHelp(help, Console.Out);

                return 0;
            }

            var exitCode = 0;

            var arguments = modelBindingDefinition.CreateAndBind(args);

            // TODO: Convert to context verification (we need the context to be valid, not the arguments)
            if (!ArgumentVerifier.VerifyArguments(arguments))
            {
                return 1;
            }

            var context = arguments.ToContext();

            try
            {
                var releaseNotesGenerator = new ReleaseNotesGenerator(context, new FileSystem.FileSystem());
                releaseNotesGenerator.GenerateReleaseNotes();

                Log.WriteLine("Done");
            }
            catch (GitReleaseNotesException ex)
            {
                exitCode = -1;
                Log.WriteLine("An expected error occurred: {0}", ex.Message);
            }
            catch (Exception ex)
            {
                exitCode = -2;
                Log.WriteLine("An unexpected error occurred: {0}", ex.Message);
            }

            if (Debugger.IsAttached)
            {
                Console.WriteLine("Press any key to continue");
                Console.ReadKey();
            }

            return exitCode;
        }
Exemplo n.º 2
0
        static int Main(string[] args)
        {
            GitReleaseNotesEnvironment.Log = new ConsoleLog();

            var modelBindingDefinition = Configuration.Configure <GitReleaseNotesArguments>();

            if (args.Any(a => a == "/?" || a == "?" || a.Equals("/help", StringComparison.InvariantCultureIgnoreCase)))
            {
                var help = new HelpProvider().GenerateModelHelp(modelBindingDefinition);
                var f    = new ConsoleHelpFormatter();
                f.WriteHelp(help, Console.Out);

                return(0);
            }

            var exitCode = 0;

            var arguments = modelBindingDefinition.CreateAndBind(args);

            // TODO: Convert to context verification (we need the context to be valid, not the arguments)
            if (!ArgumentVerifier.VerifyArguments(arguments))
            {
                return(1);
            }

            var context = arguments.ToContext();

            try
            {
                var releaseNotesGenerator = new ReleaseNotesGenerator(context, new FileSystem.FileSystem());
                releaseNotesGenerator.GenerateReleaseNotes();

                Log.WriteLine("Done");
            }
            catch (GitReleaseNotesException ex)
            {
                exitCode = -1;
                Log.WriteLine("An expected error occurred: {0}", ex.Message);
            }
            catch (Exception ex)
            {
                exitCode = -2;
                Log.WriteLine("An unexpected error occurred: {0}", ex.Message);
            }

            if (Debugger.IsAttached)
            {
                Console.WriteLine("Press any key to continue");
                Console.ReadKey();
            }

            return(exitCode);
        }
Exemplo n.º 3
0
        private static int GenerateReleaseNotes(string[] args)
        {
            var modelBindingDefinition = Args.Configuration.Configure <GitReleaseNotesArguments>();

            if (args.Any(a => a == "/?" || a == "?" || a.Equals("/help", StringComparison.InvariantCultureIgnoreCase)))
            {
                var help = new HelpProvider().GenerateModelHelp(modelBindingDefinition);
                var f    = new ConsoleHelpFormatter();
                f.WriteHelp(help, Console.Out);

                return(0);
            }

            var arguments = modelBindingDefinition.CreateAndBind(args);

            if (!ArgumentVerifier.VerifyArguments(arguments))
            {
                return(1);
            }

            var workingDirectory = arguments.WorkingDirectory ?? Directory.GetCurrentDirectory();

            var gitDirectory = GitDirFinder.TreeWalkForGitDir(workingDirectory);

            if (string.IsNullOrEmpty(gitDirectory))
            {
                throw new Exception("Failed to find .git directory.");
            }

            Console.WriteLine("Git directory found at {0}", gitDirectory);

            var repositoryRoot = Directory.GetParent(gitDirectory).FullName;

            var gitRepo = new Repository(gitDirectory);

            CreateIssueTrackers(gitRepo, arguments);

            IIssueTracker issueTracker = null;

            if (arguments.IssueTracker == null)
            {
                var firstOrDefault = _issueTrackers.FirstOrDefault(i => i.Value.RemotePresentWhichMatches);
                if (firstOrDefault.Value != null)
                {
                    issueTracker = firstOrDefault.Value;
                }
            }
            if (issueTracker == null)
            {
                if (!_issueTrackers.ContainsKey(arguments.IssueTracker.Value))
                {
                    throw new Exception(string.Format("{0} is not a known issue tracker", arguments.IssueTracker.Value));
                }

                issueTracker = _issueTrackers[arguments.IssueTracker.Value];
            }
            if (!issueTracker.VerifyArgumentsAndWriteErrorsToConsole())
            {
                return(1);
            }

            var    fileSystem           = new FileSystem.FileSystem();
            var    releaseFileWriter    = new ReleaseFileWriter(fileSystem);
            string outputFile           = null;
            var    previousReleaseNotes = new SemanticReleaseNotes();

            if (!string.IsNullOrEmpty(arguments.OutputFile))
            {
                outputFile = Path.IsPathRooted(arguments.OutputFile)
                    ? arguments.OutputFile
                    : Path.Combine(repositoryRoot, arguments.OutputFile);
                previousReleaseNotes = new ReleaseNotesFileReader(fileSystem, repositoryRoot).ReadPreviousReleaseNotes(outputFile);
            }

            var          categories     = arguments.Categories == null ? Categories : Categories.Concat(arguments.Categories.Split(',')).ToArray();
            TaggedCommit tagToStartFrom = arguments.AllTags
                ? GitRepositoryInfoFinder.GetFirstCommit(gitRepo)
                : GitRepositoryInfoFinder.GetLastTaggedCommit(gitRepo) ?? GitRepositoryInfoFinder.GetFirstCommit(gitRepo);
            var currentReleaseInfo = GitRepositoryInfoFinder.GetCurrentReleaseInfo(gitRepo);

            if (!string.IsNullOrEmpty(arguments.Version))
            {
                currentReleaseInfo.Name = arguments.Version;
                currentReleaseInfo.When = DateTimeOffset.Now;
            }
            var releaseNotes = ReleaseNotesGenerator.GenerateReleaseNotes(
                gitRepo, issueTracker,
                previousReleaseNotes, categories,
                tagToStartFrom, currentReleaseInfo,
                issueTracker.DiffUrlFormat);

            var releaseNotesOutput = releaseNotes.ToString();

            releaseFileWriter.OutputReleaseNotesFile(releaseNotesOutput, outputFile);

            return(0);
        }