public void registerHooks(string url) { var hookConfig = new NewRepositoryHook("web", new Dictionary <string, string>() { { "url", url }, // host this webhook on this app (tbd) { "content_type", "json" }, { "insecure_ssl", "0" } }); hookConfig.Events = new HashSet <string>() { "issues", "issue_comment" }; foreach (var repo in projectToRepoMapping.Values) { // make set of repos so not to duplicate using (var hook = githubClient.Repository.Hooks.Create(githubUser, repo, hookConfig)) { // register some sort of hook delete when application shutsdown from here // githubClient.Repository.Hooks.Delete(githubUser, defaultRepo, hook.Id); // NOTE: when handling the hook event we should see if we can identify events coming // from this application as to ignore them. } } }
public async Task CreateAWebHookForTestRepository() { var github = Helper.GetAuthenticatedClient(); var repoName = Helper.MakeNameWithTimestamp("create-hooks-test"); var repository = await github.Repository.Create(new NewRepository(repoName) { AutoInit = true }); var config = new Dictionary<string, string> { { "content_type", "json" }, { "url", "http://test.com/example" }, { "hostname", "http://hostname.url" }, { "username", "username" }, { "password", "password" } }; var parameters = new NewRepositoryHook("windowsazure", config) { Events = new[] { "push" }, Active = false }; var hook = await github.Repository.Hooks.Create(Helper.Credentials.Login, repository.Name, parameters); var baseHookUrl = CreateExpectedBaseHookUrl(repository.Url, hook.Id); Assert.Equal("windowsazure", hook.Name); Assert.Equal(new[] { "push" }.ToList(), hook.Events.ToList()); Assert.Equal(baseHookUrl, hook.Url); Assert.Equal(baseHookUrl + "/test", hook.TestUrl); Assert.Equal(baseHookUrl + "/pings", hook.PingUrl); Assert.NotNull(hook.CreatedAt); Assert.NotNull(hook.UpdatedAt); Assert.Equal(config.Keys, hook.Config.Keys); Assert.Equal(config.Values, hook.Config.Values); Assert.Equal(false, hook.Active); }
/// <summary> /// Creates a hook for a repository /// </summary> /// <param name="owner">The repository's owner</param> /// <param name="name">The repository's name</param> /// <param name="hook">The hook's parameters</param> /// <remarks>See <a href="http://developer.github.com/v3/repos/hooks/#create-a-hook">API documentation</a> for more information.</remarks> public IObservable <RepositoryHook> Create(string owner, string name, NewRepositoryHook hook) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(hook, "hook"); return(_client.Create(owner, name, hook).ToObservable()); }
/// <summary> /// Creates a hook for a repository /// </summary> /// <remarks>See <a href="http://developer.github.com/v3/repos/hooks/#create-a-hook">API documentation</a> for more information.</remarks> /// <returns></returns> public IObservable<RepositoryHook> Create(string owner, string repositoryName, NewRepositoryHook hook) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); Ensure.ArgumentNotNull(hook, "hook"); return _client.Create(owner, repositoryName, hook).ToObservable(); }
public void RequestsCorrectUrl() { var connection = Substitute.For<IApiConnection>(); var client = new RepositoriesClient(connection); var hook = new NewRepositoryHook("name", new Dictionary<string, string> { { "config", "" } }); client.Hooks.Create("fake", "repo", hook); connection.Received().Post<RepositoryHook>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/hooks"), hook); }
public void RequestsCorrectUrl() { var connection = Substitute.For <IApiConnection>(); var client = new RepositoriesClient(connection); var hook = new NewRepositoryHook(); client.Hooks.Create("fake", "repo", hook); connection.Received().Post <RepositoryHook>(Arg.Is <Uri>(u => u.ToString() == "repos/fake/repo/hooks"), hook); }
static RepositoryHook CreateHook(IGitHubClient github, Repository repository) { var config = new Dictionary<string, string> { { "content_type", "json" }, { "url", "http://test.com/example" } }; var parameters = new NewRepositoryHook("apropos", config) { Events = new[] { "commit_comment" }, Active = false }; var createdHook = github.Repository.Hooks.Create(Helper.Credentials.Login, repository.Name, parameters); return createdHook.Result; }
public void UsesTheSuppliedHook() { var connection = Substitute.For <IApiConnection>(); var client = new RepositoriesClient(connection); var newRepositoryHook = new NewRepositoryHook("name", new Dictionary <string, string> { { "config", "" } }); client.Hooks.Create("owner", "repo", newRepositoryHook); connection.Received().Post <RepositoryHook>(Arg.Any <Uri>(), newRepositoryHook); }
public void UsesTheSuppliedHook() { var connection = Substitute.For <IApiConnection>(); var client = new RepositoriesClient(connection); var newRepositoryHook = new NewRepositoryHook { Name = "aName" }; client.Hooks.Create("owner", "repo", newRepositoryHook); connection.Received().Post <RepositoryHook>(Arg.Any <Uri>(), newRepositoryHook); }
static RepositoryHook CreateHook(IGitHubClient github, Repository repository, string hookName, string eventName) { var config = new Dictionary<string, string> { { "content_type", "json" }, { "url", "http://test.com/example" } }; var parameters = new NewRepositoryHook(hookName, config) { Events = new[] { eventName }, Active = false }; var createdHook = github.Repository.Hooks.Create(Helper.UserName, repository.Name, parameters); return createdHook.Result; }
public void RequestsCorrectUrlWithRepositoryId() { var gitHubClient = Substitute.For <IGitHubClient>(); var client = new ObservableRepositoryHooksClient(gitHubClient); var hook = new NewRepositoryHook("name", new Dictionary <string, string> { { "config", "" } }); client.Create(1, hook); gitHubClient.Received().Repository.Hooks.Create(1, hook); }
public void RequestsCorrectUrlWithRepositoryId() { var connection = Substitute.For <IApiConnection>(); var client = new RepositoryHooksClient(connection); var hook = new NewRepositoryHook("name", new Dictionary <string, string> { { "config", "" } }); client.Create(1, hook); connection.Received().Post <RepositoryHook>(Arg.Is <Uri>(u => u.ToString() == "repositories/1/hooks"), hook); }
static RepositoryHook CreateHook(IGitHubClient github, Repository repository) { var config = new Dictionary <string, string> { { "content_type", "json" }, { "url", "http://test.com/example" } }; var parameters = new NewRepositoryHook("apropos", config) { Events = new[] { "commit_comment" }, Active = false }; var createdHook = github.Repository.Hooks.Create(Helper.Credentials.Login, repository.Name, parameters); return(createdHook.Result); }
static RepositoryHook CreateHook(IGitHubClient github, Repository repository, string hookName, string eventName) { var config = new Dictionary <string, string> { { "content_type", "json" }, { "url", "http://test.com/example" } }; var parameters = new NewRepositoryHook(hookName, config) { Events = new[] { eventName }, Active = false }; var createdHook = github.Repository.Hooks.Create(Helper.UserName, repository.Name, parameters); return(createdHook.Result); }
public virtual Task <RepositoryHook> CreateWebhook(string ownerName, string repoName, string url, string token) { _client.Credentials = new Credentials(token); Dictionary <string, string> cfg = new Dictionary <string, string>(); cfg.Add("url", url); cfg.Add("content_type", "json"); var info = new NewRepositoryHook("web", cfg); info.Active = true; return(_client.Repository.Hooks.Create(ownerName, repoName, info)); }
public async Task CreateWebHookAsync(string token, IEnumerable <string> events, string repoOwner, string repoName) { _client.Credentials = new Credentials(token); var hookConfig = new Dictionary <string, string> { { "url", $"{_settings.AppRootUrl}/api/github/webhook/handle" }, { "content_type", "application/json" } }; var hook = new NewRepositoryHook("web", hookConfig) { Active = true, Events = events }; await _client.Repository.Hooks.Create(repoOwner, repoName, hook); }
public async Task CreateAWebHookForTestRepository() { var github = Helper.GetAuthenticatedClient(); var repoName = Helper.MakeNameWithTimestamp("create-hooks-test"); var repository = await github.Repository.Create(new NewRepository(repoName) { AutoInit = true }); var config = new Dictionary <string, string> { { "content_type", "json" }, { "url", "http://test.com/example" }, { "hostname", "http://hostname.url" }, { "username", "username" }, { "password", "password" } }; var parameters = new NewRepositoryHook("windowsazure", config) { Events = new[] { "push" }, Active = false }; var hook = await github.Repository.Hooks.Create(Helper.Credentials.Login, repository.Name, parameters); var baseHookUrl = CreateExpectedBaseHookUrl(repository.Url, hook.Id); Assert.Equal("windowsazure", hook.Name); Assert.Equal(new[] { "push" }.ToList(), hook.Events.ToList()); Assert.Equal(baseHookUrl, hook.Url); Assert.Equal(baseHookUrl + "/test", hook.TestUrl); Assert.Equal(baseHookUrl + "/pings", hook.PingUrl); Assert.NotNull(hook.CreatedAt); Assert.NotNull(hook.UpdatedAt); Assert.Equal(config.Keys, hook.Config.Keys); Assert.Equal(config.Values, hook.Config.Values); Assert.Equal(false, hook.Active); }
public async Task ConfigureWebHook(string chHookUrl) { var allHooks = await _client.Repository.Hooks.GetAll(_org, _repo); if (allHooks.Any(x => x.Url != chHookUrl)) { var config = new Dictionary <string, string> { { "url", chHookUrl }, { "content_type", WebHookContentType.Json.ToString() }, { "secret", "" }, { "insecure_ssl", "false" } }; var webhook = new NewRepositoryHook("web", config) { Events = new List <string> { "*" } }; await _client.Repository.Hooks.Create(_org, _repo, webhook); } }
/// <summary> /// Creates a hook for a repository /// </summary> /// <param name="repositoryId">The Id of the repository</param> /// <param name="hook">The hook's parameters</param> /// <remarks>See <a href="http://developer.github.com/v3/repos/hooks/#create-a-hook">API documentation</a> for more information.</remarks> public IObservable <RepositoryHook> Create(long repositoryId, NewRepositoryHook hook) { Ensure.ArgumentNotNull(hook, "hook"); return(_client.Create(repositoryId, hook).ToObservable()); }
/// <summary> /// Creates a hook for a repository /// </summary> /// <param name="repositoryId">The Id of the repository</param> /// <param name="hook">The hook's parameters</param> /// <remarks>See <a href="http://developer.github.com/v3/repos/hooks/#create-a-hook">API documentation</a> for more information.</remarks> public IObservable<RepositoryHook> Create(long repositoryId, NewRepositoryHook hook) { Ensure.ArgumentNotNull(hook, "hook"); return _client.Create(repositoryId, hook).ToObservable(); }
public void UsesTheSuppliedHook() { var connection = Substitute.For<IApiConnection>(); var client = new RepositoriesClient(connection); var newRepositoryHook = new NewRepositoryHook("name", new Dictionary<string, string> { { "config", "" } }); client.Hooks.Create("owner", "repo", newRepositoryHook); connection.Received().Post<RepositoryHook>(Arg.Any<Uri>(), newRepositoryHook); }
public void RequestsCorrectUrlWithRepositoryId() { var gitHubClient = Substitute.For<IGitHubClient>(); var client = new ObservableRepositoryHooksClient(gitHubClient); var hook = new NewRepositoryHook("name", new Dictionary<string, string> { { "config", "" } }); client.Create(1, hook); gitHubClient.Received().Repository.Hooks.Create(1, hook); }