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

Commit c9d6603

Browse files
SeanFeldmanctaggart
authored andcommitted
URLs with trailing slash (#240)
* fixes #232 * additional test case * Updated BitBucket URL converter as well * merged rebase conflict * fixing implementations * Today's special: test one one cover another for the same price
1 parent b257c1b commit c9d6603

File tree

5 files changed

+47
-29
lines changed

5 files changed

+47
-29
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-

2-
namespace SourceLink.Create.BitBucket
1+
namespace SourceLink.Create.BitBucket
32
{
43
public static class UrlConverter
54
{
65
public static string Convert(string origin)
76
{
8-
if (!origin.Contains("bitbucket.org")) return null;
7+
if (!origin.Contains("bitbucket.org"))
8+
return null;
9+
910
if (origin.StartsWith("git@"))
1011
{
1112
origin = origin.Replace(':', '/');
1213
origin = origin.Replace("git@", "https://");
1314
}
14-
origin = origin.Replace(".git", "");
15+
origin = origin.Replace(".git", string.Empty);
16+
origin = origin.TrimEnd('/');
17+
1518
var uri = new System.Uri(origin);
16-
return "https://bitbucket.org" + uri.LocalPath + "/raw/{commit}/*";
19+
return $"https://bitbucket.org{uri.LocalPath}/raw/{{commit}}/*";
1720
}
1821
}
1922
}
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1-

2-
namespace SourceLink.Create.GitHub
1+
namespace SourceLink.Create.GitHub
32
{
43
public static class UrlConverter
54
{
65
public static string Convert(string origin)
76
{
8-
if (!origin.Contains("github.com")) return null;
7+
if (!origin.Contains("github.com"))
8+
return null;
9+
910
if (origin.StartsWith("git@"))
1011
{
1112
origin = origin.Replace(':', '/');
1213
origin = origin.Replace("git@", "https://");
1314
}
14-
origin = origin.Replace(".git", "");
15+
16+
origin = origin.Replace(".git", string.Empty);
17+
origin = origin.TrimEnd('/');
1518
var uri = new System.Uri(origin);
16-
return "https://raw.githubusercontent.com" + uri.LocalPath + "/{commit}/*";
19+
20+
return $"https://raw.githubusercontent.com{uri.LocalPath}/{{commit}}/*";
1721
}
1822
}
1923
}

Tests/Tests.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<ItemGroup>
1616
<ProjectReference Include="..\dotnet-sourcelink-git\dotnet-sourcelink-git.csproj" />
1717
<ProjectReference Include="..\dotnet-sourcelink\dotnet-sourcelink.csproj" />
18+
<ProjectReference Include="..\SourceLink.Create.BitBucket\SourceLink.Create.BitBucket.csproj" />
1819
<ProjectReference Include="..\SourceLink.Create.GitHub\SourceLink.Create.GitHub.csproj" />
1920
</ItemGroup>
2021

Tests/When_parsing_GitHub_links.cs

-19
This file was deleted.

Tests/When_parsing_links.cs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using Xunit;
2+
3+
namespace Tests
4+
{
5+
public class When_parsing_links
6+
{
7+
[Theory]
8+
[InlineData("git@github.com:ctaggart/sourcelink-test.git")]
9+
[InlineData("https://github.com/ctaggart/sourcelink-test.git")]
10+
[InlineData("https://github.com/ctaggart/sourcelink-test")]
11+
[InlineData("https://github.com/ctaggart/sourcelink-test/")]
12+
public void Should_return_url_in_canonical_form_for_GitHub(string provided)
13+
{
14+
var task = new SourceLink.Create.GitHub.CreateTask();
15+
Assert.Equal("https://raw.githubusercontent.com/ctaggart/sourcelink-test/{commit}/*", task.ConvertUrl(provided));
16+
}
17+
18+
[Theory]
19+
[InlineData("git@bitbucket.org:ctaggart/sourcelink-test.git")]
20+
[InlineData("https://bitbucket.org/ctaggart/sourcelink-test.git")]
21+
[InlineData("https://bitbucket.org/ctaggart/sourcelink-test")]
22+
[InlineData("https://bitbucket.org/ctaggart/sourcelink-test/")]
23+
public void Should_return_url_in_canonical_form_for_BitBucket(string provided)
24+
{
25+
var task = new SourceLink.Create.BitBucket.CreateTask();
26+
Assert.Equal("https://bitbucket.org/ctaggart/sourcelink-test/raw/{commit}/*", task.ConvertUrl(provided));
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)