-
-
Save nblumhardt/d6e388728750d0bc18b4 to your computer and use it in GitHub Desktop.
Patch corrupted duplicate release numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// First: | |
// PM> Install-Package Octopus.Client | |
using System; | |
using System.Text.RegularExpressions; | |
using System.Threading; | |
using Octopus.Client; | |
namespace Octopus.Patch.ReleaseNumberCorruption | |
{ | |
class Program | |
{ | |
const RegexOptions _flags = RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture; | |
static readonly Regex _semanticVersionRegex = new Regex(@"^(?<Version>\d+(\s*\.\s*\d+){0,3})(?<Release>-[a-z][0-9a-z-]*)?$", _flags); | |
static void Main() | |
{ | |
const string server = "http://localhost:8065/"; | |
const string apiKey = "API-IHH51S2D6BOTRKRNMVAOJZ0PU"; | |
var endpoint = new OctopusServerEndpoint(server, apiKey); | |
var repository = new OctopusRepository(endpoint); | |
Console.WriteLine("Retrieving releases to check version numbers..."); | |
var seen = 0; | |
var count = 0; | |
foreach (var release in repository.Releases.FindAll()) | |
{ | |
seen++; | |
if (string.IsNullOrWhiteSpace(release.Version) || !_semanticVersionRegex.IsMatch(release.Version)) | |
{ | |
// Generate a new version that should stay out of the way (low ordering) and | |
// use the current time as a tag. | |
var newVer = "0.0.1-" + DateTime.UtcNow.Ticks.ToString("X16"); | |
Console.WriteLine("Fixing release {0} - version was: {1}, now: {2}", | |
release.Id, release.Version, newVer); | |
release.ReleaseNotes = "Version fixed automatically, was: " + release.Version + Environment.NewLine + (release.ReleaseNotes ?? ""); | |
release.Version = newVer; | |
repository.Client.Put(release.Links["Self"], release); | |
++count; | |
Thread.Sleep(1); // millisecond, so that ticks are always unique IDs :) | |
} | |
} | |
Console.WriteLine("{0} releases seen, {1} fixed, done.", seen, count); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment