public async Task It_finds_the_requested_repo() { var console = new TestConsole(); await GitHubHandler.Handler(new TryGitHubOptions("rchande/2660eaec-6af8-452d-b70d-41227d616cd9"), console, _locator); console.Out.ToString().Replace("\r\n", "\n"). Should().Be("Found repo `rchande/2660eaec-6af8-452d-b70d-41227d616cd9`\nTo try `rchande/2660eaec-6af8-452d-b70d-41227d616cd9`, cd to your desired directory and run the following command:\n\n\tgit clone https://github.com/rchande/2660eaec-6af8-452d-b70d-41227d616cd9.git && dotnet try .\n"); }
public async Task It_asks_for_disambiguation() { var console = new TestConsole(); await GitHubHandler.Handler(new TryGitHubOptions("rchande/tribble"), console, _locator); console.Out.ToString().Replace("\r\n", "\n").Should() .Be("Which of the following did you mean?\n\trchande/upgraded-octo-tribble.\n\trchande/downgraded-octo-tribble.\n"); }
public async Task It_reports_no_matches() { var console = new TestConsole(); await GitHubHandler.Handler(new TryGitHubOptions("foo"), console, _locator); console.Out.ToString().Replace("\r\n", "\n") .Should().Be("Didn't find any repos called `foo`\n"); }
public void GitHubHandlerReturnsNoOpForMalformedPayloads(string payloadContent) { // Arrange var httpRequest = GetRequest(); var handler = new GitHubHandler(); JObject payload = JObject.Parse(payloadContent); // Act DeploymentInfo deploymentInfo; DeployAction result = handler.TryParseDeploymentInfo(httpRequest, payload: payload, targetBranch: "master", deploymentInfo: out deploymentInfo); // Assert Assert.Equal(DeployAction.NoOp, result); }
public void GitHubHandlerReturnsNoOpForPayloadsNotMatchingTargetBranch() { // Verifies delete scenario. // Arrange string payloadContent = @"{ ""repository"":{ ""url"":""https://github.com/KuduApps/PostCommitTest"" }, ref: ""refs/heads/not-master"", commits: [{""added"":[""Foo.txt""],""author"":{""email"":""*****@*****.**"",""name"":""Pranav K"",""username"":""pranavkm""},""committer"":{""email"":""*****@*****.**"",""name"":""Pranav K"",""username"":""pranavkm""},""distinct"":true,""id"":""f94996d67d6d5a060aaf2fcb72c333d0899549ab"",""message"":""Foo commit"",""modified"":[],""removed"":[],""timestamp"":""2012-12-17T14:32:20-08:00"",""url"":""https://github.com/KuduApps/PostCommitTest/commit/f94996d67d6d5a060aaf2fcb72c333d0899549ab""}] }"; var httpRequest = GetRequest(); var handler = new GitHubHandler(); JObject payload = JObject.Parse(payloadContent); // Act DeploymentInfo deploymentInfo; DeployAction result = handler.TryParseDeploymentInfo(httpRequest, payload: payload, targetBranch: "master", deploymentInfo: out deploymentInfo); // Assert Assert.Equal(DeployAction.NoOp, result); }
public void GitHubHandlerReturnsNoOpForPayloadsWithEmptyAfter() { // Verifies delete scenario. // Arrange string payloadContent = @"{""after"":""00000000000000000000000000000000"", ""repository"":{ ""url"":""https://github.com/KuduApps/PostCommitTest"" }, ref: ""refs/heads/master"", commits: [] }"; var httpRequest = GetRequest(); var handler = new GitHubHandler(); JObject payload = JObject.Parse(payloadContent); // Act DeploymentInfo deploymentInfo; DeployAction result = handler.TryParseDeploymentInfo(httpRequest, payload: payload, targetBranch: "master", deploymentInfo: out deploymentInfo); // Assert Assert.Equal(DeployAction.NoOp, result); }
public void GitHubHandlerIgnoresNonGithubPayloads() { // Arrange var headers = new NameValueCollection(); var httpRequest = new Mock <HttpRequestBase>(); httpRequest.SetupGet(r => r.Headers).Returns(headers); var handler = new GitHubHandler(); // Act DeploymentInfo deploymentInfo; DeployAction result = handler.TryParseDeploymentInfo(httpRequest.Object, payload: null, targetBranch: null, deploymentInfo: out deploymentInfo); // Assert Assert.Equal(DeployAction.UnknownPayload, result); }
public void GitHubHandlerProcessesPayloadWithMultipleCommits() { // Verifies delete scenario. // Arrange string payloadContent = @"{""after"":""f94996d67d6d5a060aaf2fcb72c333d0899549ab"",""before"":""0000000000000000000000000000000000000000"",""commits"":[{""added"":[],""author"":{""email"":""*****@*****.**"",""name"":""Kirthi Krishnamraju"",""username"":""kirthik""},""committer"":{""email"":""*****@*****.**"",""name"":""Kirthi Krishnamraju"",""username"":""kirthik""},""distinct"":true,""id"":""18ceab5cda610374b45f6496c88615b1213a7bd8"",""message"":""in foo"",""modified"":[""MvcApplication1/Controllers/HomeController.cs""],""removed"":[],""timestamp"":""2012-08-30T17:36:29-07:00"",""url"":""https://github.com/KuduApps/PostCommitTest/commit/18ceab5cda610374b45f6496c88615b1213a7bd8""},{""added"":[""Foo.txt""],""author"":{""email"":""*****@*****.**"",""name"":""Pranav K"",""username"":""pranavkm""},""committer"":{""email"":""*****@*****.**"",""name"":""Pranav K"",""username"":""pranavkm""},""distinct"":true,""id"":""f94996d67d6d5a060aaf2fcb72c333d0899549ab"",""message"":""Foo commit"",""modified"":[],""removed"":[],""timestamp"":""2012-12-17T14:32:20-08:00"",""url"":""https://github.com/KuduApps/PostCommitTest/commit/f94996d67d6d5a060aaf2fcb72c333d0899549ab""}],""compare"":""https://github.com/KuduApps/PostCommitTest/compare/18ceab5cda61^...f94996d67d6d"",""created"":true,""deleted"":false,""forced"":true,""pusher"":{""email"":""*****@*****.**"",""name"":""pranavkm""},""ref"":""refs/heads/master"",""repository"":{""private"":false,""url"":""https://github.com/KuduApps/PostCommitTest""}}"; var httpRequest = GetRequest(); var handler = new GitHubHandler(); JObject payload = JObject.Parse(payloadContent); // Act DeploymentInfo deploymentInfo; DeployAction result = handler.TryParseDeploymentInfo(httpRequest, payload: payload, targetBranch: "master", deploymentInfo: out deploymentInfo); // Assert Assert.Equal(DeployAction.ProcessDeployment, result); Assert.NotNull(deploymentInfo); Assert.Equal("GitHub", deploymentInfo.Deployer); Assert.Equal(RepositoryType.Git, deploymentInfo.RepositoryType); Assert.Equal("https://github.com/KuduApps/PostCommitTest", deploymentInfo.RepositoryUrl); Assert.Equal("f94996d67d6d5a060aaf2fcb72c333d0899549ab", deploymentInfo.TargetChangeset.Id); Assert.Equal("Pranav K", deploymentInfo.TargetChangeset.AuthorName); Assert.Equal("*****@*****.**", deploymentInfo.TargetChangeset.AuthorEmail); Assert.Equal("Foo commit", deploymentInfo.TargetChangeset.Message); }
/// <summary> /// Copies Infos to the ModInfo. /// Try to find a compatible SiteHandler for the provided urls (like Download, URL, ChangeLogUrl, GitHub) /// </summary> private static void ImportAvcInfo(AVCInfo avcInfo, ref ModInfo modInfo) { Messenger.AddDebug(string.Format(Messages.MSG_IMPORTING_AVC_VERSIONFILE_INFO_0, modInfo.Name)); string fileName = Path.GetFileNameWithoutExtension(modInfo.LocalPath); if (!OptionsController.AVCIgnoreName && !string.IsNullOrEmpty(avcInfo.Name) && (string.IsNullOrEmpty(modInfo.Name) || modInfo.Name == fileName)) { modInfo.Name = avcInfo.Name; } if (!string.IsNullOrEmpty(avcInfo.Version) && (string.IsNullOrEmpty(modInfo.Version))) { modInfo.Version = avcInfo.Version; } if (!string.IsNullOrEmpty(avcInfo.KspVersion) && (string.IsNullOrEmpty(modInfo.KSPVersion))) { modInfo.KSPVersion = avcInfo.KspVersion; } if (!OptionsController.AVCIgnoreURL && !string.IsNullOrEmpty(avcInfo.Url) && (string.IsNullOrEmpty(modInfo.AvcURL))) { AVCInfo newAvcInfo = null; try { // Get newest AVC informations for this mod. newAvcInfo = AVCParser.ReadFromWeb(avcInfo.Url); } catch (Exception ex) { Messenger.AddError(string.Format(Messages.MSG_ERROR_DOWNLOADING_NEW_AVC_VERION_FILE_FAILED), ex); } if (newAvcInfo != null) { modInfo.AvcURL = avcInfo.Url; avcInfo.Download = newAvcInfo.Download; avcInfo.ChangeLog = newAvcInfo.ChangeLog; avcInfo.ChangeLogUrl = newAvcInfo.ChangeLogUrl; avcInfo.GitHubUsername = newAvcInfo.GitHubUsername; avcInfo.GitHubRepository = newAvcInfo.GitHubRepository; avcInfo.GitHubAllowPreRelease = newAvcInfo.GitHubAllowPreRelease; } } if (string.IsNullOrEmpty(modInfo.ModURL) && !modInfo.HasSiteHandler) { ISiteHandler siteHandler = null; string downloadUrl = string.Empty; string[] urls = new[] { GitHubHandler.GetProjectUrl(avcInfo.GitHubUsername, avcInfo.GitHubRepository), avcInfo.Download, avcInfo.Url, avcInfo.ChangeLogUrl }; foreach (string url in urls) { downloadUrl = url; siteHandler = SiteHandlerManager.GetSiteHandlerByURL(downloadUrl); if (siteHandler != null) { break; } } if (siteHandler != null) { modInfo.ModURL = downloadUrl; modInfo.SiteHandlerName = siteHandler.Name; Messenger.AddDebug(string.Format(Messages.MSG_COMPATIBLE_SITEHANDLER_0_FOUND_1, siteHandler.Name, modInfo.Name)); } else { Messenger.AddDebug(string.Format(Messages.MSG_NO_COMPATIBLE_SITEHANDLER_FOUND_0, modInfo.Name)); } } }