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

Commit 565fea3

Browse files
committed
Merge branch 'release/0.3.3'
2 parents 8686352 + 5cfeb4c commit 565fea3

11 files changed

+534
-3
lines changed

nuspec/nuget/Cake.Issues.Reporting.Generic.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ See the Project Site for an overview of the whole ecosystem of addins for workin
2121
<requireLicenseAcceptance>false</requireLicenseAcceptance>
2222
<copyright>Copyright © Pascal Berger</copyright>
2323
<tags>Cake Script Cake-Issues Cake-ReportFormat Issues Reporting Html Markdown</tags>
24-
<releaseNotes>https://github.com/cake-contrib/Cake.Issues.Reporting.Generic/releases/tag/0.3.2</releaseNotes>
24+
<releaseNotes>https://github.com/cake-contrib/Cake.Issues.Reporting.Generic/releases/tag/0.3.3</releaseNotes>
2525
</metadata>
2626
<files>
2727
<file src="Cake.Issues.Reporting.Generic.dll" target="lib\net46" />

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@
8585
<ItemGroup>
8686
<Compile Include="ColumnSortOrderExtensionsTests.cs" />
8787
<Compile Include="DevExtremeThemeExtensionsTests.cs" />
88+
<Compile Include="UriExtensionsTests.cs" />
89+
<Compile Include="FileLinkSettingsTests.cs" />
8890
<Compile Include="GenericIssueReportFixture.cs" />
8991
<Compile Include="GenericIssueReportFormatSettingsExtensionsTests.cs" />
9092
<Compile Include="GenericIssueReportFormatSettingsTests.cs" />
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
namespace Cake.Issues.Reporting.Generic.Tests
2+
{
3+
using System;
4+
using Cake.Issues.Testing;
5+
using Shouldly;
6+
using Xunit;
7+
8+
public sealed class FileLinkSettingsTests
9+
{
10+
public sealed class TheGitHubMethod
11+
{
12+
[Fact]
13+
public void Should_Throw_If_RepositoryUrl_Is_Null()
14+
{
15+
// Given
16+
Uri repositoryUrl = null;
17+
var branch = "master";
18+
var rootPath = string.Empty;
19+
20+
// When
21+
var result = Record.Exception(() =>
22+
FileLinkSettings.GitHub(repositoryUrl, branch, rootPath));
23+
24+
// Then
25+
result.IsArgumentNullException("repositoryUrl");
26+
}
27+
28+
[Fact]
29+
public void Should_Throw_If_Branch_Is_Null()
30+
{
31+
// Given
32+
var repositoryUrl = new Uri("https://github.com/cake-contrib/Cake.Issues.Website");
33+
string branch = null;
34+
var rootPath = string.Empty;
35+
36+
// When
37+
var result = Record.Exception(() =>
38+
FileLinkSettings.GitHub(repositoryUrl, branch, rootPath));
39+
40+
// Then
41+
result.IsArgumentNullException("branch");
42+
}
43+
44+
[Fact]
45+
public void Should_Throw_If_Branch_Is_Empty()
46+
{
47+
// Given
48+
var repositoryUrl = new Uri("https://github.com/cake-contrib/Cake.Issues.Website");
49+
var branch = string.Empty;
50+
var rootPath = string.Empty;
51+
52+
// When
53+
var result = Record.Exception(() =>
54+
FileLinkSettings.GitHub(repositoryUrl, branch, rootPath));
55+
56+
// Then
57+
result.IsArgumentOutOfRangeException("branch");
58+
}
59+
60+
[Fact]
61+
public void Should_Throw_If_Branch_Is_Whitespace()
62+
{
63+
// Given
64+
var repositoryUrl = new Uri("https://github.com/cake-contrib/Cake.Issues.Website");
65+
var branch = " ";
66+
var rootPath = string.Empty;
67+
68+
// When
69+
var result = Record.Exception(() =>
70+
FileLinkSettings.GitHub(repositoryUrl, branch, rootPath));
71+
72+
// Then
73+
result.IsArgumentOutOfRangeException("branch");
74+
}
75+
76+
[Theory]
77+
[InlineData("https://github.com/cake-contrib/Cake.Issues.Website", "master", null, "https://github.com/cake-contrib/Cake.Issues.Website/blob/master/{FilePath}#L{Line}")]
78+
[InlineData("https://github.com/cake-contrib/Cake.Issues.Website/", "master", null, "https://github.com/cake-contrib/Cake.Issues.Website/blob/master/{FilePath}#L{Line}")]
79+
[InlineData("https://github.com/cake-contrib/Cake.Issues.Website", "master", "foo", "https://github.com/cake-contrib/Cake.Issues.Website/blob/master/foo/{FilePath}#L{Line}")]
80+
[InlineData("https://github.com/cake-contrib/Cake.Issues.Website", "master", "/foo", "https://github.com/cake-contrib/Cake.Issues.Website/blob/master/foo/{FilePath}#L{Line}")]
81+
[InlineData("https://github.com/cake-contrib/Cake.Issues.Website", "master", "foo/", "https://github.com/cake-contrib/Cake.Issues.Website/blob/master/foo/{FilePath}#L{Line}")]
82+
[InlineData("https://github.com/cake-contrib/Cake.Issues.Website", "master", "foo/bar", "https://github.com/cake-contrib/Cake.Issues.Website/blob/master/foo/bar/{FilePath}#L{Line}")]
83+
public void Should_Set_Correct_FileLinkPattern(string repositoryUrl, string branch, string rootPath, string expectedPattern)
84+
{
85+
// Given
86+
87+
// When
88+
var result = FileLinkSettings.GitHub(new Uri(repositoryUrl), branch, rootPath);
89+
90+
// Then
91+
result.FileLinkPattern.ShouldBe(expectedPattern);
92+
}
93+
}
94+
95+
public sealed class TheTeamFoundationServerMethod
96+
{
97+
[Fact]
98+
public void Should_Throw_If_RepositoryUrl_Is_Null()
99+
{
100+
// Given
101+
Uri repositoryUrl = null;
102+
var branch = "master";
103+
var rootPath = string.Empty;
104+
105+
// When
106+
var result = Record.Exception(() =>
107+
FileLinkSettings.TeamFoundationServer(repositoryUrl, branch, rootPath));
108+
109+
// Then
110+
result.IsArgumentNullException("repositoryUrl");
111+
}
112+
113+
[Fact]
114+
public void Should_Throw_If_Branch_Is_Null()
115+
{
116+
// Given
117+
var repositoryUrl = new Uri("http://myserver:8080/tfs/defaultcollection/myproject/_git/myrepository");
118+
string branch = null;
119+
var rootPath = string.Empty;
120+
121+
// When
122+
var result = Record.Exception(() =>
123+
FileLinkSettings.TeamFoundationServer(repositoryUrl, branch, rootPath));
124+
125+
// Then
126+
result.IsArgumentNullException("branch");
127+
}
128+
129+
[Fact]
130+
public void Should_Throw_If_Branch_Is_Empty()
131+
{
132+
// Given
133+
var repositoryUrl = new Uri("http://myserver:8080/tfs/defaultcollection/myproject/_git/myrepository");
134+
var branch = string.Empty;
135+
var rootPath = string.Empty;
136+
137+
// When
138+
var result = Record.Exception(() =>
139+
FileLinkSettings.TeamFoundationServer(repositoryUrl, branch, rootPath));
140+
141+
// Then
142+
result.IsArgumentOutOfRangeException("branch");
143+
}
144+
145+
[Fact]
146+
public void Should_Throw_If_Branch_Is_Whitespace()
147+
{
148+
// Given
149+
var repositoryUrl = new Uri("http://myserver:8080/tfs/defaultcollection/myproject/_git/myrepository");
150+
var branch = " ";
151+
var rootPath = string.Empty;
152+
153+
// When
154+
var result = Record.Exception(() =>
155+
FileLinkSettings.TeamFoundationServer(repositoryUrl, branch, rootPath));
156+
157+
// Then
158+
result.IsArgumentOutOfRangeException("branch");
159+
}
160+
161+
[Theory]
162+
[InlineData("http://myserver:8080/tfs/defaultcollection/myproject/_git/myrepository", "master", null, "http://myserver:8080/tfs/defaultcollection/myproject/_git/myrepository?path={FilePath}&version=GBmaster&line={Line}")]
163+
[InlineData("http://myserver:8080/tfs/defaultcollection/myproject/_git/myrepository/", "master", null, "http://myserver:8080/tfs/defaultcollection/myproject/_git/myrepository?path={FilePath}&version=GBmaster&line={Line}")]
164+
[InlineData("http://myserver:8080/tfs/defaultcollection/myproject/_git/myrepository", "master", "foo", "http://myserver:8080/tfs/defaultcollection/myproject/_git/myrepository?path=foo/{FilePath}&version=GBmaster&line={Line}")]
165+
[InlineData("http://myserver:8080/tfs/defaultcollection/myproject/_git/myrepository", "master", "/foo", "http://myserver:8080/tfs/defaultcollection/myproject/_git/myrepository?path=foo/{FilePath}&version=GBmaster&line={Line}")]
166+
[InlineData("http://myserver:8080/tfs/defaultcollection/myproject/_git/myrepository", "master", "foo/", "http://myserver:8080/tfs/defaultcollection/myproject/_git/myrepository?path=foo/{FilePath}&version=GBmaster&line={Line}")]
167+
[InlineData("http://myserver:8080/tfs/defaultcollection/myproject/_git/myrepository", "master", "foo/bar", "http://myserver:8080/tfs/defaultcollection/myproject/_git/myrepository?path=foo/bar/{FilePath}&version=GBmaster&line={Line}")]
168+
public void Should_Set_Correct_FileLinkPattern(string repositoryUrl, string branch, string rootPath, string expectedPattern)
169+
{
170+
// Given
171+
172+
// When
173+
var result = FileLinkSettings.TeamFoundationServer(new Uri(repositoryUrl), branch, rootPath);
174+
175+
// Then
176+
result.FileLinkPattern.ShouldBe(expectedPattern);
177+
}
178+
}
179+
}
180+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
namespace Cake.Issues.Reporting.Generic.Tests
2+
{
3+
using System;
4+
using Cake.Issues.Testing;
5+
using Shouldly;
6+
using Xunit;
7+
8+
public sealed class UriExtensionsTests
9+
{
10+
public sealed class TheAppendMethod
11+
{
12+
[Fact]
13+
public void Should_Throw_If_Uri_Is_Null()
14+
{
15+
// Given
16+
Uri uri = null;
17+
var path = "foo";
18+
19+
// When
20+
var result = Record.Exception(() =>
21+
uri.Append(path));
22+
23+
// Then
24+
result.IsArgumentNullException("uri");
25+
}
26+
27+
[Theory]
28+
[InlineData("https://google.com/foo/bar", "https://google.com", "foo", "bar")]
29+
[InlineData("https://google.com/foo/bar", "https://google.com/", "foo", "bar")]
30+
[InlineData("https://google.com/foo/bar", "https://google.com", "/foo", "bar")]
31+
[InlineData("https://google.com/foo/bar", "https://google.com", "foo/", "bar")]
32+
[InlineData("https://google.com/foo/bar", "https://google.com", "foo", "/bar")]
33+
[InlineData("https://google.com/foo/bar/", "https://google.com", "foo", "bar/")]
34+
[InlineData("https://google.com/foo/bar", "https://google.com", "foo/", "/bar")]
35+
[InlineData("https://google.com/bar", "https://google.com", null, "bar")]
36+
[InlineData("https://google.com/bar", "https://google.com", "", "bar")]
37+
[InlineData("https://google.com/bar", "https://google.com", " ", "bar")]
38+
[InlineData("https://google.com/bar", "https://google.com", "/", "/bar")]
39+
public void Should_Append_Paths(string expectedPath, string uri, params string[] paths)
40+
{
41+
// Given
42+
43+
// When
44+
var result = new Uri(uri).Append(paths);
45+
46+
// Then
47+
result.ToString().ShouldBe(expectedPath);
48+
}
49+
}
50+
}
51+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,16 @@
7070
<Compile Include="ColumnSortOrderExtensions.cs" />
7171
<Compile Include="DevExtremeTheme.cs" />
7272
<Compile Include="DevExtremeThemeExtensions.cs" />
73+
<Compile Include="FileLinkType.cs" />
74+
<Compile Include="FileLinkSettings.cs" />
7375
<Compile Include="HtmlDxDataGridOption.cs" />
7476
<Compile Include="GenericIssueReportFormatAliases.cs" />
7577
<Compile Include="GenericIssueReportFormatSettingsExtensions.cs" />
7678
<Compile Include="GenericIssueReportGenerator.cs" />
7779
<Compile Include="GenericIssueReportFormatSettings.cs" />
7880
<Compile Include="IIssueExtension.cs" />
7981
<Compile Include="ReportColumn.cs" />
82+
<Compile Include="UriExtensions.cs" />
8083
<Compile Include="ViewBagHelper.cs" />
8184
<Compile Include="RazorEngineReferenceResolver.cs" />
8285
<Compile Include="GenericIssueReportTemplate.cs" />
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
namespace Cake.Issues.Reporting.Generic
2+
{
3+
using System;
4+
5+
/// <summary>
6+
/// Settings how issues should be linked to files.
7+
/// </summary>
8+
public class FileLinkSettings
9+
{
10+
/// <summary>
11+
/// Gets or sets the pattern which should be used to link issues to files.
12+
/// Fields in the form <c>{FieldName}</c> are replaced with the value of the isse.
13+
/// All fields of <see cref="ReportColumn"/> supported.
14+
/// </summary>
15+
public string FileLinkPattern { get; set; }
16+
17+
/// <summary>
18+
/// Returns settings for linking to files hosted in GitHub.
19+
/// </summary>
20+
/// <param name="repositoryUrl">Full URL of the Git repository,
21+
/// eg. <code>https://github.com/cake-contrib/Cake.Issues.Reporting.Generic</code>.</param>
22+
/// <param name="branch">Name of the branch.</param>
23+
/// <param name="rootPath">Root path of the files.
24+
/// <c>null</c> or <see cref="string.Empty"/> if files are in the root of the repository.</param>
25+
/// <returns>Settings for linking to files hosted in GitHub.</returns>
26+
public static FileLinkSettings GitHub(
27+
Uri repositoryUrl,
28+
string branch,
29+
string rootPath)
30+
{
31+
repositoryUrl.NotNull(nameof(repositoryUrl));
32+
branch.NotNullOrWhiteSpace(nameof(branch));
33+
34+
return new FileLinkSettings()
35+
{
36+
FileLinkPattern = repositoryUrl.Append("blob", branch, rootPath, "{FilePath}#L{Line}").ToString()
37+
};
38+
}
39+
40+
/// <summary>
41+
/// Returns settings for linking to files hosted in Visual Studio Team Service or Team Foundation Server.
42+
/// </summary>
43+
/// <param name="repositoryUrl">Full URL of the Git repository,
44+
/// eg. <code>http://myserver:8080/tfs/defaultcollection/myproject/_git/myrepository</code>.</param>
45+
/// <param name="branch">Name of the branch.</param>
46+
/// <param name="rootPath">Root path of the files.
47+
/// <c>null</c> or <see cref="string.Empty"/> if files are in the root of the repository.</param>
48+
/// <returns>Settings for linking to files hosted in Visual Studio Team Service or Team Foundation Server.</returns>
49+
public static FileLinkSettings TeamFoundationServer(
50+
Uri repositoryUrl,
51+
string branch,
52+
string rootPath)
53+
{
54+
repositoryUrl.NotNull(nameof(repositoryUrl));
55+
branch.NotNullOrWhiteSpace(nameof(branch));
56+
57+
if (!string.IsNullOrWhiteSpace(rootPath))
58+
{
59+
rootPath = rootPath.Trim('/') + "/";
60+
}
61+
62+
return new FileLinkSettings()
63+
{
64+
FileLinkPattern =
65+
repositoryUrl.ToString().TrimEnd('/') + "?path=" + rootPath + "{FilePath}&version=GB" + branch + "&line={Line}"
66+
};
67+
}
68+
69+
/// <summary>
70+
/// Returns the file link with all patterns of <see cref="FileLinkPattern"/> replaced
71+
/// by the values of <paramref name="issue"/>.
72+
/// </summary>
73+
/// <param name="issue">Issue whose values should be used to replace the patterns.</param>
74+
/// <returns>File link with all patterns replaced.</returns>
75+
public string GetFileLink(IIssue issue)
76+
{
77+
issue.NotNull(nameof(issue));
78+
79+
if (string.IsNullOrWhiteSpace(this.FileLinkPattern))
80+
{
81+
return null;
82+
}
83+
84+
return
85+
this.FileLinkPattern
86+
.Replace("{ProviderType}", issue.ProviderType)
87+
.Replace("{ProviderName}", issue.ProviderName)
88+
.Replace("{Priority}", issue.Priority?.ToString())
89+
.Replace("{PriorityName}", issue.PriorityName)
90+
.Replace("{Project}", issue.Project)
91+
.Replace("{FilePath}", issue.AffectedFileRelativePath?.FullPath.ToString())
92+
.Replace("{Path}", issue.FilePath())
93+
.Replace("{File}", issue.FileName())
94+
.Replace("{Line}", issue.Line?.ToString())
95+
.Replace("{Rule}", issue.Rule)
96+
.Replace("{RuleUrl}", issue.RuleUrl?.ToString())
97+
.Replace("{Message}", issue.Message);
98+
}
99+
}
100+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace Cake.Issues.Reporting.Generic
2+
{
3+
/// <summary>
4+
/// Possible types how a issue can be linked to the file.
5+
/// </summary>
6+
public enum FileLinkType
7+
{
8+
/// <summary>
9+
/// Link through a hyperlink.
10+
/// </summary>
11+
Href,
12+
13+
/// <summary>
14+
/// Link through a JavaScript click.
15+
/// </summary>
16+
OnClick
17+
}
18+
}

0 commit comments

Comments
 (0)