Skip to content

Commit

Permalink
Merge pull request #74 from OctopusDeploy/bug-customExpressionFeed
Browse files Browse the repository at this point in the history
Bug custom expression feed
  • Loading branch information
MarkSiedle committed Mar 30, 2016
2 parents ce01420 + f9438cf commit 79a7266
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 12 deletions.
6 changes: 5 additions & 1 deletion NuGet.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>

<packageRestore>
Expand All @@ -11,7 +11,11 @@
</activePackageSource>

<packageSources>

<add key="Octopus-Dependencies" value="https://www.myget.org/F/octopus-dependencies/api/v3/index.json" />

<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />

</packageSources>

<disabledPackageSources>
Expand Down
3 changes: 1 addition & 2 deletions source/Octopus.Cli/Commands/ImportCommand.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using log4net;
using log4net;
using Octopus.Cli.Importers;
using Octopus.Cli.Infrastructure;
using Octopus.Cli.Util;
Expand Down
11 changes: 8 additions & 3 deletions source/Octopus.Cli/Exporters/ProjectExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ protected override void Export(Dictionary<string, string> parameters)
{
throw new CommandException("Please specify the name of the project to export using the paramater: --name=XYZ");
}

var projectName = parameters["Name"];

Log.Debug("Finding project: " + projectName);
Expand Down Expand Up @@ -73,7 +74,6 @@ protected override void Export(Dictionary<string, string> parameters)
throw new CouldNotFindException("deployment process for project",project.Name);

Log.Debug("Finding NuGet feed for deployment process...");

var nugetFeeds = new List<ReferenceDataItem>();
foreach (var step in deploymentProcess.Steps)
{
Expand All @@ -83,9 +83,15 @@ protected override void Export(Dictionary<string, string> parameters)
if (action.Properties.TryGetValue("Octopus.Action.Package.NuGetFeedId", out nugetFeedId))
{
Log.Debug("Finding NuGet feed for step " + step.Name);
var feed = Repository.Feeds.Get(nugetFeedId.Value);
FeedResource feed = null;
if (FeedCustomExpressionHelper.IsRealFeedId(nugetFeedId.Value))
feed = Repository.Feeds.Get(nugetFeedId.Value);
else
feed = FeedCustomExpressionHelper.CustomExpressionFeedWithId(nugetFeedId.Value);

if (feed == null)
throw new CouldNotFindException("NuGet feed for step", step.Name);

if (nugetFeeds.All(f => f.Id != nugetFeedId.Value))
{
nugetFeeds.Add(new ReferenceDataItem(feed.Id, feed.Name));
Expand Down Expand Up @@ -123,7 +129,6 @@ protected override void Export(Dictionary<string, string> parameters)
{
throw new CouldNotFindException("library variable set with Id", libraryVariableSetId);
}

libraryVariableSets.Add(new ReferenceDataItem(libraryVariableSet.Id, libraryVariableSet.Name));
}

Expand Down
14 changes: 8 additions & 6 deletions source/Octopus.Cli/Importers/ProjectImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Security.Permissions;
using log4net;
using Octopus.Cli.Commands;
using Octopus.Cli.Extensions;
Expand Down Expand Up @@ -37,8 +36,7 @@ class ValidatedImportSettings : BaseValidatedImportSettings
public IDictionary<string, ActionTemplateResource> Templates { get; set; }
public VariableSetResource VariableSet { get; set; }
public IEnumerable<ChannelResource> Channels { get; set; }
public IDictionary<string, LifecycleResource> ChannelLifecycles { get; set; }

public IDictionary<string, LifecycleResource> ChannelLifecycles { get; set; }
}

public ProjectImporter(IOctopusRepository repository, IOctopusFileSystem fileSystem, ILog log)
Expand All @@ -59,6 +57,7 @@ protected override bool Validate(Dictionary<string, string> paramDictionary)
{
throw new CommandException("Unable to find a lifecycle to assign to this project.");
}

Log.DebugFormat("Found lifecycle '{0}'", existingLifecycle.Name);
project.LifecycleId = existingLifecycle.Id;
}
Expand Down Expand Up @@ -470,7 +469,6 @@ IEnumerable<KeyValuePair<string, ChannelResource>> ImportProjectChannels(List<Ch
}
else
{

Log.Debug("Channel does not exist, a new channel will be created");
channel.ProjectId = importedProject.Id;
if (channel.LifecycleId != null)
Expand Down Expand Up @@ -516,7 +514,6 @@ ProjectResource ImportProject(ProjectResource project, string projectGroupId, ID

return Repository.Projects.Create(project);
}


protected CheckedReferences<ProjectGroupResource> CheckProjectGroup(ReferenceDataItem projectGroup)
{
Expand Down Expand Up @@ -546,7 +543,12 @@ protected CheckedReferences<FeedResource> CheckNuGetFeedsExist(List<ReferenceDat
var dependencies = new CheckedReferences<FeedResource>();
foreach (var nugetFeed in nugetFeeds)
{
var feed = Repository.Feeds.FindByName(nugetFeed.Name);
FeedResource feed = null;
if (FeedCustomExpressionHelper.IsRealFeedId(nugetFeed.Id))
feed = Repository.Feeds.FindByName(nugetFeed.Name);
else
feed = FeedCustomExpressionHelper.CustomExpressionFeedWithId(nugetFeed.Id);

dependencies.Register(nugetFeed.Name, nugetFeed.Id, feed);
}
return dependencies;
Expand Down
1 change: 1 addition & 0 deletions source/Octopus.Cli/Octopus.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
<Compile Include="Repositories\ActionTemplateRepository.cs" />
<Compile Include="Repositories\IActionTemplateRepository.cs" />
<Compile Include="Util\DeletionOptions.cs" />
<Compile Include="Util\FeedCustomExpressionHelper.cs" />
<Compile Include="Util\Humanize.cs" />
<Compile Include="Util\IOctopusFileSystem.cs" />
<Compile Include="Util\LineSplitter.cs" />
Expand Down
40 changes: 40 additions & 0 deletions source/Octopus.Cli/Util/FeedCustomExpressionHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Octopus.Client.Model;
using System;

namespace Octopus.Cli.Util
{
/// <summary>
/// Helps with situations where feeds use custom expressions Eg. #{MyCustomFeedURL}
/// </summary>
public static class FeedCustomExpressionHelper
{
public static string CustomExpressionFeedName = "Custom expression";

public static FeedResource CustomExpressionFeedWithId(string id)
{
var feed = new FeedResource()
{
Id = id,
Name = FeedCustomExpressionHelper.CustomExpressionFeedName
};
return feed;
}

/// <summary>
/// Helps to check for a valid repository-based feed Id.
///
/// Feeds may have custom expressions as their Id, which may contain Octostache variable syntax #{MyCustomFeedURL}.
/// If you pass a custom expression Id like this to the API, it will resolve to /api/feeds/, return all the feeds, then
/// attempt to cast that response to a FeedResource object and you'll end up getting an empty FeedResource object instead
/// of null. This method helps you detect valid repository feed objects before running into this confusing API scenario.
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public static bool IsRealFeedId(string id)
{
if (id.StartsWith("feeds-", StringComparison.OrdinalIgnoreCase))
return true;
return false;
}
}
}

0 comments on commit 79a7266

Please sign in to comment.