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

add support for the GitLab SourceLinkServerType #271

Merged
merged 1 commit into from
Oct 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ The [source link documention](https://github.com/dotnet/core/blob/master/Documen

If you are building on Windows, make sure that you configure git to checkout files with [core.autocrlf input](https://github.com/ctaggart/SourceLink/wiki/Line-Endings).

By default `SourceLink.Create.CommandLine` will try to process GitHub and BitBucket cloned repositories. You can specify a specific server type by setting the `SourceLinkServerType` MSBuild property like `/p:SourceLinkServerType=GitHub`, `/p:SourceLinkServerType=BitBucket` or `/p:SourceLinkServerType=BitBucketServer`.
By default `SourceLink.Create.CommandLine` will try to process GitHub and BitBucket cloned repositories. You can specify a specific server type by setting the `SourceLinkServerType` MSBuild property like `/p:SourceLinkServerType=GitHub`, `/p:SourceLinkServerType=BitBucket`, `/p:SourceLinkServerType=BitBucketServer` or `/p:SourceLinkServerType=GitLab`.

You can control when it runs by setting the `SourceLinkCreate` property. That property is set to `true` by default on build servers that set `CI` or `BUILD_NUMBER` environment variables. In general these tools are meant to be run only on build servers, but you can test locally by setting an MSBuild property like `/p:ci=true` or `/p:SourceLinkCreate=true`.

Expand Down
3 changes: 3 additions & 0 deletions SourceLink.Create.CommandLine/CreateTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ public static string ConvertUrl(string origin, string serverType)
case "GITHUB":
urlConverters.Add(GitHub.UrlConverter.Convert);
break;
case "GITLAB":
urlConverters.Add(GitLab.UrlConverter.Convert);
break;
case "BITBUCKET":
urlConverters.Add(BitBucket.UrlConverter.Convert);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<Compile Include="..\SourceLink.Create.BitBucket\BitBucketUrlConverter.cs" Link="BitBucketUrlConverter.cs" />
<Compile Include="..\SourceLink.Create.BitBucketServer\BitBucketServerUrlConverter.cs" Link="BitBucketServerUrlConverter.cs" />
<Compile Include="..\SourceLink.Create.GitHub\GitHubUrlConverter.cs" Link="GitHubUrlConverter.cs" />
<Compile Include="..\SourceLink.Create.GitLab\GitLabUrlConverter.cs" Link="GitLabUrlConverter.cs" />
</ItemGroup>

<ItemGroup>
Expand Down
10 changes: 10 additions & 0 deletions SourceLink.Create.GitLab/CreateTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace SourceLink.Create.GitLab
{
public class CreateTask : GitCreateTask
{
public override string ConvertUrl(string origin)
{
return UrlConverter.Convert(origin);
}
}
}
20 changes: 20 additions & 0 deletions SourceLink.Create.GitLab/GitLabUrlConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace SourceLink.Create.GitLab
{
public static class UrlConverter
{
public static string Convert(string origin)
{
if (origin.StartsWith("git@"))
{
origin = origin.Replace(':', '/');
origin = origin.Replace("git@", "https://");
}

origin = origin.Replace(".git", string.Empty);
origin = origin.TrimEnd('/');
var uri = new System.Uri(origin);

return $"https://{uri.Authority}{uri.LocalPath}/raw/{{commit}}/*";
}
}
}
39 changes: 39 additions & 0 deletions SourceLink.Create.GitLab/SourceLink.Create.GitLab.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="../build/common.props" />
<PropertyGroup>
<TargetFrameworks>netstandard1.4;net461</TargetFrameworks>
<!-- https://github.com/NuGet/Home/wiki/Adding-nuget-pack-as-a-msbuild-target -->
<IncludeBuildOutput>false</IncludeBuildOutput>
<!--<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>-->
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="15.1.548" PrivateAssets="all" />
</ItemGroup>

<!-- https://docs.microsoft.com/en-us/dotnet/articles/core/preview3/tools/extensibility -->
<ItemGroup Label="dotnet pack instructions">
<Content Include="SourceLink.Create.GitLab.targets">
<Pack>true</Pack>
<PackagePath>build</PackagePath>
</Content>

<Content Include="$(OutputPath)netstandard1.4/SourceLink.Create.GitLab.dll">
<Pack>true</Pack>
<PackagePath>build/netstandard1.4</PackagePath>
</Content>
<Content Include="$(OutputPath)netstandard1.4/SourceLink.Create.GitLab.deps.json">
<Pack>true</Pack>
<PackagePath>build/netstandard1.4</PackagePath>
</Content>

<Content Include="$(OutputPath)net461/SourceLink.Create.GitLab.dll">
<Pack>true</Pack>
<PackagePath>build/net461</PackagePath>
</Content>
</ItemGroup>
<Import Project="..\SourceLink.Create.Shared\SourceLink.Create.Shared.projitems" Label="Shared" />
<Import Project="..\SourceLink.Shared\SourceLink.Shared.projitems" Label="Shared" />

<Import Project="../build/sourcelink.props" />
</Project>
38 changes: 38 additions & 0 deletions SourceLink.Create.GitLab/SourceLink.Create.GitLab.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<Project>
<PropertyGroup>
<SourceLinkCreateGitLabDll Condition="'$(MSBuildRuntimeType)' == 'Core'">netstandard1.4\SourceLink.Create.GitLab.dll</SourceLinkCreateGitLabDll>
<SourceLinkCreateGitLabDll Condition="'$(MSBuildRuntimeType)' != 'Core'">net461\SourceLink.Create.GitLab.dll</SourceLinkCreateGitLabDll>
</PropertyGroup>
<UsingTask TaskName="SourceLink.Create.GitLab.CreateTask" AssemblyFile="$(SourceLinkCreateGitLabDll)" />

<PropertyGroup>
<SourceLinkCreate Condition="'$(SourceLinkCreate)' == ''">$(CI)</SourceLinkCreate>
<SourceLinkCreate Condition="'$(SourceLinkCreate)' == '' and '$(BUILD_NUMBER)' != ''">true</SourceLinkCreate>
<SourceLinkCreate Condition="'$(SourceLinkCreate)' == '' and '$(TF_BUILD)' != ''">true</SourceLinkCreate>
<CompileDependsOn Condition="'$(SourceLinkCreate)' == 'true'">SourceLinkCreate;$(CompileDependsOn)</CompileDependsOn>
<SourceLinkRepo Condition="'$(SourceLinkRepo)' == ''">$(MSBuildProjectDirectory)</SourceLinkRepo>
<SourceLinkFile Condition="'$(SourceLinkFile)' == ''">$(SourceLink)</SourceLinkFile>
<SourceLinkFile Condition="'$(SourceLinkFile)' == ''">$(IntermediateOutputPath)sourcelink.json</SourceLinkFile>
<SourceLinkNotInGit Condition="'$(SourceLinkNotInGit)' == ''">embed</SourceLinkNotInGit>
<SourceLinkHashMismatch Condition="'$(SourceLinkHashMismatch)' == ''">embed</SourceLinkHashMismatch>
</PropertyGroup>

<ItemGroup>
<SourceLinkSources Condition="'@(SourceLinkSources)' == ''" Include="@(Compile)" Exclude="@(EmbeddedFiles)" />
</ItemGroup>

<Target Name="SourceLinkCreate">
<SourceLink.Create.GitLab.CreateTask
GitDirectory="$(SourceLinkGitDirectory)"
Url="$(SourceLinkUrl)"
File="$(SourceLinkFile)"
Sources="@(SourceLinkSources)"
NoAutoLF="$(SourceLinkNoAutoLF)"
NotInGit="$(SourceLinkNotInGit)"
HashMismatch="$(SourceLinkHashMismatch)"
EmbeddedFilesIn="@(EmbeddedFiles)">
<Output PropertyName="SourceLink" TaskParameter="SourceLink" />
<Output ItemName="EmbeddedFiles" TaskParameter="EmbeddedFiles" />
</SourceLink.Create.GitLab.CreateTask>
</Target>
</Project>
17 changes: 16 additions & 1 deletion SourceLink.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.12
VisualStudioVersion = 15.0.26730.16
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{876D3926-2BE5-40B4-B9D4-1218875A3870}"
ProjectSection(SolutionItems) = preProject
Expand All @@ -15,6 +15,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnet-sourcelink", "dotnet
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SourceLink.Create.GitHub", "SourceLink.Create.GitHub\SourceLink.Create.GitHub.csproj", "{5CEE8EC8-7A54-4860-8B5D-29F89D7F7F4C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SourceLink.Create.GitLab", "SourceLink.Create.GitLab\SourceLink.Create.GitLab.csproj", "{A103EF79-CB2F-43FE-940C-491DE05756B6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnet-sourcelink-git", "dotnet-sourcelink-git\dotnet-sourcelink-git.csproj", "{87BCE13E-47FF-43A4-ADF4-F645FD4966AD}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj", "{13B28F5D-43CA-4243-A932-3352BB788216}"
Expand Down Expand Up @@ -93,6 +95,18 @@ Global
{5CEE8EC8-7A54-4860-8B5D-29F89D7F7F4C}.Release|x64.Build.0 = Release|Any CPU
{5CEE8EC8-7A54-4860-8B5D-29F89D7F7F4C}.Release|x86.ActiveCfg = Release|Any CPU
{5CEE8EC8-7A54-4860-8B5D-29F89D7F7F4C}.Release|x86.Build.0 = Release|Any CPU
{A103EF79-CB2F-43FE-940C-491DE05756B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A103EF79-CB2F-43FE-940C-491DE05756B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A103EF79-CB2F-43FE-940C-491DE05756B6}.Debug|x64.ActiveCfg = Debug|Any CPU
{A103EF79-CB2F-43FE-940C-491DE05756B6}.Debug|x64.Build.0 = Debug|Any CPU
{A103EF79-CB2F-43FE-940C-491DE05756B6}.Debug|x86.ActiveCfg = Debug|Any CPU
{A103EF79-CB2F-43FE-940C-491DE05756B6}.Debug|x86.Build.0 = Debug|Any CPU
{A103EF79-CB2F-43FE-940C-491DE05756B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A103EF79-CB2F-43FE-940C-491DE05756B6}.Release|Any CPU.Build.0 = Release|Any CPU
{A103EF79-CB2F-43FE-940C-491DE05756B6}.Release|x64.ActiveCfg = Release|Any CPU
{A103EF79-CB2F-43FE-940C-491DE05756B6}.Release|x64.Build.0 = Release|Any CPU
{A103EF79-CB2F-43FE-940C-491DE05756B6}.Release|x86.ActiveCfg = Release|Any CPU
{A103EF79-CB2F-43FE-940C-491DE05756B6}.Release|x86.Build.0 = Release|Any CPU
{87BCE13E-47FF-43A4-ADF4-F645FD4966AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{87BCE13E-47FF-43A4-ADF4-F645FD4966AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{87BCE13E-47FF-43A4-ADF4-F645FD4966AD}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -196,6 +210,7 @@ Global
GlobalSection(NestedProjects) = preSolution
{68D40DAC-77EF-426A-979D-1CC4723CB2A1} = {2402E19F-C4A4-43A4-B939-F5CD198EEED3}
{5CEE8EC8-7A54-4860-8B5D-29F89D7F7F4C} = {F157756B-2442-4131-848B-CBEF39E8F706}
{A103EF79-CB2F-43FE-940C-491DE05756B6} = {F157756B-2442-4131-848B-CBEF39E8F706}
{87BCE13E-47FF-43A4-ADF4-F645FD4966AD} = {2402E19F-C4A4-43A4-B939-F5CD198EEED3}
{FB0D8C0B-27DF-4D20-9F15-09794D95F744} = {F157756B-2442-4131-848B-CBEF39E8F706}
{76CC64F0-2D47-4B3C-ADEA-6E758953F2D3} = {F157756B-2442-4131-848B-CBEF39E8F706}
Expand Down
1 change: 1 addition & 0 deletions Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<ProjectReference Include="..\SourceLink.Create.BitBucket\SourceLink.Create.BitBucket.csproj" />
<ProjectReference Include="..\SourceLink.Create.BitBucketServer\SourceLink.Create.BitBucketServer.csproj" />
<ProjectReference Include="..\SourceLink.Create.GitHub\SourceLink.Create.GitHub.csproj" />
<ProjectReference Include="..\SourceLink.Create.GitLab\SourceLink.Create.GitLab.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
11 changes: 11 additions & 0 deletions Tests/When_parsing_links.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ public void Should_return_url_in_canonical_form_for_GitHub(string provided)
Assert.Equal("https://raw.githubusercontent.com/ctaggart/sourcelink-test/{commit}/*", task.ConvertUrl(provided));
}

[Theory]
[InlineData("[email protected]:ctaggart/sourcelink-test.git")]
[InlineData("https://gitlab.com/ctaggart/sourcelink-test.git")]
[InlineData("https://gitlab.com/ctaggart/sourcelink-test")]
[InlineData("https://gitlab.com/ctaggart/sourcelink-test/")]
public void Should_return_url_in_canonical_form_for_GitLab(string provided)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth adding local GitLab urls as well to the tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like also test against a gitlab.example.com domain?

{
var task = new SourceLink.Create.GitLab.CreateTask();
Assert.Equal("https://gitlab.com/ctaggart/sourcelink-test/raw/{commit}/*", task.ConvertUrl(provided));
}

[Theory]
[InlineData("[email protected]:ctaggart/sourcelink-test.git")]
[InlineData("https://bitbucket.org/ctaggart/sourcelink-test.git")]
Expand Down
6 changes: 5 additions & 1 deletion build.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$version = '2.4.1' # the version under development, update after a release
$versionSuffix = '-a124' # manually incremented for local builds
$versionSuffix = '-a125' # manually incremented for local builds

function isVersionTag($tag){
$v = New-Object Version
Expand Down Expand Up @@ -30,6 +30,10 @@ Set-Location $psscriptroot\SourceLink.Create.GitHub
dotnet restore
dotnet $pack

Set-Location $psscriptroot\SourceLink.Create.GitLab
dotnet restore
dotnet $pack

Set-Location $psscriptroot\SourceLink.Create.BitBucket
dotnet restore
dotnet $pack
Expand Down