コード例 #1
0
ファイル: GitHubTests.cs プロジェクト: slamj1/sourcelink-1
        public void Environment_Disabled()
        {
            var repo      = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, "http://github.com/test-org/test-repo1");
            var commitSha = repo.Head.Tip.Sha;

            PrepareTestEnvironment();

            VerifyValues(
                customProps: $@"
<PropertyGroup>
  <ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
  <GitRepositoryRemoteName>origin2</GitRepositoryRemoteName>
</PropertyGroup>
",
                customTargets: "",
                targets: new[]
            {
                "Build"
            },
                expressions: new[]
            {
                "@(SourceRoot->'%(SourceLinkUrl)')",
                "$(PrivateRepositoryUrl)",
            },
                expectedResults: new[]
            {
                $"https://raw.githubusercontent.com/test-org/test-repo1/{commitSha}/*",
                $"http://github.com/test-org/test-repo1",
            },
                expectedWarnings: new[]
            {
                string.Format(Resources.RepositoryDoesNotHaveSpecifiedRemote, ProjectDir.Path, "origin2", "origin")
            });
        }
コード例 #2
0
        public void Host_Unknown()
        {
            var repoUrl = $"https://contoso.com/test/test-org/_git/test-repo";

            GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, repoUrl);

            VerifyValues(
                customProps: "",
                customTargets: "",
                targets: new[]
            {
                "Build", "Pack"
            },
                expressions: new[]
            {
                "@(SourceRoot->'%(SourceLinkUrl)')",
            },
                expectedResults: new[]
            {
                "",
            },
                expectedWarnings: new[]
            {
                string.Format(Resources.SourceControlInformationIsNotAvailableGeneratedSourceLinkEmpty)
            });
        }
コード例 #3
0
        public void ImplicitHost()
        {
            var repo      = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, "http://mygitlab.com/test-org/test-repo");
            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://mygitlab.com/test-org/test-repo/raw/{commitSha}/*",
                "http://mygitlab.com/test-org/test-repo",
                "http://mygitlab.com/test-org/test-repo"
            });
        }
コード例 #4
0
        public void DefaultValuesForEnableProperties_BuildingForLiveUnitTesting()
        {
            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: "",
                targets: new[]
            {
                "Build"
            },
                expressions: new[]
            {
                "@(SourceRoot)",
                "$(Test_DefaultEnableSourceControlManagerQueries)",
                "$(Test_DefaultEnableSourceLink)",
                "$(SourceLink)"
            },
                expectedResults: new[]
            {
                "",
                "",
                "",
                ""
            },
                additionalCommandLineArgs: "/p:BuildingForLiveUnitTesting=true");
        }
コード例 #5
0
        public void Issues_error_on_git_url()
        {
            var repoUrl   = "git://噸.com/invalid_url_protocol.git";
            var repo      = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, repoUrl);
            var commitSha = repo.Head.Tip.Sha;

            VerifyValues(
                customProps: @"
<PropertyGroup>
  <PublishRepositoryUrl>true</PublishRepositoryUrl>
</PropertyGroup>
<ItemGroup>
  <SourceLinkGitWebHost Include='噸.com' ContentUrl='https://噸.com/gitweb'/>
</ItemGroup>
",
                customTargets: "",
                targets: new[]
            {
                "Build", "Pack"
            },
                expressions: Array.Empty <string>(),
                expectedErrors: new[] {
                string.Format(GitWeb.Resources.RepositoryUrlIsNotSupportedByProvider, "GIT")
            });
        }
