Skip to content

Commit

Permalink
Cater for the default case with the default channel and no version rules
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelnoonan committed May 9, 2016
1 parent 5594c56 commit b29e344
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
6 changes: 6 additions & 0 deletions source/Octopus.Cli/Commands/ChannelVersionRuleTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChannelVersionRuleTestResult>(link, new
{
Expand Down
6 changes: 0 additions & 6 deletions source/Octopus.Cli/Commands/CreateReleaseCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,6 @@ ReleasePlan AutoSelectBestReleasePlanOrThrow(ProjectResource project)
var releasePlans = new List<ReleasePlan>();
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);
Expand Down
8 changes: 3 additions & 5 deletions source/Octopus.Cli/Commands/ReleasePlanBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using log4net;
using Octopus.Cli.Infrastructure;
using Octopus.Cli.Model;
using Octopus.Client;
using Octopus.Client.Model;

Expand Down Expand Up @@ -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);
}
Expand Down
13 changes: 12 additions & 1 deletion source/Octopus.Cli/Model/ChannelVersionRuleTestResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}
}
}

0 comments on commit b29e344

Please sign in to comment.