예제 #1
0
        public void FullValidation_Https(string host)
        {
            // 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://test.{host}/test-org/_git/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)",
                "@(SourceRoot->'%(SourceLinkUrl)')",
                "$(SourceLink)",
                "$(PrivateRepositoryUrl)",
                "$(RepositoryUrl)"
            },
                expectedResults: new[]
            {
                ProjectSourceRoot,
                $"https://test.{host}/test-org/_apis/git/repositories/{repoName}/items?api-version=1.0&versionType=commit&version={commitSha}&path=/*",
                s_relativeSourceLinkJsonPath,
                $"https://test.{host}/test-org/_git/{repoName}",
                $"https://test.{host}/test-org/_git/{repoName}",
            });

            AssertEx.AreEqual(
                $@"{{""documents"":{{""{ProjectSourceRoot.Replace(@"\", @"\\")}*"":""https://test.{host}/test-org/_apis/git/repositories/{repoName}/items?api-version=1.0&versionType=commit&version={commitSha}&path=/*""}}}}",
                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://test.{host}/test-org/_git/{repoName}");
        }
        public void FullValidation_Ssh()
        {
            var repo      = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, "[email protected]:test-org/test-repo");
            var commitSha = repo.Head.Tip.Sha;

            VerifyValues(
                customProps: @"
<PropertyGroup>
  <PublishRepositoryUrl>true</PublishRepositoryUrl>
</PropertyGroup>
<ItemGroup>
  <SourceLinkBitBucketGitHost Include='cloudbitbucket.com'/>
</ItemGroup>
",
                customTargets: "",
                targets: new[]
            {
                "Build", "Pack"
            },
                expressions: new[]
            {
                "@(SourceRoot)",
                "@(SourceRoot->'%(SourceLinkUrl)')",
                "$(SourceLink)",
                "$(PrivateRepositoryUrl)",
                "$(RepositoryUrl)"
            },
                expectedResults: new[]
            {
                ProjectSourceRoot,
                $"https://cloudbitbucket.com/test-org/test-repo/raw/{commitSha}/*",
                s_relativeSourceLinkJsonPath,
                "https://cloudbitbucket.com/test-org/test-repo",
                "https://cloudbitbucket.com/test-org/test-repo"
            });

            AssertEx.AreEqual(
                $@"{{""documents"":{{""{ProjectSourceRoot.Replace(@"\", @"\\")}*"":""https://cloudbitbucket.com/test-org/test-repo/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://cloudbitbucket.com/test-org/test-repo");
        }
예제 #3
0
        public void FullValidation_Ssh()
        {
            var repo      = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, "ssh://tfs.mydomain.local:22/tfs/DefaultCollection/project/_ssh/MyProject");
            var commitSha = repo.Head.Tip.Sha;

            VerifyValues(
                customProps: @"
<PropertyGroup>
  <PublishRepositoryUrl>true</PublishRepositoryUrl>
</PropertyGroup>
<ItemGroup>
  <SourceLinkTfsGitHost Include=""tfs.mydomain.local"" VirtualDirectory=""tfs""/>
</ItemGroup>
",
                customTargets: "",
                targets: new[]
            {
                "Build", "Pack"
            },
                expressions: new[]
            {
                "@(SourceRoot)",
                "@(SourceRoot->'%(SourceLinkUrl)')",
                "$(SourceLink)",
                "$(PrivateRepositoryUrl)",
                "$(RepositoryUrl)"
            },
                expectedResults: new[]
            {
                ProjectSourceRoot,
                $"https://tfs.mydomain.local/tfs/DefaultCollection/project/_apis/git/repositories/MyProject/items?api-version=1.0&versionType=commit&version={commitSha}&path=/*",
                s_relativeSourceLinkJsonPath,
                "https://tfs.mydomain.local/tfs/DefaultCollection/project/_git/MyProject",
                "https://tfs.mydomain.local/tfs/DefaultCollection/project/_git/MyProject",
            });

            AssertEx.AreEqual(
                $@"{{""documents"":{{""{ProjectSourceRoot.Replace(@"\", @"\\")}*"":""https://tfs.mydomain.local/tfs/DefaultCollection/project/_apis/git/repositories/MyProject/items?api-version=1.0&versionType=commit&version={commitSha}&path=/*""}}}}",
                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://tfs.mydomain.local/tfs/DefaultCollection/project/_git/MyProject");
        }