コード例 #6
0
        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/commit/{commitSha}/*",
                $"http://噸.com/test-org/{repoName}",
                $"http://噸.com/test-org/{repoName}"
            });
        }
コード例 #7
0
        public void FullValidation_EnterpriseNewHttps()
        {
            // 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://bitbucket.domain.com/scm/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>
  <SourceLinkBitbucketGitHost Include=""bitbucket.domain.com"" EnterpriseEdition=""true"" Version=""4.7""/>
</ItemGroup>
",
                customTargets: "",
                targets: new[]
            {
                "Build", "Pack"
            },
                expressions: new[]
            {
                "@(SourceRoot)",
                "@(SourceRoot->'%(SourceLinkUrl)')",
                "$(SourceLink)",
                "$(PrivateRepositoryUrl)",
                "$(RepositoryUrl)"
            },
                expectedResults: new[]
            {
                NuGetPackageFolders,
                ProjectSourceRoot,
                $"https://bitbucket.domain.com/projects/test-org/repos/{repoName}/raw/*?at={commitSha}",
                s_relativeSourceLinkJsonPath,
                $"https://bitbucket.domain.com/scm/test-org/{repoName}",
                $"https://bitbucket.domain.com/scm/test-org/{repoName}"
            });

            AssertEx.AreEqual(
                $@"{{""documents"":{{""{ProjectSourceRoot.Replace(@"\", @"\\")}*"":""https://bitbucket.domain.com/projects/test-org/repos/{repoName}/raw/*?at={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://bitbucket.domain.com/scm/test-org/{repoName}");
        }
コード例 #8
0
        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  = "ssh://tfs.噸.local:22/tfs/DefaultCollection/project/_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>
<ItemGroup>
  <SourceLinkAzureDevOpsServerGitHost Include=""tfs.噸.local"" VirtualDirectory=""tfs""/>
</ItemGroup>
",
                customTargets: "",
                targets: new[]
            {
                "Build", "Pack"
            },
                expressions: new[]
            {
                "@(SourceRoot)",
                "@(SourceRoot->'%(SourceLinkUrl)')",
                "$(SourceLink)",
                "$(PrivateRepositoryUrl)",
                "$(RepositoryUrl)"
            },
                expectedResults: new[]
            {
                NuGetPackageFolders,
                ProjectSourceRoot,
                $"https://tfs.噸.local/tfs/DefaultCollection/project/_apis/git/repositories/{repoName}/items?api-version=1.0&versionType=commit&version={commitSha}&path=/*",
                s_relativeSourceLinkJsonPath,
                $"https://tfs.噸.local/tfs/DefaultCollection/project/_git/{repoName}",
                $"https://tfs.噸.local/tfs/DefaultCollection/project/_git/{repoName}",
            });

            AssertEx.AreEqual(
                $@"{{""documents"":{{""{ProjectSourceRoot.Replace(@"\", @"\\")}*"":""https://tfs.噸.local/tfs/DefaultCollection/project/_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://tfs.噸.local/tfs/DefaultCollection/project/_git/{repoName}");
        }
コード例 #9
0
        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  = $"ssh://git@噸.com/test-%72epo\u1234%24%2572%2F.git";
            var repoName = "test-repo\u1234%24%2572%2F.git";

            var repo      = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, repoUrl);
            var commitSha = repo.Head.Tip.Sha;

            VerifyValues(
                customProps: @"
<PropertyGroup>
  <PublishRepositoryUrl>true</PublishRepositoryUrl>
</PropertyGroup>
<ItemGroup>
  <SourceLinkGitWebHost Include='噸.com' ContentUrl='https://噸.com/gitweb'/>
</ItemGroup>
",
                customTargets: "",
                targets: new[]
            {
                "Build", "Pack"
            },
                expressions: new[]
            {
                "@(SourceRoot)",
                "@(SourceRoot->'%(SourceLinkUrl)')",
                "$(SourceLink)",
                "$(PrivateRepositoryUrl)",
                "$(RepositoryUrl)"
            },
                expectedResults: new[]
            {
                NuGetPackageFolders,
                ProjectSourceRoot,
                $"https://噸.com/gitweb/?p={repoName};a=blob_plain;hb={commitSha};f=*",
                s_relativeSourceLinkJsonPath,
                $"ssh://git@噸.com/{repoName}",
                $"ssh://git@噸.com/{repoName}"
            });

            AssertEx.AreEqual(
                $@"{{""documents"":{{""{ProjectSourceRoot.Replace(@"\", @"\\")}*"":""https://噸.com/gitweb/?p={repoName};a=blob_plain;hb={commitSha};f=*""}}}}",
                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: $"ssh://git@噸.com/{repoName}");
        }
コード例 #10
0
        public void MutlipleProjects()
        {
            var projectName2     = "Project2";
            var projectFileName2 = projectName2 + ".csproj";

            var project2 = RootDir.CreateDirectory(projectName2).CreateFile(projectFileName2).WriteAllText(@"
<Project Sdk='Microsoft.NET.Sdk'>
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>
</Project>
");

            using var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(
                      RootDir.Path,
                      new[] { Path.Combine(ProjectName, ProjectFileName), Path.Combine(projectName2, projectFileName2) },
                      "http://github.com/test-org/test-repo1");

            repo.Network.Remotes.Add("origin2", "http://github.com/test-org/test-repo2");

            var commitSha = repo.Head.Tip.Sha;

            VerifyValues(
                customProps: $@"
<ItemGroup>
  <ProjectReference Include='{project2.Path}'/>
</ItemGroup>
<PropertyGroup>
  <GitRepositoryRemoteName>origin2</GitRepositoryRemoteName>
</PropertyGroup>
",
                customTargets: "",
                targets: new[]
            {
                "Build"
            },
                expressions: new[]
            {
                "@(SourceRoot)",
                "@(SourceRoot->'%(SourceLinkUrl)')",
                "$(SourceLink)",
                "$(PrivateRepositoryUrl)",
            },
                expectedResults: new[]
            {
                NuGetPackageFolders,
                SourceRoot,
                $"https://raw.githubusercontent.com/test-org/test-repo2/{commitSha}/*",
                s_relativeSourceLinkJsonPath,
                $"http://github.com/test-org/test-repo2",
            },
                // the second project should reuse the repository info cached by the first project:
                buildVerbosity: "detailed",
                expectedBuildOutputFilter: line => line.Contains("SourceLink: Reusing cached git repository information."));
        }
コード例 #11
0
        public void FullValidation_EnterpriseNewHttps_UrlWithPersonalToken()
        {
            var repoUrl  = "https://user_name%40domain.com:[email protected]/scm/test-org/project1.git";
            var repoName = "project1";

            var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName },
                                                                        repoUrl);
            var commitSha = repo.Head.Tip.Sha;

            VerifyValues(
                customProps: @"
<PropertyGroup>
  <PublishRepositoryUrl>true</PublishRepositoryUrl>
</PropertyGroup>
<ItemGroup>
  <SourceLinkBitbucketGitHost Include=""bitbucket.domain.com"" EnterpriseEdition=""true"" Version=""4.7""/>
</ItemGroup>
",
                customTargets: "",
                targets: new[]
            {
                "Build", "Pack"
            },
                expressions: new[]
            {
                "@(SourceRoot)",
                "@(SourceRoot->'%(SourceLinkUrl)')",
                "$(SourceLink)",
                "$(PrivateRepositoryUrl)",
                "$(RepositoryUrl)"
            },
                expectedResults: new[]
            {
                ProjectSourceRoot,
                $"https://bitbucket.domain.com/projects/test-org/repos/{repoName}/raw/*?at={commitSha}",
                s_relativeSourceLinkJsonPath,
                $"https://bitbucket.domain.com/scm/test-org/{repoName}.git",
                $"https://bitbucket.domain.com/scm/test-org/{repoName}.git"
            });

            AssertEx.AreEqual(
                $@"{{""documents"":{{""{ProjectSourceRoot.Replace(@"\", @"\\")}*"":""https://bitbucket.domain.com/projects/test-org/repos/{repoName}/raw/*?at={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://bitbucket.domain.com/scm/test-org/{repoName}.git");
        }
コード例 #12
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");
        }
コード例 #13
0
        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");
        }
コード例 #14
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");
        }
コード例 #15
0
        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}",
            });
        }
コード例 #16
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",
                ""
            });
        }
コード例 #17
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}");
        }