fix(github): support custom webhook override
This commit is contained in:
parent
499a8666db
commit
a07cee7ad6
3 changed files with 29 additions and 19 deletions
|
|
@ -21,6 +21,8 @@ class Change extends Component
|
|||
|
||||
public string $webhook_endpoint = '';
|
||||
|
||||
public string $custom_webhook_endpoint = '';
|
||||
|
||||
public ?string $ipv4 = null;
|
||||
|
||||
public ?string $ipv6 = null;
|
||||
|
|
@ -98,6 +100,7 @@ protected function rules(): array
|
|||
'pullRequests' => 'nullable|string',
|
||||
'privateKeyId' => 'nullable|int',
|
||||
'webhook_endpoint' => ['required', 'string', 'url'],
|
||||
'custom_webhook_endpoint' => ['nullable', 'string', 'url'],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -238,7 +238,10 @@ class="bg-transparent border-transparent hover:bg-transparent hover:border-trans
|
|||
<div class="mx-auto grid w-full max-w-5xl grid-cols-1 gap-4 lg:grid-cols-2">
|
||||
@can('create', $github_app)
|
||||
<section class="box-without-bg flex-col gap-4 p-6 h-full transition-all duration-200"
|
||||
x-data="{ webhookEndpoint: $wire.entangle('webhook_endpoint').live }">
|
||||
x-data="{
|
||||
webhookEndpoint: $wire.entangle('webhook_endpoint').live,
|
||||
customWebhookEndpoint: $wire.entangle('custom_webhook_endpoint').live,
|
||||
}">
|
||||
<div class="flex flex-col gap-4 text-left h-full">
|
||||
<div class="flex items-center justify-between">
|
||||
<svg class="size-10" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
|
||||
|
|
@ -259,13 +262,10 @@ class="px-2 py-1 text-xs font-bold uppercase tracking-wide bg-coollabs/10 dark:b
|
|||
</div>
|
||||
<div class="flex flex-col gap-3 pt-4 border-t border-neutral-200 dark:border-coolgray-400">
|
||||
@if (!isCloud() || isDev())
|
||||
<x-forms.input canGate="create" :canResource="$github_app" x-model="webhookEndpoint"
|
||||
:value="$webhook_endpoint" id="webhook_endpoint" type="url"
|
||||
list="webhook-endpoint-suggestions" label="Webhook Endpoint"
|
||||
placeholder="https://coolify.example.com"
|
||||
helper="Type or select the public URL GitHub should use for webhooks. Useful when a tunnel or proxy terminates HTTPS while Coolify itself is configured with HTTP. Do not include /webhooks.">
|
||||
</x-forms.input>
|
||||
<datalist id="webhook-endpoint-suggestions">
|
||||
<x-forms.select canGate="create" :canResource="$github_app"
|
||||
wire:model.live='webhook_endpoint' x-model="webhookEndpoint"
|
||||
label="Webhook Endpoint"
|
||||
helper="All Git webhooks will be sent to this endpoint unless a custom endpoint is set below.">
|
||||
@if ($fqdn)
|
||||
<option value="{{ $fqdn }}">Use {{ $fqdn }}</option>
|
||||
@endif
|
||||
|
|
@ -278,7 +278,11 @@ class="px-2 py-1 text-xs font-bold uppercase tracking-wide bg-coollabs/10 dark:b
|
|||
@if (config('app.url'))
|
||||
<option value="{{ config('app.url') }}">Use {{ config('app.url') }}</option>
|
||||
@endif
|
||||
</datalist>
|
||||
</x-forms.select>
|
||||
<x-forms.input canGate="create" :canResource="$github_app"
|
||||
x-model="customWebhookEndpoint" id="custom_webhook_endpoint" type="url"
|
||||
label="Custom Webhook Endpoint" placeholder="https://coolify.example.com"
|
||||
helper="Use a custom URL only when it should override the selected endpoint. Useful when a tunnel or proxy terminates HTTPS while Coolify itself is configured with HTTP. Do not include /webhooks." />
|
||||
@else
|
||||
<div class="text-sm dark:text-neutral-400">You need to register a GitHub App before using this source.</div>
|
||||
@endif
|
||||
|
|
@ -292,7 +296,7 @@ class="px-2 py-1 text-xs font-bold uppercase tracking-wide bg-coollabs/10 dark:b
|
|||
</div>
|
||||
<div class="mt-auto pt-2">
|
||||
<x-forms.button canGate="create" :canResource="$github_app" class="w-full justify-center" isHighlighted
|
||||
x-on:click.prevent="createGithubApp(webhookEndpoint, {{ Illuminate\Support\Js::from($preview_deployment_permissions) }}, {{ Illuminate\Support\Js::from($administration) }})">
|
||||
x-on:click.prevent="createGithubApp(webhookEndpoint, customWebhookEndpoint, {{ Illuminate\Support\Js::from($preview_deployment_permissions) }}, {{ Illuminate\Support\Js::from($administration) }})">
|
||||
Register Now
|
||||
</x-forms.button>
|
||||
</div>
|
||||
|
|
@ -335,17 +339,19 @@ class="px-2 py-1 text-xs font-bold uppercase tracking-wide bg-neutral-100 dark:b
|
|||
</div>
|
||||
</div>
|
||||
<script>
|
||||
function createGithubApp(webhook_endpoint, preview_deployment_permissions, administration) {
|
||||
function createGithubApp(webhook_endpoint, custom_webhook_endpoint, preview_deployment_permissions, administration) {
|
||||
const {
|
||||
organization,
|
||||
html_url,
|
||||
uuid
|
||||
} = @js($github_app->only(['organization', 'html_url', 'uuid']));
|
||||
if (!webhook_endpoint) {
|
||||
const selectedEndpoint = webhook_endpoint ? webhook_endpoint.trim() : '';
|
||||
const customEndpoint = custom_webhook_endpoint ? custom_webhook_endpoint.trim() : '';
|
||||
if (!customEndpoint && !selectedEndpoint) {
|
||||
alert('Please enter a webhook endpoint.');
|
||||
return;
|
||||
}
|
||||
let baseUrl = webhook_endpoint.trim().replace(/\/+$/, '');
|
||||
let baseUrl = (customEndpoint || selectedEndpoint).replace(/\/+$/, '');
|
||||
const name = @js($name);
|
||||
const manifestState = @js($manifestState);
|
||||
const isDev = @js(config('app.env')) ===
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ function validPrivateKey(): string
|
|||
->assertSet('webhook_endpoint', 'http://localhost:8000');
|
||||
});
|
||||
|
||||
test('webhook endpoint can be typed manually when creating github app', function () {
|
||||
test('custom webhook endpoint input is used as an override for selected endpoint', function () {
|
||||
config(['app.url' => 'http://localhost:8000']);
|
||||
|
||||
InstanceSettings::findOrFail(0)->update([
|
||||
|
|
@ -131,11 +131,12 @@ function validPrivateKey(): string
|
|||
Livewire::withQueryParams(['github_app_uuid' => $githubApp->uuid])
|
||||
->test(Change::class)
|
||||
->assertSuccessful()
|
||||
->set('webhook_endpoint', 'https://staging.example.com')
|
||||
->assertSet('webhook_endpoint', 'https://staging.example.com')
|
||||
->assertSee('Type or select the public URL GitHub should use for webhooks', false)
|
||||
->assertSee('https://staging.example.com')
|
||||
->assertSee('webhook-endpoint-suggestions');
|
||||
->set('custom_webhook_endpoint', 'https://staging.example.com')
|
||||
->assertSet('webhook_endpoint', 'http://staging.example.com')
|
||||
->assertSet('custom_webhook_endpoint', 'https://staging.example.com')
|
||||
->assertSee('Use a custom URL only when it should override the selected endpoint.', false)
|
||||
->assertSee('Custom Webhook Endpoint')
|
||||
->assertSee('createGithubApp(webhookEndpoint, customWebhookEndpoint');
|
||||
});
|
||||
|
||||
test('can mount with fully configured github app', function () {
|
||||
|
|
|
|||
Loading…
Reference in a new issue