public static string BuildNugetVersionFromBranchSemVer200(this ICakeContext context, int major, int minor, int patch, string branch, string hash = null) { var settings = new BuildNugetVersionFromBranchSemVer200Settings { BranchName = branch, Hash = hash }; return(BuildNugetVersionFromBranchSemVer200(context, major, minor, patch, settings)); }
private static int GetPatch(int patch, string trimmedBranch, BuildNugetVersionFromBranchSemVer200Settings settings) { if (settings.PreReleaseFilters != null && settings.PreReleaseFilters.Any(f => Regex.IsMatch(trimmedBranch, f))) { return(patch + (settings.BranchChangeNumber ?? 0)); } else { return(patch); } }
private static string ComposeSuffixSemVer2(BuildNugetVersionFromBranchSemVer200Settings settings) { string branch = GetTrimmedBranchName(settings); string hash = settings.Hash; int? branchChangeNumber = settings.BranchChangeNumber; string suffix = string.Empty; branch = branch.Substring(0, Math.Min(branch.Length, 200)); var separator = GetSuffixSeparator(settings.PreReleaseFilters != null && settings.PreReleaseFilters.All(f => !Regex.IsMatch(branch, f))); if (settings.PreReleaseFilters != null && settings.PreReleaseFilters.All(f => !Regex.IsMatch(branch, f))) { if (IsBranchPrefixNecessary(branch) || settings.AlwaysApplyBranchPrefix) { branch = $"{settings.BranchPrefix}{branch}"; } suffix = branch; if (branchChangeNumber != null) { suffix += $".{branchChangeNumber}"; } if (hash != null) { suffix += $".{hash}"; } } else { if (hash != null) { suffix = hash; } } return(string.IsNullOrEmpty(suffix) ? suffix : separator + NormalizeSuffixSemVer2(suffix, 255)); }
public static string BuildNugetVersionFromBranchSemVer200(this ICakeContext context, int major, int minor, int patch, BuildNugetVersionFromBranchSemVer200Settings settings) { if (settings.BranchName == null) { throw new ArgumentNullException("BranchName cannot be null!"); } patch = GetPatch(patch, GetTrimmedBranchName(settings), settings); string version = ComposeVersion(major, minor, patch); var suffix = ComposeSuffixSemVer2(settings); return($"{version}{suffix}"); }