Skip to content

Commit

Permalink
Improve exception message if multiple modified files with absolute pa…
Browse files Browse the repository at this point in the history
…th are found (#368)
  • Loading branch information
pascalberger committed Oct 26, 2023
1 parent 5c9f24c commit c3c5d96
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/Cake.Issues.PullRequests.Tests/IssueFiltererTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Cake.Issues.PullRequests.Tests
{
using System;
using System.Collections.Generic;
using System.Linq;
using Cake.Core.IO;
Expand Down Expand Up @@ -157,7 +158,9 @@ public void Should_Throw_If_Modified_Files_Contain_Absolute_Path()
new Dictionary<IIssue, IssueCommentInfo>()));

// Then
result.IsPullRequestIssuesException(@"Absolute file paths are not supported for modified files. Path: c:/FakeIssueProvider.cs");
result.IsPullRequestIssuesException(
@"Absolute file paths are not supported for modified files:" + Environment.NewLine +
@" c:/FakeIssueProvider.cs");
}

[Fact]
Expand Down
5 changes: 3 additions & 2 deletions src/Cake.Issues.PullRequests/IssueFilterer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,11 @@ internal class IssueFilterer
/// <param name="modifiedFilePaths">List of modified files in the pull request.</param>
private static void ValidateModifiedFiles(IEnumerable<FilePath> modifiedFilePaths)
{
foreach (var filePath in modifiedFilePaths.Where(x => !x.IsRelative))
var absoluteFilePaths = modifiedFilePaths.Where(x => !x.IsRelative).ToList();
if (absoluteFilePaths.Any())
{
throw new PullRequestIssuesException(
$"Absolute file paths are not supported for modified files. Path: {filePath}");
$"Absolute file paths are not supported for modified files:{Environment.NewLine}{string.Join(Environment.NewLine, absoluteFilePaths.Select(x => " " + x))}");
}
}

Expand Down

0 comments on commit c3c5d96

Please sign in to comment.