public void TestCreateOrUpdateHookCreate() { // Setup SimpleGithubManagement channel = new SimpleGithubManagement(); GithubRepositoryHook createdHook = null; bool tested = false; channel.GetRepositoryHooksThunk = ar => new List <GithubRepositoryHook>(); channel.CreateRepositoryHookThunk = ar => { createdHook = ar.Values["hook"] as GithubRepositoryHook; createdHook.Id = "id"; return(createdHook); }; channel.TestRepositoryHookThunk = ar => { if (ar.Values["id"].Equals("id")) { tested = true; } }; Site website = new Site { SiteProperties = new SiteProperties { Properties = new List <NameValuePair> { new NameValuePair { Name = "RepositoryUri", Value = "https://mynewsite999.scm.azurewebsites.net:443" }, new NameValuePair { Name = "PublishingUsername", Value = "$username" }, new NameValuePair { Name = "PublishingPassword", Value = "password" } } } }; // Test CmdletAccessor cmdletAccessor = new CmdletAccessor(); cmdletAccessor.GithubChannel = channel; GithubClientAccessor githubClientAccessor = new GithubClientAccessor(cmdletAccessor, null, null); githubClientAccessor.CreateOrUpdateHookAccessor("owner", "repository", website); Assert.IsNotNull(createdHook); Assert.IsTrue(tested); }
protected void CreateOrUpdateHook(string owner, string repository, Site website) { string baseUri = website.GetProperty("repositoryuri"); string publishingUsername = website.GetProperty("publishingusername"); string publishingPassword = website.GetProperty("publishingpassword"); UriBuilder newUri = new UriBuilder(baseUri); newUri.UserName = publishingUsername; newUri.Password = publishingPassword; newUri.Path = "/deploy"; string deployUri = newUri.ToString(); List <GithubRepositoryHook> repositoryHooks = new List <GithubRepositoryHook>(); InvokeInGithubOperationContext(() => { repositoryHooks = PSCmdlet.GithubChannel.GetRepositoryHooks(owner, repository); }); var existingHook = repositoryHooks.FirstOrDefault(h => h.Name.Equals("web") && new Uri(h.Config.Url).Host.Equals(new Uri(deployUri).Host)); if (existingHook != null) { if (!existingHook.Config.Url.Equals(newUri.ToString(), StringComparison.InvariantCultureIgnoreCase)) { existingHook.Config.Url = deployUri; InvokeInGithubOperationContext(() => PSCmdlet.GithubChannel.UpdateRepositoryHook(owner, repository, existingHook.Id, existingHook)); InvokeInGithubOperationContext(() => PSCmdlet.GithubChannel.TestRepositoryHook(owner, repository, existingHook.Id)); } else { throw new Exception(Resources.LinkAlreadyEstablished); } } else { GithubRepositoryHook githubRepositoryHook = new GithubRepositoryHook() { Name = "web", Active = true, Events = new List <string> { "push" }, Config = new GithubRepositoryHookConfig { Url = deployUri, InsecureSsl = "1", ContentType = "form" } }; InvokeInGithubOperationContext(() => { githubRepositoryHook = PSCmdlet.GithubChannel.CreateRepositoryHook(owner, repository, githubRepositoryHook); }); InvokeInGithubOperationContext(() => PSCmdlet.GithubChannel.TestRepositoryHook(owner, repository, githubRepositoryHook.Id)); } }
protected void CreateOrUpdateHook(string owner, string repository, Site website) { string baseUri = website.GetProperty("repositoryuri"); string publishingUsername = website.GetProperty("publishingusername"); string publishingPassword = website.GetProperty("publishingpassword"); UriBuilder newUri = new UriBuilder(baseUri); newUri.UserName = publishingUsername; newUri.Password = publishingPassword; newUri.Path = "/deploy"; string deployUri = newUri.ToString(); List<GithubRepositoryHook> repositoryHooks = new List<GithubRepositoryHook>(); InvokeInGithubOperationContext(() => { repositoryHooks = Pscmdlet.GithubChannel.GetRepositoryHooks(owner, repository); }); var existingHook = repositoryHooks.FirstOrDefault(h => h.Name.Equals("web") && new Uri(h.Config.Url).Host.Equals(new Uri(deployUri).Host)); if (existingHook != null) { if (!existingHook.Config.Url.Equals(newUri.ToString(), StringComparison.InvariantCultureIgnoreCase)) { existingHook.Config.Url = deployUri; InvokeInGithubOperationContext(() => Pscmdlet.GithubChannel.UpdateRepositoryHook(owner, repository, existingHook.Id, existingHook)); InvokeInGithubOperationContext(() => Pscmdlet.GithubChannel.TestRepositoryHook(owner, repository, existingHook.Id)); } else { throw new Exception(Resources.LinkAlreadyEstablished); } } else { GithubRepositoryHook githubRepositoryHook = new GithubRepositoryHook() { Name = "web", Active = true, Events = new List<string> { "push" }, Config = new GithubRepositoryHookConfig { Url = deployUri, InsecureSsl = "1", ContentType = "form" } }; InvokeInGithubOperationContext(() => { githubRepositoryHook = Pscmdlet.GithubChannel.CreateRepositoryHook(owner, repository, githubRepositoryHook); }); InvokeInGithubOperationContext(() => Pscmdlet.GithubChannel.TestRepositoryHook(owner, repository, githubRepositoryHook.Id)); } }
public static GithubRepositoryHook UpdateRepositoryHook(this IGithubServiceManagement proxy, string owner, string repository, string id, GithubRepositoryHook hook) { return(proxy.EndUpdateRepositoryHook(proxy.BeginUpdateRepositoryHook(owner, repository, id, hook, null, null))); }
public static GithubRepositoryHook UpdateRepositoryHook(this IGithubServiceManagement proxy, string owner, string repository, string id, GithubRepositoryHook hook) { return proxy.EndUpdateRepositoryHook(proxy.BeginUpdateRepositoryHook(owner, repository, id, hook, null, null)); }
public IAsyncResult BeginUpdateRepositoryHook(string owner, string repository, string id, GithubRepositoryHook hook, AsyncCallback callback, object state) { SimpleServiceManagementAsyncResult result = new SimpleServiceManagementAsyncResult(); result.Values["owner"] = owner; result.Values["repository"] = repository; result.Values["id"] = id; result.Values["hook"] = hook; result.Values["callback"] = callback; result.Values["state"] = state; return result; }
public IAsyncResult BeginUpdateRepositoryHook(string owner, string repository, string id, GithubRepositoryHook hook, AsyncCallback callback, object state) { SimpleServiceManagementAsyncResult result = new SimpleServiceManagementAsyncResult(); result.Values["owner"] = owner; result.Values["repository"] = repository; result.Values["id"] = id; result.Values["hook"] = hook; result.Values["callback"] = callback; result.Values["state"] = state; return(result); }