예제 #1
0
        public void KeepsCustomisations()
        {
            IRepository   repo;
            IIssueTracker issueTracker;

            new TestDataCreator(new DateTimeOffset(2012, 1, 1, 0, 0, 0, new TimeSpan()))
            .CreateRelease("0.1.0", "Issue1", "Issue2")
            .CreateRelease("0.2.0", "Issue3")
            .Build(out repo, out issueTracker);

            var tagToStartFrom     = GitRepositoryInfoFinder.GetFirstCommit(repo);
            var currentReleaseInfo = GitRepositoryInfoFinder.GetCurrentReleaseInfo(repo);

            var previousReleaseNotes = SemanticReleaseNotes.Parse(@"# vNext


Commits: ...


# 0.2.0 (05 January 2012)

**Note this release does some stuff!**


 - [2] - Edited Issue3

Another comment

Commits:  AC39885536...CA74E870F2


# 0.1.0 (03 January 2012)

## Features
 - [0] - Edited Issue1
 - [1] - Edited Issue2
 - [2] - Edited Issue3

## Fixes
 - [3] - Edited Issue4
 - [4] - Edited Issue5

This is a comment about the release

Which spans multiple lines


Commits: E413A880DB...F6924D7A0B");

            var releaseNotes = ReleaseNotesGenerator.GenerateReleaseNotes(
                repo, issueTracker, previousReleaseNotes, new Categories(),
                tagToStartFrom, currentReleaseInfo, "url/{0}...{1}");

            Approvals.Verify(releaseNotes.ToString(), Scrubber);
        }
예제 #2
0
        public void AllTagsWithNoCommitsOrIssuesAfterLastRelease()
        {
            IRepository   repo;
            IIssueTracker issueTracker;

            new TestDataCreator(new DateTimeOffset(2012, 1, 1, 0, 0, 0, new TimeSpan()))
            .CreateRelease("0.1.0", "Issue1", "Issue2")
            .CreateRelease("0.2.0", "Issue3")
            .Build(out repo, out issueTracker);

            var tagToStartFrom     = GitRepositoryInfoFinder.GetFirstCommit(repo);
            var currentReleaseInfo = GitRepositoryInfoFinder.GetCurrentReleaseInfo(repo);

            var releaseNotes = ReleaseNotesGenerator.GenerateReleaseNotes(
                repo, issueTracker, new SemanticReleaseNotes(), new Categories(),
                tagToStartFrom, currentReleaseInfo, issueTracker.DiffUrlFormat);

            Approvals.Verify(releaseNotes.ToString(), Scrubber);
        }
        public void AllTags()
        {
            IRepository   repo;
            IIssueTracker issueTracker;

            new TestDataCreator(new DateTimeOffset(2012, 1, 1, 0, 0, 0, new TimeSpan()))
            .CreateRelease("0.1.0", "Issue1", "Issue2")
            .CreateRelease("0.2.0", "Issue3")
            .AddIssues("Issue4")
            .Build(out repo, out issueTracker);

            var tagToStartFrom     = GitRepositoryInfoFinder.GetFirstCommit(repo);
            var currentReleaseInfo = GitRepositoryInfoFinder.GetCurrentReleaseInfo(repo);

            var releaseNotes = ReleaseNotesGenerator.GenerateReleaseNotes(
                repo, issueTracker, new SemanticReleaseNotes(), new string[0],
                tagToStartFrom, currentReleaseInfo, string.Empty);

            Approvals.Verify(releaseNotes.ToString());
        }
예제 #4
0
        public void AppendOnlyNewItems()
        {
            IRepository   repo;
            IIssueTracker issueTracker;

            new TestDataCreator(new DateTimeOffset(2012, 1, 1, 0, 0, 0, new TimeSpan()))
            .CreateRelease("0.1.0", "Issue1", "Issue2")
            .CreateRelease("0.2.0", "Issue3")
            .AddIssues("Issue4")
            .Build(out repo, out issueTracker);

            var tagToStartFrom     = GitRepositoryInfoFinder.GetFirstCommit(repo);
            var currentReleaseInfo = GitRepositoryInfoFinder.GetCurrentReleaseInfo(repo);

            var previousReleaseNotes = SemanticReleaseNotes.Parse(@"# vNext


Commits: ...


# 0.2.0 (05 January 2012)

 - [2] - Edited Issue3

Commits:  AC39885536...CA74E870F2


# 0.1.0 (03 January 2012)

 - [0] - Edited Issue1
 - [1] - Edited Issue2

Commits: E413A880DB...F6924D7A0B");

            var releaseNotes = ReleaseNotesGenerator.GenerateReleaseNotes(
                repo, issueTracker, previousReleaseNotes, new Categories(),
                tagToStartFrom, currentReleaseInfo, string.Empty);

            Approvals.Verify(releaseNotes.ToString(), Scrubber);
        }
        public static SemanticReleaseNotes GenerateReleaseNotes(Context context)
        {
            using (var gitRepoContext = GetRepository(context))
            {
                // Remote repo's require some additional preparation before first use.
                if (gitRepoContext.IsRemote)
                {
                    gitRepoContext.PrepareRemoteRepoForUse(context.Repository.Branch);
                    if (!string.IsNullOrWhiteSpace(context.OutputFile))
                    {
                        gitRepoContext.CheckoutFilesIfExist(context.OutputFile);
                    }
                }

                var gitRepo = gitRepoContext.Repository;

                CreateIssueTrackers(gitRepo, context);

                IIssueTracker issueTracker = null;
                if (context.IssueTracker == null)
                {
                    var firstOrDefault = _issueTrackers.FirstOrDefault(i => i.Value.RemotePresentWhichMatches);
                    if (firstOrDefault.Value != null)
                    {
                        issueTracker = firstOrDefault.Value;
                    }
                }

                if (issueTracker == null)
                {
                    if (!_issueTrackers.ContainsKey(context.IssueTracker.Value))
                    {
                        throw new GitReleaseNotesException("{0} is not a known issue tracker", context.IssueTracker.Value);
                    }

                    issueTracker = _issueTrackers[context.IssueTracker.Value];
                }

                if (!issueTracker.VerifyArgumentsAndWriteErrorsToLog())
                {
                    throw new GitReleaseNotesException("Argument verification failed");
                }

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

                var outputPath      = gitRepo.Info.Path;
                var outputDirectory = new DirectoryInfo(outputPath);
                if (outputDirectory.Name == ".git")
                {
                    outputPath = outputDirectory.Parent.FullName;
                }

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

                var categories     = new Categories(context.Categories, context.AllLabels);
                var tagToStartFrom = context.AllTags
                    ? GitRepositoryInfoFinder.GetFirstCommit(gitRepo)
                    : GitRepositoryInfoFinder.GetLastTaggedCommit(gitRepo) ?? GitRepositoryInfoFinder.GetFirstCommit(gitRepo);
                var currentReleaseInfo = GitRepositoryInfoFinder.GetCurrentReleaseInfo(gitRepo);
                if (!string.IsNullOrEmpty(context.Version))
                {
                    currentReleaseInfo.Name = context.Version;
                    currentReleaseInfo.When = DateTimeOffset.Now;
                }

                var releaseNotes = GenerateReleaseNotes(
                    gitRepo, issueTracker,
                    previousReleaseNotes, categories,
                    tagToStartFrom, currentReleaseInfo,
                    issueTracker.DiffUrlFormat);

                var releaseNotesOutput = releaseNotes.ToString();
                releaseFileWriter.OutputReleaseNotesFile(releaseNotesOutput, outputFile);

                return(releaseNotes);
            }
        }
예제 #6
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);
        }