Skip to content
This repository was archived by the owner on Apr 6, 2024. It is now read-only.

Commit 4ecf644

Browse files
authored
Merge pull request #38 from cake-contrib/feature/issue-extensions
(GH-37) Add extension for returning file name and path
2 parents e1bc183 + 5e94212 commit 4ecf644

File tree

4 files changed

+35
-12
lines changed

4 files changed

+35
-12
lines changed

src/Cake.Issues.Reporting.Generic/Cake.Issues.Reporting.Generic.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
<Compile Include="GenericIssueReportFormatAliases.cs" />
7474
<Compile Include="GenericIssueReportGenerator.cs" />
7575
<Compile Include="GenericIssueReportFormatSettings.cs" />
76+
<Compile Include="IIssueExtension.cs" />
7677
<Compile Include="RazorEngineReferenceResolver.cs" />
7778
<Compile Include="GenericIssueReportTemplate.cs" />
7879
<Compile Include="GenericIssueReportTemplateExtensions.cs" />
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
namespace Cake.Issues.Reporting.Generic
2+
{
3+
using Cake.Core.IO;
4+
5+
/// <summary>
6+
/// Extension for <see cref="IIssue"/>.
7+
/// </summary>
8+
public static class IIssueExtension
9+
{
10+
/// <summary>
11+
/// Returns the path of the <see cref="IIssue.AffectedFileRelativePath"/>.
12+
/// </summary>
13+
/// <param name="issue">Issue for which the path should be returned.</param>
14+
/// <returns>Path of the file affected by the issue.</returns>
15+
public static string FilePath(this IIssue issue)
16+
{
17+
return issue.AffectedFileRelativePath?.GetDirectory().FullPath;
18+
}
19+
20+
/// <summary>
21+
/// Returns the name of the file of the <see cref="IIssue.AffectedFileRelativePath"/>.
22+
/// </summary>
23+
/// <param name="issue">Issue for which the file name should be returned.</param>
24+
/// <returns>Name of the file affected by the issue.</returns>
25+
public static string FileName(this IIssue issue)
26+
{
27+
return issue.AffectedFileRelativePath?.GetFilename().ToString();
28+
}
29+
}
30+
}

src/Cake.Issues.Reporting.Generic/RazorEngineReferenceResolver.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public IEnumerable<CompilerReference> GetReferences(
3131
yield return CompilerReference.From(this.FindLoaded(loadedAssemblies, "Newtonsoft.Json.dll"));
3232
yield return CompilerReference.From(this.FindLoaded(loadedAssemblies, "Cake.Core.dll"));
3333
yield return CompilerReference.From(this.FindLoaded(loadedAssemblies, "Cake.Issues.dll"));
34+
yield return CompilerReference.From(this.FindLoaded(loadedAssemblies, "Cake.Issues.Reporting.Generic.dll"));
3435
yield return CompilerReference.From(typeof(RazorEngine.Engine).Assembly);
3536
}
3637

src/Cake.Issues.Reporting.Generic/Templates/DataTable.cshtml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@model IEnumerable<Cake.Issues.IIssue>
2+
@using Cake.Issues.Reporting.Generic
23

34
<!DOCTYPE html>
45

@@ -77,18 +78,8 @@
7778
<tr>
7879
<td>@issue.PriorityName</td>
7980
<td>@issue.Project</td>
80-
<td>
81-
@if (issue.AffectedFileRelativePath != null)
82-
{
83-
@issue.AffectedFileRelativePath.GetDirectory()
84-
}
85-
</td>
86-
<td>
87-
@if (issue.AffectedFileRelativePath != null)
88-
{
89-
@issue.AffectedFileRelativePath.GetFilename()
90-
}
91-
</td>
81+
<td>@issue.FilePath()</td>
82+
<td>@issue.FileName()</td>
9283
<td>@issue.Line</td>
9384
<td>
9485
@if (issue.RuleUrl != null)

0 commit comments

Comments
 (0)