예제 #4
0
        public void FullValidation_Ssh(string host)
        {
            var repo      = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, $"ssh://test@vs-ssh.{host}:22/test-org/_ssh/test-repo");
            var commitSha = repo.Head.Tip.Sha;

            VerifyValues(
                customProps: @"
<PropertyGroup>
  <PublishRepositoryUrl>true</PublishRepositoryUrl>
</PropertyGroup>
",
                customTargets: "",
                targets: new[]
            {
                "Build", "Pack"
            },
                expressions: new[]
            {
                "@(SourceRoot)",
                "@(SourceRoot->'%(SourceLinkUrl)')",
                "$(SourceLink)",
                "$(PrivateRepositoryUrl)",
                "$(RepositoryUrl)"
            },
                expectedResults: new[]
            {
                ProjectSourceRoot,
                $"https://test.{host}/test-org/_apis/git/repositories/test-repo/items?api-version=1.0&versionType=commit&version={commitSha}&path=/*",
                s_relativeSourceLinkJsonPath,
                $"https://test.{host}/test-org/_git/test-repo",
                $"https://test.{host}/test-org/_git/test-repo",
            });

            AssertEx.AreEqual(
                $@"{{""documents"":{{""{ProjectSourceRoot.Replace(@"\", @"\\")}*"":""https://test.{host}/test-org/_apis/git/repositories/test-repo/items?api-version=1.0&versionType=commit&version={commitSha}&path=/*""}}}}",
                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://test.{host}/test-org/_git/test-repo");
        }
예제 #5
0
        public void GenerateSourceLinkFileTarget_EnableSourceLinkCondition()
        {
            GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, "http://github.com/test-org/test-repo");

            VerifyValues(
                customProps: @"
<PropertyGroup>
  <Test_DefaultEnableSourceControlManagerQueries>$(EnableSourceControlManagerQueries)</Test_DefaultEnableSourceControlManagerQueries>
  <Test_DefaultEnableSourceLink>$(EnableSourceLink)</Test_DefaultEnableSourceLink>
</PropertyGroup>

",
                customTargets: @"
<Target Name=""Test_SetEnableSourceLink"" BeforeTargets=""InitializeSourceControlInformation"">
  <PropertyGroup>
    <EnableSourceLink>false</EnableSourceLink>
  </PropertyGroup>
</Target>
",
                targets: new[]
            {
                "Build"
            },
                expressions: new[]
            {
                "@(SourceRoot)",
                "$(Test_DefaultEnableSourceControlManagerQueries)",
                "$(Test_DefaultEnableSourceLink)",
                "$(SourceLink)"
            },
                expectedResults: new[]
            {
                NuGetPackageFolders,
                ProjectSourceRoot,
                "true",
                "true",
                ""
            });
        }
        public void Host_VisualStudio(string host)
        {
            // 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://test.{host}/test-org/_git/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)",
                "@(SourceRoot->'%(SourceLinkUrl)')",
                "$(SourceLink)",
                "$(PrivateRepositoryUrl)",
                "$(RepositoryUrl)"
            },
                expectedResults: new[]
            {
                NuGetPackageFolders,
                ProjectSourceRoot,
                $"https://test.{host}/test-org/_apis/git/repositories/{repoName}/items?api-version=1.0&versionType=commit&version={commitSha}&path=/*",
                s_relativeSourceLinkJsonPath,
                $"https://test.{host}/test-org/_git/{repoName}",
                $"https://test.{host}/test-org/_git/{repoName}",
            });
        }
예제 #7
0
        public void CustomTranslation()
        {
            // 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  = "ssh://[email protected]:22/test-org/_ssh/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: @"
<Target Name=""TranslateVstsToGitHub""
        DependsOnTargets=""$(SourceControlManagerUrlTranslationTargets)""
        BeforeTargets=""SourceControlManagerPublishTranslatedUrls"">

    <PropertyGroup>
      <_Pattern>https://([^.]+)[.]visualstudio.com/([^/]+)/_git/([^/]+)</_Pattern>
      <_Replacement>https://github.com/$2/$3</_Replacement>
    </PropertyGroup>

    <PropertyGroup>
      <ScmRepositoryUrl>$([System.Text.RegularExpressions.Regex]::Replace($(ScmRepositoryUrl), $(_Pattern), $(_Replacement)))</ScmRepositoryUrl>
    </PropertyGroup>

    <ItemGroup>
      <SourceRoot Update=""@(SourceRoot)"">
        <ScmRepositoryUrl>$([System.Text.RegularExpressions.Regex]::Replace(%(SourceRoot.ScmRepositoryUrl), $(_Pattern), $(_Replacement)))</ScmRepositoryUrl>
      </SourceRoot>
    </ItemGroup>
  </Target>
",
                targets: new[]
            {
                "Build", "Pack"
            },
                expressions: new[]
            {
                "@(SourceRoot)",
                "@(SourceRoot->'%(SourceLinkUrl)')",
                "$(SourceLink)",
                "$(PrivateRepositoryUrl)",
                "$(RepositoryUrl)"
            },
                expectedResults: new[]
            {
                ProjectSourceRoot,
                $"https://raw.githubusercontent.com/test-org/{repoName}/{commitSha}/*",
                s_relativeSourceLinkJsonPath,
                $"https://github.com/test-org/{repoName}",
                $"https://github.com/test-org/{repoName}",
            });

            AssertEx.AreEqual(
                $@"{{""documents"":{{""{ProjectSourceRoot.Replace(@"\", @"\\")}*"":""https://raw.githubusercontent.com/test-org/{repoName}/{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://github.com/test-org/{repoName}");
        }