async Task <ReleasePlan> AutoSelectBestReleasePlanOrThrow(ProjectResource project) { // Build a release plan for each channel to determine which channel is the best match for the provided options channels = await Repository.Projects.GetChannels(project).ConfigureAwait(false); var candidateChannels = await channels.GetAllPages(Repository).ConfigureAwait(false); var releasePlans = new List <ReleasePlan>(); foreach (var channel in candidateChannels) { commandOutputProvider.Information("Building a release plan for Channel '{Channel:l}'...", channel.Name); var plan = await releasePlanBuilder.Build(Repository, project, channel, VersionPreReleaseTag).ConfigureAwait(false); releasePlans.Add(plan); if (plan.ChannelHasAnyEnabledSteps() == false) { commandOutputProvider.Warning($"Channel {channel.Name} does not contain any packageSteps"); } } var viablePlans = releasePlans.Where(p => p.IsViableReleasePlan()).ToArray(); if (viablePlans.Length <= 0) { throw new CommandException( "There are no viable release plans in any channels using the provided arguments. The following release plans were considered:" + System.Environment.NewLine + $"{releasePlans.Select(p => p.FormatAsTable()).NewlineSeperate()}"); } if (viablePlans.Length == 1) { var selectedPlan = viablePlans.Single(); commandOutputProvider.Information("Selected the release plan for Channel '{Channel:l}' - it is a perfect match", selectedPlan.Channel.Name); return(selectedPlan); } if (viablePlans.Length > 1 && viablePlans.Any(p => p.Channel.IsDefault)) { var selectedPlan = viablePlans.First(p => p.Channel.IsDefault); commandOutputProvider.Information("Selected the release plan for Channel '{Channel:l}' - there were multiple matching Channels ({AllChannels:l}) so we selected the default channel.", selectedPlan.Channel.Name, viablePlans.Select(p => p.Channel.Name).CommaSeperate()); return(selectedPlan); } throw new CommandException( $"There are {viablePlans.Length} viable release plans using the provided arguments so we cannot auto-select one. The viable release plans are:" + System.Environment.NewLine + $"{viablePlans.Select(p => p.FormatAsTable()).NewlineSeperate()}" + System.Environment.NewLine + "The unviable release plans are:" + System.Environment.NewLine + $"{releasePlans.Except(viablePlans).Select(p => p.FormatAsTable()).NewlineSeperate()}"); }