-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add support for Gitee * update unit test for Gitee * update repository url translate test for Gitee * fix gitee task 'AssemblyFile' property * add integration tests for Gitee
- Loading branch information
Showing
26 changed files
with
559 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
// Licensed to the.NET Foundation under one or more agreements. | ||
// The.NET Foundation licenses this file to you under the MIT license. | ||
// See the License.txt file in the project root for more information. | ||
|
||
using System.IO; | ||
using TestUtilities; | ||
|
||
namespace Microsoft.SourceLink.IntegrationTests | ||
{ | ||
public class GiteeTests : DotNetSdkTestBase | ||
{ | ||
public GiteeTests() | ||
: base("Microsoft.SourceLink.Gitee") | ||
{ | ||
} | ||
|
||
[ConditionalFact(typeof(DotNetSdkAvailable))] | ||
public void FullValidation_Https() | ||
{ | ||
// Test non-ascii characters and escapes in the URL. | ||
// Escaped URI reserved characters should remain escaped, non-reserved characters unescaped in the results. | ||
var repoUrl = "https://噸.com/test-org/test-%72epo\u1234%24%2572%2F"; | ||
var repoName = "test-repo\u1234%24%2572%2F"; | ||
|
||
var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); | ||
var commitSha = repo.Head.Tip.Sha; | ||
|
||
VerifyValues( | ||
customProps: @" | ||
<PropertyGroup> | ||
<PublishRepositoryUrl>true</PublishRepositoryUrl> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<SourceLinkGiteeHost Include='噸.com'/> | ||
</ItemGroup> | ||
", | ||
customTargets: "", | ||
targets: new[] | ||
{ | ||
"Build", "Pack" | ||
}, | ||
expressions: new[] | ||
{ | ||
"@(SourceRoot)", | ||
"@(SourceRoot->'%(SourceLinkUrl)')", | ||
"$(SourceLink)", | ||
"$(PrivateRepositoryUrl)", | ||
"$(RepositoryUrl)" | ||
}, | ||
expectedResults: new[] | ||
{ | ||
NuGetPackageFolders, | ||
ProjectSourceRoot, | ||
$"https://噸.com/test-org/{repoName}/raw/{commitSha}/*", | ||
s_relativeSourceLinkJsonPath, | ||
$"https://噸.com/test-org/{repoName}", | ||
$"https://噸.com/test-org/{repoName}" | ||
}); | ||
|
||
AssertEx.AreEqual( | ||
$@"{{""documents"":{{""{ProjectSourceRoot.Replace(@"\", @"\\")}*"":""https://噸.com/test-org/{repoName}/raw/{commitSha}/*""}}}}", | ||
File.ReadAllText(Path.Combine(ProjectDir.Path, s_relativeSourceLinkJsonPath))); | ||
|
||
TestUtilities.ValidateAssemblyInformationalVersion( | ||
Path.Combine(ProjectDir.Path, s_relativeOutputFilePath), | ||
"1.0.0+" + commitSha); | ||
|
||
TestUtilities.ValidateNuSpecRepository( | ||
Path.Combine(ProjectDir.Path, s_relativePackagePath), | ||
type: "git", | ||
commit: commitSha, | ||
url: $"https://噸.com/test-org/{repoName}"); | ||
} | ||
|
||
[ConditionalFact(typeof(DotNetSdkAvailable))] | ||
public void FullValidation_Ssh() | ||
{ | ||
// Test non-ascii characters and escapes in the URL. | ||
// Escaped URI reserved characters should remain escaped, non-reserved characters unescaped in the results. | ||
var repoUrl = "test-user@噸.com:test-org/test-%72epo\u1234%24%2572%2F"; | ||
var repoName = "test-repo\u1234%24%2572%2F"; | ||
|
||
var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); | ||
var commitSha = repo.Head.Tip.Sha; | ||
|
||
VerifyValues( | ||
customProps: @" | ||
<PropertyGroup> | ||
<PublishRepositoryUrl>true</PublishRepositoryUrl> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<SourceLinkGiteeHost Include='噸.com'/> | ||
</ItemGroup> | ||
", | ||
customTargets: "", | ||
targets: new[] | ||
{ | ||
"Build", "Pack" | ||
}, | ||
expressions: new[] | ||
{ | ||
"@(SourceRoot)", | ||
"@(SourceRoot->'%(SourceLinkUrl)')", | ||
"$(SourceLink)", | ||
"$(PrivateRepositoryUrl)", | ||
"$(RepositoryUrl)" | ||
}, | ||
expectedResults: new[] | ||
{ | ||
NuGetPackageFolders, | ||
ProjectSourceRoot, | ||
$"https://噸.com/test-org/{repoName}/raw/{commitSha}/*", | ||
s_relativeSourceLinkJsonPath, | ||
$"https://噸.com/test-org/{repoName}", | ||
$"https://噸.com/test-org/{repoName}" | ||
}); | ||
|
||
AssertEx.AreEqual( | ||
$@"{{""documents"":{{""{ProjectSourceRoot.Replace(@"\", @"\\")}*"":""https://噸.com/test-org/{repoName}/raw/{commitSha}/*""}}}}", | ||
File.ReadAllText(Path.Combine(ProjectDir.Path, s_relativeSourceLinkJsonPath))); | ||
|
||
TestUtilities.ValidateAssemblyInformationalVersion( | ||
Path.Combine(ProjectDir.Path, s_relativeOutputFilePath), | ||
"1.0.0+" + commitSha); | ||
|
||
TestUtilities.ValidateNuSpecRepository( | ||
Path.Combine(ProjectDir.Path, s_relativePackagePath), | ||
type: "git", | ||
commit: commitSha, | ||
url: $"https://噸.com/test-org/{repoName}"); | ||
} | ||
|
||
|
||
[ConditionalFact(typeof(DotNetSdkAvailable))] | ||
public void ImplicitHost() | ||
{ | ||
// Test non-ascii characters and escapes in the URL. | ||
// Escaped URI reserved characters should remain escaped, non-reserved characters unescaped in the results. | ||
var repoUrl = "http://噸.com/test-org/test-%72epo\u1234%24%2572%2F"; | ||
var repoName = "test-repo\u1234%24%2572%2F"; | ||
|
||
var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); | ||
var commitSha = repo.Head.Tip.Sha; | ||
|
||
VerifyValues( | ||
customProps: @" | ||
<PropertyGroup> | ||
<PublishRepositoryUrl>true</PublishRepositoryUrl> | ||
</PropertyGroup> | ||
", | ||
customTargets: "", | ||
targets: new[] | ||
{ | ||
"Build", "Pack" | ||
}, | ||
expressions: new[] | ||
{ | ||
"@(SourceRoot->'%(SourceLinkUrl)')", | ||
"$(PrivateRepositoryUrl)", | ||
"$(RepositoryUrl)" | ||
}, | ||
expectedResults: new[] | ||
{ | ||
$"http://噸.com/test-org/{repoName}/raw/{commitSha}/*", | ||
$"http://噸.com/test-org/{repoName}", | ||
$"http://噸.com/test-org/{repoName}" | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the License.txt file in the project root for more information. | ||
using Microsoft.Build.Tasks.SourceControl; | ||
using TestUtilities; | ||
using Xunit; | ||
using static TestUtilities.KeyValuePairUtils; | ||
|
||
namespace Microsoft.SourceLink.Gitee.UnitTests | ||
{ | ||
public class GetSourceLinkUrlTests | ||
{ | ||
[Fact] | ||
public void EmptyHosts() | ||
{ | ||
var engine = new MockEngine(); | ||
|
||
var task = new GetSourceLinkUrl() | ||
{ | ||
BuildEngine = engine, | ||
SourceRoot = new MockItem("x", KVP("RepositoryUrl", "http://abc.com"), KVP("SourceControl", "git")), | ||
}; | ||
|
||
bool result = task.Execute(); | ||
|
||
AssertEx.AssertEqualToleratingWhitespaceDifferences( | ||
"ERROR : " + string.Format(CommonResources.AtLeastOneRepositoryHostIsRequired, "SourceLinkGiteeHost", "Gitee"), engine.Log); | ||
|
||
Assert.False(result); | ||
} | ||
|
||
[Theory] | ||
[InlineData("", "")] | ||
[InlineData("", "/")] | ||
[InlineData("/", "")] | ||
[InlineData("/", "/")] | ||
public void BuildSourceLinkUrl(string s1, string s2) | ||
{ | ||
var engine = new MockEngine(); | ||
|
||
var task = new GetSourceLinkUrl() | ||
{ | ||
BuildEngine = engine, | ||
SourceRoot = new MockItem("/src/", KVP("RepositoryUrl", "http://subdomain.mygitee.com:100/a/b" + s1), KVP("SourceControl", "git"), KVP("RevisionId", "0123456789abcdefABCDEF000000000000000000")), | ||
Hosts = new[] | ||
{ | ||
new MockItem("mygitee.com", KVP("ContentUrl", "https://domain.com/x/y" + s2)), | ||
} | ||
}; | ||
|
||
bool result = task.Execute(); | ||
AssertEx.AssertEqualToleratingWhitespaceDifferences("", engine.Log); | ||
AssertEx.AreEqual("https://domain.com/x/y/a/b/raw/0123456789abcdefABCDEF000000000000000000/*", task.SourceLinkUrl); | ||
Assert.True(result); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/SourceLink.Gitee.UnitTests/Microsoft.SourceLink.Gitee.UnitTests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the License.txt file in the project root for more information. --> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFrameworks>net472;net7.0</TargetFrameworks> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\SourceLink.Gitee\Microsoft.SourceLink.Gitee.csproj" /> | ||
<ProjectReference Include="..\TestUtilities\TestUtilities.csproj" /> | ||
</ItemGroup> | ||
</Project> |
52 changes: 52 additions & 0 deletions
52
src/SourceLink.Gitee.UnitTests/TranslateRepositoryUrlsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the License.txt file in the project root for more information. | ||
using System.Linq; | ||
using TestUtilities; | ||
using Xunit; | ||
using static TestUtilities.KeyValuePairUtils; | ||
|
||
namespace Microsoft.SourceLink.Gitee.UnitTests | ||
{ | ||
public class TranslateRepositoryUrlsTests | ||
{ | ||
[Fact] | ||
public void Translate() | ||
{ | ||
var engine = new MockEngine(); | ||
|
||
var task = new TranslateRepositoryUrls() | ||
{ | ||
BuildEngine = engine, | ||
RepositoryUrl = "ssh://gitee.com/a/b", | ||
IsSingleProvider = true, | ||
SourceRoots = new[] | ||
{ | ||
new MockItem("/1/", KVP("SourceControl", "git"), KVP("ScmRepositoryUrl", "ssh://gitee.com:22/a/b")), | ||
new MockItem("/2/", KVP("SourceControl", "tfvc"), KVP("ScmRepositoryUrl", "ssh://gitee1.com/a/b")), | ||
new MockItem("/2/", KVP("SourceControl", "git"), KVP("ScmRepositoryUrl", "ssh://gitee1.com/a/b")), | ||
new MockItem("/2/", KVP("SourceControl", "tfvc"), KVP("ScmRepositoryUrl", "ssh://gitee2.com/a/b")), | ||
}, | ||
Hosts = new[] | ||
{ | ||
new MockItem("gitee1.com") | ||
} | ||
}; | ||
|
||
bool result = task.Execute(); | ||
AssertEx.AssertEqualToleratingWhitespaceDifferences("", engine.Log); | ||
|
||
AssertEx.AreEqual("https://gitee.com/a/b", task.TranslatedRepositoryUrl); | ||
|
||
AssertEx.Equal(new[] | ||
{ | ||
"https://gitee.com/a/b", | ||
"ssh://gitee1.com/a/b", | ||
"https://gitee1.com/a/b", | ||
"ssh://gitee2.com/a/b" | ||
}, task.TranslatedSourceRoots?.Select(r => r.GetMetadata("ScmRepositoryUrl"))); | ||
|
||
Assert.True(result); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the License.txt file in the project root for more information. | ||
|
||
using System; | ||
using Microsoft.Build.Framework; | ||
using Microsoft.Build.Tasks.SourceControl; | ||
|
||
namespace Microsoft.SourceLink.Gitee | ||
{ | ||
/// <summary> | ||
/// The task calculates SourceLink URL for a given SourceRoot. | ||
/// If the SourceRoot is associated with a git repository with a recognized domain the <see cref="SourceLinkUrl"/> | ||
/// output property is set to the content URL corresponding to the domain, otherwise it is set to string "N/A". | ||
/// </summary> | ||
public sealed class GetSourceLinkUrl : GetSourceLinkUrlGitTask | ||
{ | ||
protected override string HostsItemGroupName => "SourceLinkGiteeHost"; | ||
protected override string ProviderDisplayName => "Gitee"; | ||
|
||
protected override Uri GetDefaultContentUriFromHostUri(string authority, Uri gitUri) | ||
=> new Uri($"{gitUri.Scheme}://{authority}", UriKind.Absolute); | ||
|
||
protected override string? BuildSourceLinkUrl(Uri contentUri, Uri gitUri, string relativeUrl, string revisionId, ITaskItem? hostItem) | ||
=> UriUtilities.Combine(UriUtilities.Combine(contentUri.ToString(), relativeUrl), "raw/"+ revisionId + "/*"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the License.txt file in the project root for more information. --> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFrameworks>net472;netcoreapp3.1;net7.0</TargetFrameworks> | ||
<TargetFrameworks Condition=" '$(DotNetBuildFromSource)' == 'true' ">net7.0</TargetFrameworks> | ||
<AutoGenerateAssemblyVersion>true</AutoGenerateAssemblyVersion> | ||
|
||
<!-- Using an explicit nuspec file due to https://github.com/NuGet/Home/issues/6754 --> | ||
<IsPackable>true</IsPackable> | ||
<NuspecFile>$(MSBuildProjectName).nuspec</NuspecFile> | ||
<NuspecBasePath>$(OutputPath)</NuspecBasePath> | ||
|
||
<PackageDescription>Generates source link for Gitee repositories.</PackageDescription> | ||
<PackageTags>MSBuild Tasks Gitee source link</PackageTags> | ||
<DevelopmentDependency>true</DevelopmentDependency> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="..\Common\NullableAttributes.cs" Link="Common\NullableAttributes.cs" /> | ||
<Compile Include="..\Common\Names.cs" Link="Common\Names.cs" /> | ||
<Compile Include="..\Common\GetSourceLinkUrlGitTask.cs" Link="Common\GetSourceLinkUrlGitTask.cs" /> | ||
<Compile Include="..\Common\TranslateRepositoryUrlGitTask.cs" Link="Common\TranslateRepositoryUrlGitTask.cs" /> | ||
<Compile Include="..\Common\UriUtilities.cs" Link="Common\UriUtilities.cs" /> | ||
<EmbeddedResource Include="..\Common\CommonResources.resx" Link="Common\CommonResources.resx"> | ||
<Namespace>Microsoft.Build.Tasks.SourceControl</Namespace> | ||
<GenerateSource>true</GenerateSource> | ||
</EmbeddedResource> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Build" Version="$(MicrosoftBuildVersion)" /> | ||
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="$(MicrosoftBuildTasksCore)" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<InternalsVisibleTo Include="Microsoft.SourceLink.Gitee.UnitTests" /> | ||
<InternalsVisibleTo Include="Microsoft.SourceLink.Git.IntegrationTests" /> | ||
</ItemGroup> | ||
</Project> |
Oops, something went wrong.