chore: optimizing next version handling
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Application.Commands;
|
||||
using Application.Queries;
|
||||
@@ -82,10 +83,10 @@ namespace Cli
|
||||
.Title($"Select new version. (Current version is [green]{versionInfo.CurrentVersion}[/])")
|
||||
.PageSize(10)
|
||||
.AddChoices(
|
||||
new Selection("rc ", versionInfo.NextMinorRcVersion),
|
||||
new Selection("patch", versionInfo.NextPatchVersion),
|
||||
new Selection("minor", versionInfo.NextMinorVersion),
|
||||
new Selection("major", versionInfo.NextMajorVersion)
|
||||
versionInfo
|
||||
.NextVersions
|
||||
.Select(nv => new Selection(nv.Title, nv.Version))
|
||||
.ToList()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
@@ -19,7 +20,7 @@ namespace Application.Models
|
||||
Patch = patch;
|
||||
}
|
||||
|
||||
public Version(int major, int minor, int patch, int rc)
|
||||
public Version(int major, int minor, int patch, int? rc)
|
||||
{
|
||||
Major = major;
|
||||
Minor = minor;
|
||||
@@ -32,7 +33,16 @@ namespace Application.Models
|
||||
Major = major;
|
||||
Minor = minor;
|
||||
Patch = patch;
|
||||
Rc = ExtractNumberFromRcString(rc);
|
||||
Rc = rc == null ? null : ExtractNumberFromRcString(rc);
|
||||
Service = service ?? "";
|
||||
}
|
||||
|
||||
public Version(int major, int minor, int patch, int? rc, string service)
|
||||
{
|
||||
Major = major;
|
||||
Minor = minor;
|
||||
Patch = patch;
|
||||
Rc = rc;
|
||||
Service = service ?? "";
|
||||
}
|
||||
|
||||
@@ -75,62 +85,88 @@ namespace Application.Models
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
private Version Copy()
|
||||
{
|
||||
return new Version(Major, Minor, Patch, Rc, Service);
|
||||
}
|
||||
|
||||
public Version NextMajor()
|
||||
{
|
||||
var nextVersion = new Version(Major, Minor, Patch, Rc.ToString(), Service);
|
||||
nextVersion.BumpMajor();
|
||||
if (Rc != null)
|
||||
{
|
||||
throw new ArgumentException("Cannot create next Major. Release RC first.");
|
||||
}
|
||||
|
||||
var nextVersion = Copy();
|
||||
nextVersion.Major++;
|
||||
nextVersion.Minor = 0;
|
||||
nextVersion.Patch = 0;
|
||||
return nextVersion;
|
||||
}
|
||||
|
||||
public Version NextMinor()
|
||||
{
|
||||
var nextVersion = new Version(Major, Minor, Patch, Rc.ToString(), Service);
|
||||
nextVersion.BumpMinor();
|
||||
if (Rc != null)
|
||||
{
|
||||
throw new ArgumentException("Cannot create next Minor. Release RC first.");
|
||||
}
|
||||
|
||||
var nextVersion = Copy();
|
||||
nextVersion.Minor++;
|
||||
nextVersion.Patch = 0;
|
||||
return nextVersion;
|
||||
}
|
||||
|
||||
public Version NextPatch()
|
||||
{
|
||||
var nextVersion = new Version(Major, Minor, Patch, Rc.ToString(), Service);
|
||||
nextVersion.BumpPatch();
|
||||
if (Rc != null)
|
||||
{
|
||||
throw new ArgumentException("Cannot create next Patch. Release RC first.");
|
||||
}
|
||||
|
||||
var nextVersion = Copy();
|
||||
nextVersion.Patch++;
|
||||
return nextVersion;
|
||||
}
|
||||
|
||||
public Version NextRc()
|
||||
{
|
||||
var nextVersion = new Version(Major, Minor, Patch, Rc.ToString(), Service);
|
||||
nextVersion.BumpRc();
|
||||
if (Rc == null)
|
||||
{
|
||||
throw new ArgumentException("Cannot create next RC. Not an RC.");
|
||||
}
|
||||
|
||||
var nextVersion = Copy();
|
||||
nextVersion.Rc++;
|
||||
return nextVersion;
|
||||
}
|
||||
|
||||
public void BumpMajor()
|
||||
public Version CreateRc()
|
||||
{
|
||||
Major++;
|
||||
Minor = 0;
|
||||
Patch = 0;
|
||||
Rc = null;
|
||||
if (Rc != null)
|
||||
{
|
||||
throw new ArgumentException("Cannot create RC. Already an RC.");
|
||||
}
|
||||
|
||||
var nextVersion = Copy();
|
||||
nextVersion.Rc = 0;
|
||||
return nextVersion;
|
||||
}
|
||||
|
||||
public void BumpMinor()
|
||||
{
|
||||
Minor++;
|
||||
Patch = 0;
|
||||
Rc = null;
|
||||
}
|
||||
|
||||
public void BumpPatch()
|
||||
{
|
||||
Patch++;
|
||||
Rc = null;
|
||||
}
|
||||
|
||||
public void BumpRc()
|
||||
public Version ReleaseRc()
|
||||
{
|
||||
if (Rc == null)
|
||||
{
|
||||
BumpMinor();
|
||||
throw new ArgumentException("Cannot release RC. Not an RC.");
|
||||
}
|
||||
Rc = Rc == null ? 0 : Rc + 1;
|
||||
|
||||
var nextVersion = new Version(Major, Minor, Patch, (string)null, Service);
|
||||
return nextVersion;
|
||||
}
|
||||
|
||||
public bool IsRc()
|
||||
{
|
||||
return Rc != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Application.Models
|
||||
{
|
||||
public class VersionInformation
|
||||
@@ -5,16 +7,34 @@ namespace Application.Models
|
||||
public VersionInformation(Version currentVersion)
|
||||
{
|
||||
CurrentVersion = currentVersion;
|
||||
NextMajorVersion = currentVersion.NextMajor();
|
||||
NextMinorVersion = currentVersion.NextMinor();
|
||||
NextPatchVersion = currentVersion.NextPatch();
|
||||
NextMinorRcVersion = currentVersion.NextRc();
|
||||
if (currentVersion.IsRc())
|
||||
{
|
||||
NextVersions.Add(new NextVersion("next rc", currentVersion.NextRc()));
|
||||
NextVersions.Add(new NextVersion("release", currentVersion.ReleaseRc()));
|
||||
}
|
||||
else
|
||||
{
|
||||
NextVersions.Add(new NextVersion("rc", currentVersion.CreateRc()));
|
||||
NextVersions.Add(new NextVersion("patch", currentVersion.NextPatch()));
|
||||
NextVersions.Add(new NextVersion("minor", currentVersion.NextMinor()));
|
||||
NextVersions.Add(new NextVersion("major", currentVersion.NextMajor()));
|
||||
}
|
||||
}
|
||||
|
||||
public Version CurrentVersion { get; }
|
||||
public Version NextMajorVersion { get; }
|
||||
public Version NextMinorVersion { get; }
|
||||
public Version NextPatchVersion { get; }
|
||||
public Version NextMinorRcVersion { get; }
|
||||
|
||||
public List<NextVersion> NextVersions = new List<NextVersion>();
|
||||
}
|
||||
|
||||
public class NextVersion
|
||||
{
|
||||
public NextVersion(string title, Version version)
|
||||
{
|
||||
Title = title;
|
||||
Version = version;
|
||||
}
|
||||
|
||||
public string Title { get; }
|
||||
public Version Version { get; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user