Skip to content

Commit b43fd21

Browse files
author
Jake Ginnivan
committed
Better NuGet support with the legacy tag
1 parent cfb5907 commit b43fd21

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

GitVersionCore/SemanticVersionPreReleaseTag.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,31 @@ public string ToString(string format, IFormatProvider formatProvider = null)
133133
case "t":
134134
return Number.HasValue ? string.Format("{0}.{1}", Name, Number) : Name;
135135
case "l":
136-
return Number.HasValue ? string.Format("{0}{1}", Name, Number) : Name;
136+
return Number.HasValue ? FormatLegacy(GetLegacyName(), Number.ToString()) : FormatLegacy(GetLegacyName());
137137
case "lp":
138-
return Number.HasValue ? string.Format("{0}{1}", Name, Number.Value.ToString("D4")) : Name;
138+
return Number.HasValue ? FormatLegacy(GetLegacyName(), Number.Value.ToString("D4")) : FormatLegacy(GetLegacyName());
139139
default:
140140
throw new ArgumentException("Unknown format", "format");
141141
}
142142
}
143143

144+
string FormatLegacy(string tag, string number = null)
145+
{
146+
var tagLength = tag.Length;
147+
var numberLength = number == null ? 0 : number.Length;
148+
149+
if (tagLength + numberLength > 20)
150+
return string.Format("{0}{1}", tag.Substring(0, 20 - numberLength), number);
151+
152+
return string.Format("{0}{1}", tag, number);
153+
}
154+
155+
string GetLegacyName()
156+
{
157+
var firstPart = Name.Split('_')[0];
158+
return firstPart.Replace("-", string.Empty).Replace(".", string.Empty);
159+
}
160+
144161
public bool HasTag()
145162
{
146163
return !string.IsNullOrEmpty(Name);

Tests/SemanticVersionTests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using GitVersion;
22
using NUnit.Framework;
3+
using Shouldly;
34

45
[TestFixture]
56
public class SemanticVersionTests
@@ -51,5 +52,14 @@ public void ValidateInvalidVersionParsing(string versionString)
5152
Assert.IsFalse(SemanticVersion.TryParse(versionString, out version), "TryParse Result");
5253
}
5354

55+
[Test]
56+
public void LegacySemVerTest()
57+
{
58+
new SemanticVersionPreReleaseTag("TKT-2134_JiraDescription", null).ToString("l").ShouldBe("TKT2134");
59+
new SemanticVersionPreReleaseTag("AReallyReallyReallyLongBranchName", null).ToString("l").ShouldBe("AReallyReallyReallyL");
60+
new SemanticVersionPreReleaseTag("TKT-2134_JiraDescription", 1).ToString("lp").ShouldBe("TKT21340001");
61+
new SemanticVersionPreReleaseTag("AReallyReallyReallyLongBranchName", 1).ToString("lp").ShouldBe("AReallyReallyRea0001");
62+
}
63+
5464

5565
}

0 commit comments

Comments
 (0)