public void Should_find_previous_commit_that_was_at_least_a_minor_bump()
 {
     var finder = new VersionOnMasterFinder
                  {
                      Repository = new MockRepository
                                   {
                                       Branches = new MockBranchCollection
                                                  {
                                                      new MockBranch("master")
                                                      {
                                                          new MockCommit
                                                          {
                                                              MessageEx = "Merge branch 'hotfix-0.3.0'",
                                                              CommitterEx = 2.Seconds().Ago().ToSignature()
                                                          },
                                                          new MockCommit
                                                          {
                                                              MessageEx = "Merge branch 'hotfix-0.3.1'",
                                                              CommitterEx = 2.Seconds().Ago().ToSignature(),
                                                          },
                                                          new MockCommit
                                                          {
                                                              MessageEx = "Merge branch 'hotfix-0.2.0'",
                                                              CommitterEx = 2.Seconds().Ago().ToSignature()
                                                          },
                                                      },
                                                  }
                                   },
                      OlderThan = 1.Seconds().Ago()
                  };
     var version = finder.Execute();
     Assert.AreEqual(0, version.Major);
     Assert.AreEqual(3, version.Minor);
 }
        SemanticVersion GetSemanticVersion()
        {
            var versionOnMasterFinder = new VersionOnMasterFinder
                                        {
                                            Repository = Repository,
                                            OlderThan = Commit.When()
                                        };
            var versionFromMaster = versionOnMasterFinder.Execute();

            var developBranch = Repository.GetBranch("develop");
            var preReleasePartOne = developBranch.Commits
                .SkipWhile(x => x != Commit)
                .TakeWhile(x => x.When() >= versionFromMaster.Timestamp)
                .Count();
            return new SemanticVersion
            {
                Major = versionFromMaster.Major,
                Minor = versionFromMaster.Minor,
                PreReleasePartOne = preReleasePartOne
            };
        }
        public VersionAndBranch FindVersion()
        {
            var firstCommitOnBranch = FindFirstCommitOnBranchFunc();

            if (firstCommitOnBranch == Commit.Id) //no commits on branch. use develop approach
            {
                var developVersionFinder = new DevelopVersionFinder
                {
                    Commit = Commit,
                    Repository = Repository
                };
                var versionFromDevelopFinder = developVersionFinder.FindVersion();
                versionFromDevelopFinder.BranchType = BranchType.Feature;
                versionFromDevelopFinder.BranchName = FeatureBranch.Name;
                return versionFromDevelopFinder;
            }

            var versionOnMasterFinder = new VersionOnMasterFinder
            {
                Repository = Repository,
                OlderThan = Commit.When()
            };
            var versionFromMaster = versionOnMasterFinder.Execute();

            return new VersionAndBranch
            {
                BranchType = BranchType.Feature,
                BranchName = FeatureBranch.Name,
                Sha = Commit.Sha,
                Version = new SemanticVersion
                {
                    Major = versionFromMaster.Major,
                    Minor = versionFromMaster.Minor + 1,
                    Patch = 0,
                    Stability = Stability.Unstable,
                    PreReleasePartOne = 0,
                    Suffix = firstCommitOnBranch.Prefix()
                }
            };
        }
Exemplo n.º 4
0
        public VersionAndBranch FindVersion()
        {
            var versionOnMasterFinder = new VersionOnMasterFinder
            {
                Repository = Repository,
                OlderThan = Commit.When(),
            };
            var versionFromMaster = versionOnMasterFinder
                .Execute();

            string suffix;
            if (TeamCity.IsBuildingAPullRequest())
            {
                suffix = TeamCity.CurrentPullRequestNo().ToString();
            }
            else
            {
                suffix = PullBranch.CanonicalName.Substring(PullBranch.CanonicalName.IndexOf("/pull/") + 6);
            }

            return new VersionAndBranch
            {
                BranchType = BranchType.PullRequest,
                BranchName = PullBranch.Name,
                Sha = Commit.Sha,
                Version = new SemanticVersion
                {
                    Major = versionFromMaster.Major,
                    Minor = versionFromMaster.Minor + 1,
                    Patch = 0,
                    Stability = Stability.Unstable,
                    PreReleasePartOne = 0,
                    Suffix = suffix
                }
            };
        }