diff --git a/src/ModularPipelines.Build/Modules/CodeFormattedNicelyModule.cs b/src/ModularPipelines.Build/Modules/CodeFormattedNicelyModule.cs index 4cc3644de3..e3e0ead7e1 100644 --- a/src/ModularPipelines.Build/Modules/CodeFormattedNicelyModule.cs +++ b/src/ModularPipelines.Build/Modules/CodeFormattedNicelyModule.cs @@ -44,21 +44,10 @@ public Task ShouldSkip(IPipelineContext context) try { - await context.DotNet().Format(new DotNetFormatOptions - { - Arguments = ["whitespace"], - WorkingDirectory = context.Git().RootDirectory, - VerifyNoChanges = true, - Severity = "info", - }, cancellationToken); + await RunDotNetFormat(context, whitespaceOnly: true, verifyNoChanges: true, cancellationToken); // The code hasn't been formatted nicely! - return await context.DotNet().Format(new DotNetFormatOptions - { - WorkingDirectory = context.Git().RootDirectory, - VerifyNoChanges = true, - Severity = "info", - }, cancellationToken); + return await RunDotNetFormat(context, whitespaceOnly: false, verifyNoChanges: true, cancellationToken); } catch (Exception) { @@ -70,20 +59,8 @@ await context.DotNet().Format(new DotNetFormatOptions ArgumentNullException.ThrowIfNull(_githubSettings.Value.StandardToken); - await context.DotNet().Format(new DotNetFormatOptions - { - WorkingDirectory = context.Git().RootDirectory, - VerifyNoChanges = false, - Severity = "info", - }, cancellationToken); - - await context.DotNet().Format(new DotNetFormatOptions - { - Arguments = ["whitespace"], - WorkingDirectory = context.Git().RootDirectory, - VerifyNoChanges = false, - Severity = "info", - }, cancellationToken); + await RunDotNetFormat(context, whitespaceOnly: false, verifyNoChanges: false, cancellationToken); + await RunDotNetFormat(context, whitespaceOnly: true, verifyNoChanges: false, cancellationToken); var branchTriggeringPullRequest = context.GitHub().EnvironmentVariables.HeadRef!; @@ -98,4 +75,21 @@ await GitHelpers.CommitAndPush(context, branchTriggeringPullRequest, DotnetForma throw new Exception("Formatting code. This run will abort. Another run will trigger with the formatted code."); } } + + private static Task RunDotNetFormat( + IModuleContext context, + bool whitespaceOnly, + bool verifyNoChanges, + CancellationToken cancellationToken) + { + var options = new DotNetFormatOptions + { + Arguments = whitespaceOnly ? ["whitespace"] : null, + WorkingDirectory = context.Git().RootDirectory, + VerifyNoChanges = verifyNoChanges, + Severity = "info", + }; + + return context.DotNet().Format(options, cancellationToken); + } } \ No newline at end of file