This repository was archived by the owner on Apr 16, 2020. It is now read-only.
File tree 5 files changed +47
-29
lines changed
SourceLink.Create.BitBucket
5 files changed +47
-29
lines changed Original file line number Diff line number Diff line change 1
-
2
- namespace SourceLink . Create . BitBucket
1
+ namespace SourceLink . Create . BitBucket
3
2
{
4
3
public static class UrlConverter
5
4
{
6
5
public static string Convert ( string origin )
7
6
{
8
- if ( ! origin . Contains ( "bitbucket.org" ) ) return null ;
7
+ if ( ! origin . Contains ( "bitbucket.org" ) )
8
+ return null ;
9
+
9
10
if ( origin . StartsWith ( "git@" ) )
10
11
{
11
12
origin = origin . Replace ( ':' , '/' ) ;
12
13
origin = origin . Replace ( "git@" , "https://" ) ;
13
14
}
14
- origin = origin . Replace ( ".git" , "" ) ;
15
+ origin = origin . Replace ( ".git" , string . Empty ) ;
16
+ origin = origin . TrimEnd ( '/' ) ;
17
+
15
18
var uri = new System . Uri ( origin ) ;
16
- return "https://bitbucket.org" + uri . LocalPath + " /raw/{commit}/*";
19
+ return $ "https://bitbucket.org{ uri . LocalPath } /raw/{{ commit} }/*";
17
20
}
18
21
}
19
22
}
Original file line number Diff line number Diff line change 1
-
2
- namespace SourceLink . Create . GitHub
1
+ namespace SourceLink . Create . GitHub
3
2
{
4
3
public static class UrlConverter
5
4
{
6
5
public static string Convert ( string origin )
7
6
{
8
- if ( ! origin . Contains ( "github.com" ) ) return null ;
7
+ if ( ! origin . Contains ( "github.com" ) )
8
+ return null ;
9
+
9
10
if ( origin . StartsWith ( "git@" ) )
10
11
{
11
12
origin = origin . Replace ( ':' , '/' ) ;
12
13
origin = origin . Replace ( "git@" , "https://" ) ;
13
14
}
14
- origin = origin . Replace ( ".git" , "" ) ;
15
+
16
+ origin = origin . Replace ( ".git" , string . Empty ) ;
17
+ origin = origin . TrimEnd ( '/' ) ;
15
18
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}}/*";
17
21
}
18
22
}
19
23
}
Original file line number Diff line number Diff line change 15
15
<ItemGroup >
16
16
<ProjectReference Include =" ..\dotnet-sourcelink-git\dotnet-sourcelink-git.csproj" />
17
17
<ProjectReference Include =" ..\dotnet-sourcelink\dotnet-sourcelink.csproj" />
18
+ <ProjectReference Include =" ..\SourceLink.Create.BitBucket\SourceLink.Create.BitBucket.csproj" />
18
19
<ProjectReference Include =" ..\SourceLink.Create.GitHub\SourceLink.Create.GitHub.csproj" />
19
20
</ItemGroup >
20
21
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments