From b29e34402b1a139ae52f9d53915811e7d1691a6f Mon Sep 17 00:00:00 2001 From: Michael Noonan Date: Mon, 9 May 2016 22:30:05 +1000 Subject: [PATCH] Cater for the default case with the default channel and no version rules --- .../Commands/ChannelVersionRuleTester.cs | 6 ++++++ source/Octopus.Cli/Commands/CreateReleaseCommand.cs | 6 ------ source/Octopus.Cli/Commands/ReleasePlanBuilder.cs | 8 +++----- .../Model/ChannelVersionRuleTestResult.cs | 13 ++++++++++++- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/source/Octopus.Cli/Commands/ChannelVersionRuleTester.cs b/source/Octopus.Cli/Commands/ChannelVersionRuleTester.cs index eb5b51363..783b3f3ca 100644 --- a/source/Octopus.Cli/Commands/ChannelVersionRuleTester.cs +++ b/source/Octopus.Cli/Commands/ChannelVersionRuleTester.cs @@ -8,6 +8,12 @@ public class ChannelVersionRuleTester : IChannelVersionRuleTester { public ChannelVersionRuleTestResult Test(IOctopusRepository repository, ChannelVersionRuleResource rule, string packageVersion) { + if (rule == null) + { + // Anything goes if there is no rule defined for this step + return ChannelVersionRuleTestResult.Null(); + } + var link = repository.Client.RootDocument.Link("VersionRuleTest"); var response = repository.Client.Get(link, new { diff --git a/source/Octopus.Cli/Commands/CreateReleaseCommand.cs b/source/Octopus.Cli/Commands/CreateReleaseCommand.cs index 37e917fca..11c781b9f 100644 --- a/source/Octopus.Cli/Commands/CreateReleaseCommand.cs +++ b/source/Octopus.Cli/Commands/CreateReleaseCommand.cs @@ -195,12 +195,6 @@ ReleasePlan AutoSelectBestReleasePlanOrThrow(ProjectResource project) var releasePlans = new List(); foreach (var channel in candidateChannels) { - if (channel.Rules.Count <= 0) - { - Log.Debug($"Channel '{channel.Name}' has no version rules, skipping..."); - continue; - } - Log.Info($"Building a release plan for Channel '{channel.Name}'..."); var plan = releasePlanBuilder.Build(Repository, project, channel, VersionPreReleaseTag); diff --git a/source/Octopus.Cli/Commands/ReleasePlanBuilder.cs b/source/Octopus.Cli/Commands/ReleasePlanBuilder.cs index 053b6ace3..e1bbb0312 100644 --- a/source/Octopus.Cli/Commands/ReleasePlanBuilder.cs +++ b/source/Octopus.Cli/Commands/ReleasePlanBuilder.cs @@ -3,6 +3,7 @@ using System.Linq; using log4net; using Octopus.Cli.Infrastructure; +using Octopus.Cli.Model; using Octopus.Client; using Octopus.Client.Model; @@ -79,11 +80,8 @@ public ReleasePlan Build(IOctopusRepository repository, ProjectResource project, { foreach (var step in plan.Steps) { - var rule = - channel.Rules.SingleOrDefault( - r => r.Actions.Any(s => s.Equals(step.StepName, StringComparison.OrdinalIgnoreCase))); - if (rule == null) continue; - + // Note the rule can be null, meaning: anything goes + var rule = channel.Rules.SingleOrDefault(r => r.Actions.Any(s => s.Equals(step.StepName, StringComparison.OrdinalIgnoreCase))); var result = versionRuleTester.Test(repository, rule, step.Version); step.SetChannelVersionRuleTestResult(result); } diff --git a/source/Octopus.Cli/Model/ChannelVersionRuleTestResult.cs b/source/Octopus.Cli/Model/ChannelVersionRuleTestResult.cs index 3797b7a2c..f06d9a265 100644 --- a/source/Octopus.Cli/Model/ChannelVersionRuleTestResult.cs +++ b/source/Octopus.Cli/Model/ChannelVersionRuleTestResult.cs @@ -9,13 +9,24 @@ public class ChannelVersionRuleTestResult : Resource public bool SatisfiesVersionRange { get; set; } public bool SatisfiesPreReleaseTag { get; set; } public bool IsSatisfied => SatisfiesVersionRange && SatisfiesPreReleaseTag; + public bool IsNull { get; private set; } const string Pass = "PASS"; const string Fail = "FAIL"; public string ToSummaryString() { - return $"Range: {(SatisfiesVersionRange ? Pass : Fail)} Tag: {(SatisfiesPreReleaseTag ? Pass : Fail)}"; + return IsNull ? "Allow any version" : $"Range: {(SatisfiesVersionRange ? Pass : Fail)} Tag: {(SatisfiesPreReleaseTag ? Pass : Fail)}"; + } + + public static ChannelVersionRuleTestResult Null() + { + return new ChannelVersionRuleTestResult + { + IsNull = true, + SatisfiesVersionRange = true, + SatisfiesPreReleaseTag = true, + }; } } }