protected ISourceProvider GetSourceProvider(string repositoryType) { ISourceProvider sourceProvider = null; switch (repositoryType) { case RepositoryTypes.Bitbucket: case RepositoryTypes.GitHub: case RepositoryTypes.GitHubEnterprise: sourceProvider = new AuthenticatedGitSourceProvider(); break; case RepositoryTypes.Git: sourceProvider = new ExternalGitSourceProvider(); break; case RepositoryTypes.TfsGit: sourceProvider = new TfsGitSourceProvider(); break; case RepositoryTypes.TfsVersionControl: sourceProvider = new TfsVCSourceProvider(); break; case RepositoryTypes.Svn: sourceProvider = new SvnSourceProvider(); break; default: throw new NotSupportedException(repositoryType); } return(sourceProvider); }
public void GetSourceGitClone() { using (TestHostContext tc = new TestHostContext(this)) { // Arrange. string dumySourceFolder = Path.Combine(tc.GetDirectory(WellKnownDirectory.Bin), "SourceProviderL0"); var executionContext = GetTestExecutionContext(tc, dumySourceFolder, "master", "a596e13f5db8869f44574be0392fb8fe1e790ce4", false); var endpoint = GetTestSourceEndpoint("https://github.com/microsoft/azure-pipelines-agent", false, false); var _gitCommandManager = GetDefaultGitCommandMock(); tc.SetSingleton <IGitCommandManager>(_gitCommandManager.Object); tc.SetSingleton <IVstsAgentWebProxy>(new VstsAgentWebProxy()); var _configStore = new Mock <IConfigurationStore>(); _configStore.Setup(x => x.GetSettings()).Returns(() => new AgentSettings() { ServerUrl = "http://localhost:8080/tfs" }); tc.SetSingleton <IConfigurationStore>(_configStore.Object); tc.SetSingleton <IAgentCertificateManager>(new AgentCertificateManager()); GitSourceProvider gitSourceProvider = new ExternalGitSourceProvider(); gitSourceProvider.Initialize(tc); gitSourceProvider.SetVariablesInEndpoint(executionContext.Object, endpoint); // Act. gitSourceProvider.GetSourceAsync(executionContext.Object, endpoint, default(CancellationToken)).GetAwaiter().GetResult(); // Assert. _gitCommandManager.Verify(x => x.GitInit(executionContext.Object, dumySourceFolder)); _gitCommandManager.Verify(x => x.GitRemoteAdd(executionContext.Object, dumySourceFolder, "origin", "https://github.com/microsoft/azure-pipelines-agent")); _gitCommandManager.Verify(x => x.GitRemoteSetUrl(executionContext.Object, dumySourceFolder, "origin", "https://github.com/microsoft/azure-pipelines-agent")); _gitCommandManager.Verify(x => x.GitRemoteSetPushUrl(executionContext.Object, dumySourceFolder, "origin", "https://github.com/microsoft/azure-pipelines-agent")); _gitCommandManager.Verify(x => x.GitCheckout(executionContext.Object, dumySourceFolder, "a596e13f5db8869f44574be0392fb8fe1e790ce4", It.IsAny <CancellationToken>())); } }
public ISourceProvider GetSourceProvider(string repositoryType) { ISourceProvider sourceProvider = null; if (string.Equals(repositoryType, Pipelines.RepositoryTypes.Bitbucket, StringComparison.OrdinalIgnoreCase) || string.Equals(repositoryType, Pipelines.RepositoryTypes.GitHub, StringComparison.OrdinalIgnoreCase) || string.Equals(repositoryType, Pipelines.RepositoryTypes.GitHubEnterprise, StringComparison.OrdinalIgnoreCase)) { sourceProvider = new AuthenticatedGitSourceProvider(); } else if (string.Equals(repositoryType, Pipelines.RepositoryTypes.ExternalGit, StringComparison.OrdinalIgnoreCase)) { sourceProvider = new ExternalGitSourceProvider(); } else if (string.Equals(repositoryType, Pipelines.RepositoryTypes.Git, StringComparison.OrdinalIgnoreCase)) { sourceProvider = new TfsGitSourceProvider(); } else if (string.Equals(repositoryType, Pipelines.RepositoryTypes.Tfvc, StringComparison.OrdinalIgnoreCase)) { sourceProvider = new TfsVCSourceProvider(); } else if (string.Equals(repositoryType, Pipelines.RepositoryTypes.Svn, StringComparison.OrdinalIgnoreCase)) { sourceProvider = new SvnSourceProvider(); } else { throw new NotSupportedException(repositoryType); } return(sourceProvider); }
public void GetSourceGitClone() { using (TestHostContext tc = new TestHostContext(this)) { // Arrange. string dumySourceFolder = Path.Combine(IOUtil.GetBinPath(), "SourceProviderL0"); var executionContext = GetTestExecutionContext(tc, dumySourceFolder, "master", "a596e13f5db8869f44574be0392fb8fe1e790ce4", false); var endpoint = GetTestSourceEndpoint("https://github.com/Microsoft/vsts-agent", false, false); var _gitCommandManager = GetDefaultGitCommandMock(); tc.SetSingleton <IGitCommandManager>(_gitCommandManager.Object); tc.SetSingleton <IWhichUtil>(new WhichUtil()); tc.SetSingleton <IVstsAgentWebProxy>(new VstsAgentWebProxy()); GitSourceProvider gitSourceProvider = new ExternalGitSourceProvider(); gitSourceProvider.Initialize(tc); gitSourceProvider.SetVariablesInEndpoint(executionContext.Object, endpoint); // Act. gitSourceProvider.GetSourceAsync(executionContext.Object, endpoint, default(CancellationToken)).GetAwaiter().GetResult(); // Assert. _gitCommandManager.Verify(x => x.GitInit(executionContext.Object, dumySourceFolder)); _gitCommandManager.Verify(x => x.GitRemoteAdd(executionContext.Object, dumySourceFolder, "origin", "https://github.com/Microsoft/vsts-agent")); _gitCommandManager.Verify(x => x.GitRemoteSetUrl(executionContext.Object, dumySourceFolder, "origin", "https://github.com/Microsoft/vsts-agent")); _gitCommandManager.Verify(x => x.GitRemoteSetPushUrl(executionContext.Object, dumySourceFolder, "origin", "https://github.com/Microsoft/vsts-agent")); _gitCommandManager.Verify(x => x.GitCheckout(executionContext.Object, dumySourceFolder, "a596e13f5db8869f44574be0392fb8fe1e790ce4", It.IsAny <CancellationToken>())); } }
public void GetSourceGitClonePR() { using (TestHostContext tc = new TestHostContext(this)) { var trace = tc.GetTrace(); // Arrange. string dumySourceFolder = Path.Combine(IOUtil.GetBinPath(), "SourceProviderL0"); var executionContext = GetTestExecutionContext(tc, dumySourceFolder, "refs/pull/12345", "a596e13f5db8869f44574be0392fb8fe1e790ce4", false); var endpoint = GetTestSourceEndpoint("https://github.com/Microsoft/vsts-agent", false, false); var _gitCommandManager = GetDefaultGitCommandMock(); tc.SetSingleton <IGitCommandManager>(_gitCommandManager.Object); tc.SetSingleton <IWhichUtil>(new WhichUtil()); GitSourceProvider gitSourceProvider = new ExternalGitSourceProvider(); gitSourceProvider.Initialize(tc); gitSourceProvider.SetVariablesInEndpoint(executionContext.Object, endpoint); // Act. gitSourceProvider.GetSourceAsync(executionContext.Object, endpoint, default(CancellationToken)).GetAwaiter().GetResult(); // Assert. _gitCommandManager.Verify(x => x.GitInit(executionContext.Object, dumySourceFolder)); _gitCommandManager.Verify(x => x.GitRemoteAdd(executionContext.Object, dumySourceFolder, "origin", "https://github.com/Microsoft/vsts-agent")); _gitCommandManager.Verify(x => x.GitFetch(executionContext.Object, dumySourceFolder, "origin", It.IsAny <int>(), new List <string>() { "+refs/heads/*:refs/remotes/origin/*", "+refs/pull/12345:refs/remotes/pull/12345" }, It.IsAny <string>(), It.IsAny <CancellationToken>())); _gitCommandManager.Verify(x => x.GitRemoteSetUrl(executionContext.Object, dumySourceFolder, "origin", "https://github.com/Microsoft/vsts-agent")); _gitCommandManager.Verify(x => x.GitRemoteSetPushUrl(executionContext.Object, dumySourceFolder, "origin", "https://github.com/Microsoft/vsts-agent")); _gitCommandManager.Verify(x => x.GitCheckout(executionContext.Object, dumySourceFolder, It.Is <string>(s => s.Equals("refs/remotes/pull/12345")), It.IsAny <CancellationToken>())); } }
public void GetSourceGitFetchPR() { using (TestHostContext tc = new TestHostContext(this)) { var trace = tc.GetTrace(); // Arrange. string dumySourceFolder = Path.Combine(tc.GetDirectory(WellKnownDirectory.Bin), "SourceProviderL0"); try { Directory.CreateDirectory(dumySourceFolder); string dumyGitFolder = Path.Combine(dumySourceFolder, ".git"); Directory.CreateDirectory(dumyGitFolder); string dumyGitConfig = Path.Combine(dumyGitFolder, "config"); File.WriteAllText(dumyGitConfig, "test git confg file"); var executionContext = GetTestExecutionContext(tc, dumySourceFolder, "refs/pull/12345/merge", "a596e13f5db8869f44574be0392fb8fe1e790ce4", false); var endpoint = GetTestSourceEndpoint("https://github.com/Microsoft/vsts-agent", false, false); var _gitCommandManager = GetDefaultGitCommandMock(); tc.SetSingleton <IGitCommandManager>(_gitCommandManager.Object); tc.SetSingleton <IWhichUtil>(new WhichUtil()); tc.SetSingleton <IVstsAgentWebProxy>(new VstsAgentWebProxy()); var _configStore = new Mock <IConfigurationStore>(); _configStore.Setup(x => x.GetSettings()).Returns(() => new AgentSettings() { ServerUrl = "http://*****:*****@github.com/Microsoft/vsts-agent")); _gitCommandManager.Verify(x => x.GitRemoteSetPushUrl(executionContext.Object, dumySourceFolder, "origin", "https://*****:*****@github.com/Microsoft/vsts-agent")); _gitCommandManager.Verify(x => x.GitFetch(executionContext.Object, dumySourceFolder, "origin", It.IsAny <int>(), new List <string>() { "+refs/heads/*:refs/remotes/origin/*", "+refs/pull/12345/merge:refs/remotes/pull/12345/merge" }, It.IsAny <string>(), It.IsAny <CancellationToken>())); _gitCommandManager.Verify(x => x.GitRemoteSetUrl(executionContext.Object, dumySourceFolder, "origin", "https://github.com/Microsoft/vsts-agent")); _gitCommandManager.Verify(x => x.GitRemoteSetPushUrl(executionContext.Object, dumySourceFolder, "origin", "https://github.com/Microsoft/vsts-agent")); _gitCommandManager.Verify(x => x.GitCheckout(executionContext.Object, dumySourceFolder, "refs/remotes/pull/12345/merge", It.IsAny <CancellationToken>())); } finally { IOUtil.DeleteDirectory(dumySourceFolder, CancellationToken.None); } } }
public void GetSourceReCloneOnUrlNotMatch() { using (TestHostContext tc = new TestHostContext(this)) { var trace = tc.GetTrace(); // Arrange. string dumySourceFolder = Path.Combine(tc.GetDirectory(WellKnownDirectory.Bin), "SourceProviderL0"); try { Directory.CreateDirectory(dumySourceFolder); string dumyGitFolder = Path.Combine(dumySourceFolder, ".git"); Directory.CreateDirectory(dumyGitFolder); string dumyGitConfig = Path.Combine(dumyGitFolder, "config"); File.WriteAllText(dumyGitConfig, "test git confg file"); var executionContext = GetTestExecutionContext(tc, dumySourceFolder, "refs/heads/users/user1", "", true); var endpoint = GetTestSourceEndpoint("https://github.com/Microsoft/vsts-agent", false, false); var _gitCommandManager = GetDefaultGitCommandMock(); _gitCommandManager .Setup(x => x.GitGetFetchUrl(It.IsAny <IExecutionContext>(), It.IsAny <string>())) .Returns(Task.FromResult <Uri>(new Uri("https://github.com/Microsoft/vsts-another-agent"))); tc.SetSingleton <IGitCommandManager>(_gitCommandManager.Object); tc.SetSingleton <IWhichUtil>(new WhichUtil()); tc.SetSingleton <IVstsAgentWebProxy>(new VstsAgentWebProxy()); var _configStore = new Mock <IConfigurationStore>(); _configStore.Setup(x => x.GetSettings()).Returns(() => new AgentSettings() { ServerUrl = "http://localhost:8080/tfs" }); tc.SetSingleton <IConfigurationStore>(_configStore.Object); tc.SetSingleton <IAgentCertificateManager>(new AgentCertificateManager()); GitSourceProvider gitSourceProvider = new ExternalGitSourceProvider(); gitSourceProvider.Initialize(tc); gitSourceProvider.SetVariablesInEndpoint(executionContext.Object, endpoint); // Act. gitSourceProvider.GetSourceAsync(executionContext.Object, endpoint, default(CancellationToken)).GetAwaiter().GetResult(); // Assert. _gitCommandManager.Verify(x => x.GitInit(executionContext.Object, dumySourceFolder)); _gitCommandManager.Verify(x => x.GitRemoteAdd(executionContext.Object, dumySourceFolder, "origin", "https://github.com/Microsoft/vsts-agent")); _gitCommandManager.Verify(x => x.GitCheckout(executionContext.Object, dumySourceFolder, "refs/remotes/origin/users/user1", It.IsAny <CancellationToken>())); } finally { IOUtil.DeleteDirectory(dumySourceFolder, CancellationToken.None); } } }
public void GetSourcePreferFeatureVariables() { using (TestHostContext tc = new TestHostContext(this)) { var trace = tc.GetTrace(); // Arrange. string dumySourceFolder = Path.Combine(tc.GetDirectory(WellKnownDirectory.Bin), "SourceProviderL0"); try { Directory.CreateDirectory(dumySourceFolder); var executionContext = GetTestExecutionContext(tc, dumySourceFolder, "refs/remotes/origin/master", "", false); executionContext.Object.Variables.Set("agent.source.git.lfs", "true"); executionContext.Object.Variables.Set("agent.source.git.shallowFetchDepth", "10"); var endpoint = GetTestSourceEndpoint("https://github.com/Microsoft/vsts-agent", false, false, false, 0); var _gitCommandManager = GetDefaultGitCommandMock(); tc.SetSingleton <IGitCommandManager>(_gitCommandManager.Object); tc.SetSingleton <IWhichUtil>(new WhichUtil()); tc.SetSingleton <IVstsAgentWebProxy>(new VstsAgentWebProxy()); var _configStore = new Mock <IConfigurationStore>(); _configStore.Setup(x => x.GetSettings()).Returns(() => new AgentSettings() { ServerUrl = "http://*****:*****@github.com/Microsoft/vsts-agent.git/info/lfs")); _gitCommandManager.Verify(x => x.GitConfig(executionContext.Object, dumySourceFolder, "remote.origin.lfspushurl", "https://*****:*****@github.com/Microsoft/vsts-agent.git/info/lfs")); _gitCommandManager.Verify(x => x.GitLFSFetch(executionContext.Object, dumySourceFolder, "origin", It.IsAny <string>(), It.IsAny <string>(), It.IsAny <CancellationToken>())); _gitCommandManager.Verify(x => x.GitFetch(executionContext.Object, dumySourceFolder, "origin", 10, It.IsAny <List <string> >(), It.IsAny <string>(), It.IsAny <CancellationToken>())); _gitCommandManager.Verify(x => x.GitCheckout(executionContext.Object, dumySourceFolder, "refs/remotes/origin/master", It.IsAny <CancellationToken>())); } finally { IOUtil.DeleteDirectory(dumySourceFolder, CancellationToken.None); } } }
public void GetSourceGitFetchWithClean() { using (TestHostContext tc = new TestHostContext(this)) { var trace = tc.GetTrace(); // Arrange. string dumySourceFolder = Path.Combine(IOUtil.GetBinPath(), "SourceProviderL0"); try { Directory.CreateDirectory(dumySourceFolder); string dumyGitFolder = Path.Combine(dumySourceFolder, ".git"); Directory.CreateDirectory(dumyGitFolder); string dumyGitConfig = Path.Combine(dumyGitFolder, "config"); File.WriteAllText(dumyGitConfig, "test git confg file"); var executionContext = GetTestExecutionContext(tc, dumySourceFolder, "refs/remotes/origin/master", "", false); var endpoint = GetTestSourceEndpoint("https://github.com/Microsoft/vsts-agent", true, false); var _gitCommandManager = GetDefaultGitCommandMock(); tc.SetSingleton <IGitCommandManager>(_gitCommandManager.Object); tc.SetSingleton <IWhichUtil>(new WhichUtil()); tc.SetSingleton <IVstsAgentWebProxy>(new VstsAgentWebProxy()); GitSourceProvider gitSourceProvider = new ExternalGitSourceProvider(); gitSourceProvider.Initialize(tc); gitSourceProvider.SetVariablesInEndpoint(executionContext.Object, endpoint); // Act. gitSourceProvider.GetSourceAsync(executionContext.Object, endpoint, default(CancellationToken)).GetAwaiter().GetResult(); // Assert. _gitCommandManager.Verify(x => x.GitClean(executionContext.Object, dumySourceFolder)); _gitCommandManager.Verify(x => x.GitReset(executionContext.Object, dumySourceFolder)); _gitCommandManager.Verify(x => x.GitDisableAutoGC(executionContext.Object, dumySourceFolder)); _gitCommandManager.Verify(x => x.GitRemoteSetUrl(executionContext.Object, dumySourceFolder, "origin", It.Is <string>(s => s.Equals("https://*****:*****@github.com/Microsoft/vsts-agent")))); _gitCommandManager.Verify(x => x.GitRemoteSetPushUrl(executionContext.Object, dumySourceFolder, "origin", It.Is <string>(s => s.Equals("https://*****:*****@github.com/Microsoft/vsts-agent")))); _gitCommandManager.Verify(x => x.GitFetch(executionContext.Object, dumySourceFolder, "origin", It.IsAny <int>(), It.IsAny <List <string> >(), It.IsAny <string>(), It.IsAny <CancellationToken>())); _gitCommandManager.Verify(x => x.GitRemoteSetUrl(executionContext.Object, dumySourceFolder, "origin", "https://github.com/Microsoft/vsts-agent")); _gitCommandManager.Verify(x => x.GitRemoteSetPushUrl(executionContext.Object, dumySourceFolder, "origin", "https://github.com/Microsoft/vsts-agent")); _gitCommandManager.Verify(x => x.GitCheckout(executionContext.Object, dumySourceFolder, "refs/remotes/origin/master", It.IsAny <CancellationToken>())); } finally { IOUtil.DeleteDirectory(dumySourceFolder, CancellationToken.None); } } }
public void GetSourceGitFetchWithLFS() { using (TestHostContext tc = new TestHostContext(this)) { var trace = tc.GetTrace(); // Arrange. string dumySourceFolder = Path.Combine(tc.GetDirectory(WellKnownDirectory.Bin), "SourceProviderL0"); try { Directory.CreateDirectory(dumySourceFolder); var executionContext = GetTestExecutionContext(tc, dumySourceFolder, "refs/remotes/origin/master", "", false); var endpoint = GetTestSourceEndpoint("https://github.com/Microsoft/vsts-agent", false, false, true); var _gitCommandManager = GetDefaultGitCommandMock(); tc.SetSingleton <IGitCommandManager>(_gitCommandManager.Object); tc.SetSingleton <IWhichUtil>(new WhichUtil()); tc.SetSingleton <IVstsAgentWebProxy>(new VstsAgentWebProxy()); GitSourceProvider gitSourceProvider = new ExternalGitSourceProvider(); gitSourceProvider.Initialize(tc); gitSourceProvider.SetVariablesInEndpoint(executionContext.Object, endpoint); // Act. gitSourceProvider.GetSourceAsync(executionContext.Object, endpoint, default(CancellationToken)).GetAwaiter().GetResult(); // Assert. _gitCommandManager.Verify(x => x.GitInit(executionContext.Object, dumySourceFolder)); _gitCommandManager.Verify(x => x.GitRemoteAdd(executionContext.Object, dumySourceFolder, "origin", "https://github.com/Microsoft/vsts-agent")); _gitCommandManager.Verify(x => x.GitLFSInstall(executionContext.Object, dumySourceFolder)); _gitCommandManager.Verify(x => x.GitConfig(executionContext.Object, dumySourceFolder, "remote.origin.lfsurl", "https://*****:*****@github.com/Microsoft/vsts-agent.git/info/lfs")); _gitCommandManager.Verify(x => x.GitConfig(executionContext.Object, dumySourceFolder, "remote.origin.lfspushurl", "https://*****:*****@github.com/Microsoft/vsts-agent.git/info/lfs")); _gitCommandManager.Verify(x => x.GitLFSFetch(executionContext.Object, dumySourceFolder, "origin", It.IsAny <string>(), It.IsAny <string>(), It.IsAny <CancellationToken>())); _gitCommandManager.Verify(x => x.GitFetch(executionContext.Object, dumySourceFolder, "origin", It.IsAny <int>(), It.IsAny <List <string> >(), It.IsAny <string>(), It.IsAny <CancellationToken>())); _gitCommandManager.Verify(x => x.GitCheckout(executionContext.Object, dumySourceFolder, "refs/remotes/origin/master", It.IsAny <CancellationToken>())); } finally { IOUtil.DeleteDirectory(dumySourceFolder, CancellationToken.None); } } }