Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add additional configuration option #568

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,14 @@ Libraries to handle GitHub Webhooks in .NET applications.
.Build();
```

`ConfigureGitHubWebhooks()` takes one optional parameter:
`ConfigureGitHubWebhooks()` either takes an optional parameter:

* `secret`. The secret you have configured in GitHub, if you have set this up.

or:

* `configure`. A function that takes an IConfiguration instance and expects the secret you have configured in GitHub in return.

The function is available on the `/api/github/webhooks` endpoint.

## Thanks
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace Octokit.Webhooks.AzureFunctions;
namespace Octokit.Webhooks.AzureFunctions;

using System;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

Expand All @@ -14,4 +16,18 @@ public static class GithubWebhookHostBuilderExtensions
public static IHostBuilder ConfigureGitHubWebhooks(this IHostBuilder hostBuilder, string? secret = null) =>
hostBuilder.ConfigureServices(services =>
services.AddOptions<GitHubWebhooksOptions>().Configure(options => options.Secret = secret));

/// <summary>
/// Configures GitHub webhook function.
/// </summary>
/// <param name="hostBuilder"><see cref="IHostBuilder" /> instance.</param>
/// <param name="configure">A function that takes an <see cref="IConfiguration" /> instance and expects the secret you have configured in GitHub in return.</param>
/// <returns>Returns <see cref="IHostBuilder" /> instance.</returns>
public static IHostBuilder ConfigureGitHubWebhooks(this IHostBuilder hostBuilder, Func<IConfiguration, string> configure)
{
ArgumentNullException.ThrowIfNull(configure);

return hostBuilder.ConfigureServices((context, services) =>
services.AddOptions<GitHubWebhooksOptions>().Configure(options => options.Secret = configure(context.Configuration)));
}
}