コード例 #1
0
 public SemanticVersion(int major = 0, int minor = 0, int patch = 0)
 {
     Major         = major;
     Minor         = minor;
     Patch         = patch;
     PreReleaseTag = new SemanticVersionPreReleaseTag();
     BuildMetaData = new SemanticVersionBuildMetaData();
 }
コード例 #2
0
        public SemanticVersion(SemanticVersion semanticVersion)
        {
            Major = semanticVersion.Major;
            Minor = semanticVersion.Minor;
            Patch = semanticVersion.Patch;

            PreReleaseTag = new SemanticVersionPreReleaseTag(semanticVersion.PreReleaseTag);
            BuildMetaData = new SemanticVersionBuildMetaData(semanticVersion.BuildMetaData);
        }
コード例 #3
0
        public static bool TryParse(string version, string tagPrefixRegex, out SemanticVersion semanticVersion)
        {
            try
            {
                var match = Regex.Match(version, string.Format("^({0})?(?<version>.*)$", tagPrefixRegex));

                if (!match.Success)
                {
                    semanticVersion = null;
                    return(false);
                }

                version = match.Groups["version"].Value;
                var parsed = ParseSemVer.Match(version);

                if (!parsed.Success)
                {
                    semanticVersion = null;
                    return(false);
                }

                var semanticVersionBuildMetaData = SemanticVersionBuildMetaData.Parse(parsed.Groups["BuildMetaData"].Value);
                var fourthPart = parsed.Groups["FourthPart"];
                if (fourthPart.Success && semanticVersionBuildMetaData.CommitsSinceTag == null)
                {
                    semanticVersionBuildMetaData.CommitsSinceTag = int.Parse(fourthPart.Value);
                }

                semanticVersion = new SemanticVersion
                {
                    Major         = int.Parse(parsed.Groups["Major"].Value),
                    Minor         = parsed.Groups["Minor"].Success ? int.Parse(parsed.Groups["Minor"].Value) : 0,
                    Patch         = parsed.Groups["Patch"].Success ? int.Parse(parsed.Groups["Patch"].Value) : 0,
                    PreReleaseTag = SemanticVersionPreReleaseTag.Parse(parsed.Groups["Tag"].Value),
                    BuildMetaData = semanticVersionBuildMetaData
                };

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine($"{version} did not match a known SemVer format.");
                Console.WriteLine(e);
                semanticVersion = null;
                return(false);
            }
        }
コード例 #4
0
        public static bool TryParse(string version, string tagPrefixRegex, out SemanticVersion semanticVersion)
        {
            var match = Regex.Match(version, $"^({tagPrefixRegex})?(?<version>.*)$");

            if (!match.Success)
            {
                semanticVersion = null;
                return(false);
            }

            version = match.Groups["version"].Value;
            var parsed = ParseSemVer.Match(version);

            if (!parsed.Success)
            {
                semanticVersion = null;
                return(false);
            }

            var semanticVersionBuildMetaData = SemanticVersionBuildMetaData.Parse(parsed.Groups["BuildMetaData"].Value);
            var fourthPart = parsed.Groups["FourthPart"];

            if (fourthPart.Success && semanticVersionBuildMetaData.CommitsSinceTag == null)
            {
                semanticVersionBuildMetaData.CommitsSinceTag = int.Parse(fourthPart.Value);
            }

            semanticVersion = new SemanticVersion
            {
                Major         = int.Parse(parsed.Groups["Major"].Value),
                Minor         = parsed.Groups["Minor"].Success ? int.Parse(parsed.Groups["Minor"].Value) : 0,
                Patch         = parsed.Groups["Patch"].Success ? int.Parse(parsed.Groups["Patch"].Value) : 0,
                PreReleaseTag = SemanticVersionPreReleaseTag.Parse(parsed.Groups["Tag"].Value),
                BuildMetaData = semanticVersionBuildMetaData
            };

            return(true);
        }
コード例 #5
0
        public bool FindVersion(GitVersionContext context, out SemanticVersion semanticVersion)
        {
            var versionString = GetUnknownBranchSuffix(context.CurrentBranch);

            if (!versionString.Contains("."))
            {
                semanticVersion = null;
                return(false);
            }
            var shortVersion = ShortVersionParser.Parse(versionString);

            SemanticVersionPreReleaseTag semanticVersionPreReleaseTag = context.CurrentBranch.Name.Replace("-" + versionString, string.Empty) + ".1";

            var nbHotfixCommits = BranchCommitDifferenceFinder.NumberOfCommitsInBranchNotKnownFromBaseBranch(context.Repository, context.CurrentBranch, BranchType.Unknown, "master");

            var tagVersion = RecentTagVersionExtractor.RetrieveMostRecentOptionalTagVersion(context.Repository, shortVersion, context.CurrentBranch.Commits.Take(nbHotfixCommits + 1));

            if (tagVersion != null)
            {
                semanticVersionPreReleaseTag = tagVersion;
            }

            if (semanticVersionPreReleaseTag.Name == "release")
            {
                semanticVersionPreReleaseTag.Name = "beta";
            }

            semanticVersion = new SemanticVersion
            {
                Major         = shortVersion.Major,
                Minor         = shortVersion.Minor,
                Patch         = shortVersion.Patch,
                PreReleaseTag = semanticVersionPreReleaseTag,
                BuildMetaData = new SemanticVersionBuildMetaData(nbHotfixCommits, context.CurrentBranch.Name, context.CurrentCommit.Sha, context.CurrentCommit.When())
            };
            return(true);
        }
コード例 #6
0
 public SemanticVersion()
 {
     PreReleaseTag = new SemanticVersionPreReleaseTag();
     BuildMetaData = new SemanticVersionBuildMetaData();
 }