feat: adds a 'v' prefix to the new version based on wether the newest last version had one
This commit is contained in:
@@ -98,8 +98,8 @@ namespace Cli
|
||||
.Title("[red]Error evaluating version from newest tag.[/]\nAdd new version tag **AND** push to origin?)")
|
||||
.PageSize(10)
|
||||
.AddChoices(
|
||||
new Selection("yes", new Version(0, 1, 0)),
|
||||
new Selection("yes", new Version(0, 1, 0, 1)),
|
||||
new Selection("yes", new Version(0, 1, 0, true)),
|
||||
new Selection("yes", new Version(0, 1, 0, 1, true)),
|
||||
new Selection("no", null)
|
||||
)
|
||||
);
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<PackageId>Novaloop.UpdateTag</PackageId>
|
||||
<title>Updates the tag of a repo to the next chosen version according the semver symantic.</title>
|
||||
<PackageTags>semver;update-tag;tag;git</PackageTags>
|
||||
<Version>0.3.1</Version>
|
||||
<Version>0.4.0</Version>
|
||||
<Authors>Matthias Langhard</Authors>
|
||||
<Company>Novaloop AG</Company>
|
||||
<PackageProjectUrl>https://gitlab.com/novaloop-oss/novaloop.update-tag</PackageProjectUrl>
|
||||
|
||||
@@ -13,37 +13,41 @@ namespace Application.Models
|
||||
/// </summary>
|
||||
public class Version
|
||||
{
|
||||
public Version(int major, int minor, int patch)
|
||||
public Version(int major, int minor, int patch, bool hasVPrefix)
|
||||
{
|
||||
Major = major;
|
||||
Minor = minor;
|
||||
Patch = patch;
|
||||
_hasVPrefix = hasVPrefix;
|
||||
}
|
||||
|
||||
public Version(int major, int minor, int patch, int? rc)
|
||||
public Version(int major, int minor, int patch, int? rc, bool hasVPrefix)
|
||||
{
|
||||
Major = major;
|
||||
Minor = minor;
|
||||
Patch = patch;
|
||||
Rc = rc;
|
||||
_hasVPrefix = hasVPrefix;
|
||||
}
|
||||
|
||||
public Version(int major, int minor, int patch, string rc, string service)
|
||||
public Version(int major, int minor, int patch, string rc, string service, bool hasVPrefix)
|
||||
{
|
||||
Major = major;
|
||||
Minor = minor;
|
||||
Patch = patch;
|
||||
Rc = rc == null ? null : ExtractNumberFromRcString(rc);
|
||||
Service = service ?? "";
|
||||
_hasVPrefix = hasVPrefix;
|
||||
}
|
||||
|
||||
public Version(int major, int minor, int patch, int? rc, string service)
|
||||
public Version(int major, int minor, int patch, int? rc, string service, bool hasVPrefix)
|
||||
{
|
||||
Major = major;
|
||||
Minor = minor;
|
||||
Patch = patch;
|
||||
Rc = rc;
|
||||
Service = service ?? "";
|
||||
_hasVPrefix = hasVPrefix;
|
||||
}
|
||||
|
||||
private static int? ExtractNumberFromRcString(string rc)
|
||||
@@ -58,12 +62,16 @@ namespace Application.Models
|
||||
public int Patch { get; private set; }
|
||||
public int? Rc { get; private set; }
|
||||
public string Service { get; private set; }
|
||||
|
||||
private readonly bool _hasVPrefix;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.Append('v');
|
||||
if (_hasVPrefix)
|
||||
{
|
||||
sb.Append('v');
|
||||
}
|
||||
|
||||
sb.Append(Major);
|
||||
sb.Append('.');
|
||||
sb.Append(Minor);
|
||||
@@ -88,7 +96,7 @@ namespace Application.Models
|
||||
|
||||
private Version Copy()
|
||||
{
|
||||
return new Version(Major, Minor, Patch, Rc, Service);
|
||||
return new Version(Major, Minor, Patch, Rc, Service, _hasVPrefix);
|
||||
}
|
||||
|
||||
public Version NextMajor()
|
||||
@@ -191,7 +199,7 @@ namespace Application.Models
|
||||
throw new ArgumentException("Cannot release RC. Not an RC.");
|
||||
}
|
||||
|
||||
var nextVersion = new Version(Major, Minor, Patch, (string)null, Service);
|
||||
var nextVersion = new Version(Major, Minor, Patch, (string)null, Service, _hasVPrefix);
|
||||
return nextVersion;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Application.Interfaces;
|
||||
@@ -27,21 +28,23 @@ namespace Infrastructure.Services
|
||||
{
|
||||
if (TryParse(tag.FriendlyName, out var semver))
|
||||
{
|
||||
yield return new Version(semver.Major, semver.Minor, semver.Patch, semver.Prerelease, semver.Build);
|
||||
yield return semver;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryParse(string version, out SemVersion semverVersion)
|
||||
private static bool TryParse(string versionStr, out Version version)
|
||||
{
|
||||
try
|
||||
{
|
||||
semverVersion = SemVersion.Parse(version.TrimStart('v').TrimStart('V'));
|
||||
var semver = SemVersion.Parse(versionStr.TrimStart('v').TrimStart('V'));
|
||||
var hasVPrefix = versionStr.StartsWith("v", StringComparison.InvariantCultureIgnoreCase);
|
||||
version = new Version(semver.Major, semver.Minor, semver.Patch, semver.Prerelease, semver.Build, hasVPrefix);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
semverVersion = null;
|
||||
version = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user