This commit is contained in:
Andras Bacsai 2023-06-14 13:07:58 +02:00
parent 4698ab9722
commit 2c9c9a86f4
3 changed files with 53 additions and 36 deletions

View File

@ -12,6 +12,10 @@ class Change extends Component
public string|null $ipv4;
public string|null $ipv6;
public string|null $fqdn;
public bool|null $default_permissions = true;
public bool|null $preview_deployment_permissions = true;
public $parameters;
public GithubApp $github_app;
public string $name;
@ -48,13 +52,6 @@ class Change extends Component
}
public function instantSave()
{
try {
$this->github_app->is_system_wide = $this->is_system_wide;
$this->github_app->save();
$this->emit('saved', 'GitHub settings updated!');
} catch (\Exception $e) {
return general_error_handler(err: $e, that: $this);
}
}
public function delete()

View File

@ -8,7 +8,7 @@
'noDirty' => $attributes->has('noDirty'),
'disabled' => null,
])
<label {{ $attributes->merge(['class' => 'flex cursor-pointer w-64 label']) }}>
<div {{ $attributes->merge(['class' => 'flex cursor-pointer w-96 label']) }}>
<div class="flex gap-1 label-text">
@if ($label)
{{ $label }}
@ -16,7 +16,7 @@
{{ $id }}
@endif
@if ($helper)
<div class="group">
<div class="group w-fit">
<div class="cursor-pointer text-warning">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
class="w-4 h-4 stroke-current">
@ -36,4 +36,4 @@
<input type="checkbox" @if ($disabled !== null) disabled @endif name={{ $id }}
@if (!$noDirty) wire:dirty.class="input-warning" @endif
@if ($instantSave) wire:click='instantSave' wire:model.defer={{ $id }} @else wire:model.defer={{ $value ?? $id }} @endif />
</label>
</div>

View File

@ -62,9 +62,19 @@
helper="If checked, this GitHub App will be available for everyone in this Coolify instance."
instantSave id="is_system_wide" />
@else
<div class="text-sm ">You need to register a GitHub App before using this source.</div>
<div class="flex items-end gap-4 pt-2 pb-10">
<form class="flex gap-2">
<form class="flex gap-4">
<div class="flex items-end gap-2">
<h3>Register a GitHub App</h3>
<x-forms.button
x-on:click.prevent="createGithubApp('{{ $webhook_endpoint }}','{{ $preview_deployment_permissions }}')">
Register a
GitHub
Application
</x-forms.button>
</div>
<div class="pt-1 pb-2 text-sm">You need to register a GitHub App before using this source.</div>
<div class="pt-2 pb-10">
<div class="flex items-end gap-2">
<x-forms.select wire:model='webhook_endpoint' label="Webhook Endpoint"
helper="All Git webhooks will be sent to this endpoint. <br><br>If you would like to use domain instead of IP address, set your Coolify instance's FQDN in the Settings menu.">
@if ($ipv4)
@ -77,11 +87,18 @@
<option value="{{ $fqdn }}">Use {{ $fqdn }}</option>
@endif
</x-forms.select>
<x-forms.button x-on:click.prevent="createGithubApp('{{ $webhook_endpoint }}')">Register a GitHub
Application
</x-forms.button>
</form>
</div>
<div class="flex flex-col gap-2 pt-4">
<x-forms.checkbox disabled instantSave id="default_permissions" label="Default Permissions"
helper="Contents: read<br>Metadata: read<br>Email: read" />
<x-forms.checkbox instantSave id="preview_deployment_permissions"
label="Preview Deployments Permission"
helper="Necessary for updating pull requests with useful comments (deployment status, links, etc.)<br><br>Pull Request: read & write" />
</div>
</div>
</form>
<div class="flex gap-2">
<x-forms.input id="github_app.name" label="App Name" disabled />
<x-forms.input id="github_app.organization" label="Organization"
@ -102,9 +119,9 @@
</div>
<x-forms.checkbox
helper="If checked, this GitHub App will be available for everyone in this Coolify instance." noDirty
label="System Wide?" instantSave disabled id="is_system_wide" />
label="System Wide?" disabled id="is_system_wide" />
<script>
function createGithubApp(webhook_endpoint) {
function createGithubApp(webhook_endpoint, preview_deployment_permissions) {
const {
organization,
uuid,
@ -119,6 +136,14 @@
}
const webhookBaseUrl = `${baseUrl}/webhooks`;
const path = organization ? `organizations/${organization}/settings/apps/new` : 'settings/apps/new';
const default_permissions = {
contents: 'read',
metadata: 'read',
emails: 'read'
};
if (preview_deployment_permissions) {
default_permissions.pull_requests = 'write';
}
const data = {
name,
url: baseUrl,
@ -132,12 +157,7 @@
request_oauth_on_install: false,
setup_url: `${webhookBaseUrl}/source/github/install?source=${uuid}`,
setup_on_update: true,
default_permissions: {
contents: 'read',
metadata: 'read',
pull_requests: 'write',
emails: 'read'
},
default_permissions,
default_events: ['pull_request', 'push']
};
const form = document.createElement('form');