Skip to content

Commit 11a5f7e

Browse files
thomhurstclaude
andauthored
refactor: Extract NuGet upload logic to shared helper (#1465)
* chore: Add .worktrees/ to .gitignore for parallel development 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: Extract NuGet upload logic to shared helper Extract duplicated NuGet package upload logic from UploadPackagesToNugetModule and UploadPackagesToLocalNuGetModule into a new NugetUploadHelper class. Fixes #1459 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Address code review feedback - type mismatch and null check - Fix UploadPackagesToLocalNuGetModule.cs: Use .Path property on Folder object when passing to source parameter (fixes type mismatch) - UploadPackagesToNugetModule.cs already has the required null check for API key at line 39 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 1dd3f30 commit 11a5f7e

3 files changed

Lines changed: 42 additions & 23 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using EnumerableAsyncProcessor.Extensions;
2+
using ModularPipelines.Context;
3+
using ModularPipelines.DotNet.Extensions;
4+
using ModularPipelines.DotNet.Options;
5+
using ModularPipelines.Models;
6+
using File = ModularPipelines.FileSystem.File;
7+
8+
namespace ModularPipelines.Build.Helpers;
9+
10+
public static class NugetUploadHelper
11+
{
12+
public static async Task<CommandResult[]> UploadPackagesAsync(
13+
IModuleContext context,
14+
IEnumerable<File> packagePaths,
15+
string source,
16+
string? apiKey,
17+
CancellationToken cancellationToken)
18+
{
19+
return await packagePaths
20+
.SelectAsync(async nugetFile => await context.DotNet().Nuget.Push(new DotNetNugetPushOptions
21+
{
22+
Path = nugetFile,
23+
Source = source,
24+
ApiKey = apiKey,
25+
}, cancellationToken), cancellationToken: cancellationToken)
26+
.ProcessOneAtATime();
27+
}
28+
}

src/ModularPipelines.Build/Modules/LocalMachine/UploadPackagesToLocalNuGetModule.cs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
using EnumerableAsyncProcessor.Extensions;
2-
using Microsoft.Extensions.Logging;
31
using ModularPipelines.Attributes;
2+
using ModularPipelines.Build.Helpers;
43
using ModularPipelines.Context;
5-
using ModularPipelines.DotNet.Extensions;
6-
using ModularPipelines.DotNet.Options;
74
using ModularPipelines.Extensions;
85
using ModularPipelines.FileSystem;
96
using ModularPipelines.Models;
@@ -23,12 +20,11 @@ public class UploadPackagesToLocalNuGetModule : Module<CommandResult[]>
2320
var localRepoLocation = context.GetModule<CreateLocalNugetFolderModule, Folder>();
2421
var packagePaths = context.GetModule<PackagePathsParserModule, List<File>>();
2522

26-
return await packagePaths.Value!
27-
.SelectAsync(async nugetFile => await context.DotNet().Nuget.Push(new DotNetNugetPushOptions
28-
{
29-
Path = nugetFile,
30-
Source = localRepoLocation.Value.AssertExists(),
31-
}, cancellationToken), cancellationToken: cancellationToken)
32-
.ProcessOneAtATime();
23+
return await NugetUploadHelper.UploadPackagesAsync(
24+
context,
25+
packagePaths.Value!,
26+
source: localRepoLocation.Value.AssertExists()!.Path,
27+
apiKey: null,
28+
cancellationToken);
3329
}
3430
}

src/ModularPipelines.Build/Modules/UploadPackagesToNugetModule.cs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
using EnumerableAsyncProcessor.Extensions;
2-
using Microsoft.Extensions.Logging;
31
using Microsoft.Extensions.Options;
42
using ModularPipelines.Attributes;
3+
using ModularPipelines.Build.Helpers;
54
using ModularPipelines.Build.Settings;
65
using ModularPipelines.Context;
7-
using ModularPipelines.DotNet.Extensions;
8-
using ModularPipelines.DotNet.Options;
96
using ModularPipelines.Git.Attributes;
107
using ModularPipelines.GitHub.Attributes;
118
using ModularPipelines.Models;
@@ -43,13 +40,11 @@ public Task<SkipDecision> ShouldSkip(IPipelineContext context)
4340

4441
var packagePaths = context.GetModule<PackagePathsParserModule, List<File>>();
4542

46-
return await packagePaths.Value!
47-
.SelectAsync(async nugetFile => await context.DotNet().Nuget.Push(new DotNetNugetPushOptions
48-
{
49-
Path = nugetFile,
50-
Source = "https://api.nuget.org/v3/index.json",
51-
ApiKey = _nugetSettings.Value.ApiKey!,
52-
}, cancellationToken), cancellationToken: cancellationToken)
53-
.ProcessOneAtATime();
43+
return await NugetUploadHelper.UploadPackagesAsync(
44+
context,
45+
packagePaths.Value!,
46+
source: "https://api.nuget.org/v3/index.json",
47+
apiKey: _nugetSettings.Value.ApiKey,
48+
cancellationToken);
5449
}
5550
}

0 commit comments

Comments
 (0)