diff --git a/app/Http/Livewire/Source/Github/Change.php b/app/Http/Livewire/Source/Github/Change.php index d0b717730..c6d02635a 100644 --- a/app/Http/Livewire/Source/Github/Change.php +++ b/app/Http/Livewire/Source/Github/Change.php @@ -3,17 +3,18 @@ namespace App\Http\Livewire\Source\Github; use App\Models\GithubApp; +use App\Models\InstanceSettings; use Livewire\Component; class Change extends Component { public string $webhook_endpoint; - public string|null $ipv4; - public string|null $ipv6; - public string|null $fqdn; + public ?string $ipv4; + public ?string $ipv6; + public ?string $fqdn; - public bool|null $default_permissions = true; - public bool|null $preview_deployment_permissions = true; + public ?bool $default_permissions = true; + public ?bool $preview_deployment_permissions = true; public $parameters; public GithubApp $github_app; @@ -28,29 +29,68 @@ class Change extends Component 'github_app.custom_user' => 'required|string', 'github_app.custom_port' => 'required|int', 'github_app.app_id' => 'required|int', - 'github_app.installation_id' => 'nullable', - 'github_app.client_id' => 'nullable', - 'github_app.client_secret' => 'nullable', - 'github_app.webhook_secret' => 'nullable', + 'github_app.installation_id' => 'required|int', + 'github_app.client_id' => 'required|string', + 'github_app.client_secret' => 'required|string', + 'github_app.webhook_secret' => 'required|string', 'github_app.is_system_wide' => 'required|bool', ]; public function mount() { + $github_app_uuid = request()->github_app_uuid; + $this->github_app = GithubApp::where('uuid', $github_app_uuid)->first(); + if (!$this->github_app) { + return redirect()->route('source.all'); + } + $settings = InstanceSettings::get(); + $this->github_app->makeVisible('client_secret')->makeVisible('webhook_secret'); + + $this->name = str($this->github_app->name)->kebab(); + $this->fqdn = $settings->fqdn; + + if ($settings->public_ipv4) { + $this->ipv4 = 'http://' . $settings->public_ipv4 . ':' . config('app.port'); + } + if ($settings->public_ipv6) { + $this->ipv6 = 'http://' . $settings->public_ipv6 . ':' . config('app.port'); + } + if ($this->github_app->installation_id && session('from')) { + $source_id = data_get(session('from'), 'source_id'); + if (!$source_id || $this->github_app->id !== $source_id) { + session()->forget('from'); + } else { + $parameters = data_get(session('from'), 'parameters'); + $back = data_get(session('from'), 'back'); + $environment_name = data_get($parameters, 'environment_name'); + $project_uuid = data_get($parameters, 'project_uuid'); + $type = data_get($parameters, 'type'); + $destination = data_get($parameters, 'destination'); + session()->forget('from'); + return redirect()->route($back, [ + 'environment_name' => $environment_name, + 'project_uuid' => $project_uuid, + 'type' => $type, + 'destination' => $destination, + ]); + } + } + $this->parameters = get_route_parameters(); if (isCloud() && !isDev()) { $this->webhook_endpoint = config('app.url'); } else { $this->webhook_endpoint = $this->ipv4; $this->is_system_wide = $this->github_app->is_system_wide; } - $this->parameters = get_route_parameters(); } public function submit() { try { + $this->github_app->makeVisible('client_secret')->makeVisible('webhook_secret'); $this->validate(); $this->github_app->save(); + $this->emit('success', 'Github App updated successfully.'); } catch (\Throwable $e) { return handleError($e, $this); } diff --git a/config/sentry.php b/config/sentry.php index 8899bddd2..8ffa05932 100644 --- a/config/sentry.php +++ b/config/sentry.php @@ -7,7 +7,7 @@ return [ // The release version of your application // Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD')) - 'release' => '4.0.0-beta.111', + 'release' => '4.0.0-beta.112', // When left empty or `null` the Laravel environment will be used 'environment' => config('app.env'), diff --git a/config/version.php b/config/version.php index f02cc33b3..b2220ad08 100644 --- a/config/version.php +++ b/config/version.php @@ -1,3 +1,3 @@ This source will be deleted. It is not reversible.
Please think again.

-
-
-

GitHub App

-
- @if ($github_app->app_id) - Save - + @if (data_get($github_app, 'app_id')) + +
+

GitHub App

+
@if (data_get($github_app, 'installation_id')) + Save - Update Repositories @endif - @else - Save - @endif - - Delete - + + Delete + +
-
-
Your Private GitHub App for private repositories.
- @if (data_get($github_app, 'app_id')) +
Your Private GitHub App for private repositories.
@if (!data_get($github_app, 'installation_id'))
You must complete this step before you can use this source!
- + Install Repositories on GitHub @else @@ -78,110 +72,118 @@
@endif - @else -
- - - - You must complete this step before you can use this source! + + @else +
+

GitHub App

+
+ + Delete +
-
-

Register a GitHub App

-
You need to register a GitHub App before using this source.
-
- @if (!isCloud() || isDev()) -
- - @if ($ipv4) - - @endif - @if ($ipv6) - - @endif - @if ($fqdn) - - @endif - @if (config('app.url')) - - @endif - - - Register - -
- @else +
+
+ + + + You must complete this step before you can use this source! +
+
+

Register a GitHub App

+
You need to register a GitHub App before using this source.
+
+ @if (!isCloud() || isDev()) +
+ + @if ($ipv4) + + @endif + @if ($ipv6) + + @endif + @if ($fqdn) + + @endif + @if (config('app.url')) + + @endif + - Register Now + Register - @endif -
- -
+ @else + + Register Now + + @endif +
+ +
- - - @endif - + 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, + hook_attributes: { + url: `${webhookBaseUrl}/source/github/events`, + active: true, + }, + redirect_url: `${webhookBaseUrl}/source/github/redirect`, + callback_urls: [`${baseUrl}/login/github/app`], + public: false, + request_oauth_on_install: false, + setup_url: `${webhookBaseUrl}/source/github/install?source=${uuid}`, + setup_on_update: true, + default_permissions, + default_events: ['pull_request', 'push'] + }; + const form = document.createElement('form'); + form.setAttribute('method', 'post'); + form.setAttribute('action', `${html_url}/${path}?state=${uuid}`); + const input = document.createElement('input'); + input.setAttribute('id', 'manifest'); + input.setAttribute('name', 'manifest'); + input.setAttribute('type', 'hidden'); + input.setAttribute('value', JSON.stringify(data)); + form.appendChild(input); + document.getElementsByTagName('body')[0].appendChild(form); + form.submit(); + } + + @endif
diff --git a/routes/web.php b/routes/web.php index 83e119aee..54226ca89 100644 --- a/routes/web.php +++ b/routes/web.php @@ -20,11 +20,10 @@ use App\Http\Livewire\Server\PrivateKey\Show as PrivateKeyShow; use App\Http\Livewire\Server\Proxy\Show as ProxyShow; use App\Http\Livewire\Server\Proxy\Logs as ProxyLogs; use App\Http\Livewire\Server\Show; +use App\Http\Livewire\Source\Github\Change as GitHubChange; use App\Http\Livewire\Subscription\Show as SubscriptionShow; use App\Http\Livewire\Waitlist\Index as WaitlistIndex; -use App\Models\GithubApp; use App\Models\GitlabApp; -use App\Models\InstanceSettings; use App\Models\PrivateKey; use App\Models\Server; use App\Models\StandaloneDocker; @@ -178,49 +177,7 @@ Route::middleware(['auth'])->group(function () { 'sources' => $sources, ]); })->name('source.all'); - Route::get('/source/github/{github_app_uuid}', function (Request $request) { - $github_app = GithubApp::where('uuid', request()->github_app_uuid)->first(); - if (!$github_app) { - abort(404); - } - $github_app->makeVisible('client_secret')->makeVisible('webhook_secret'); - $settings = InstanceSettings::get(); - $name = Str::of(Str::kebab($github_app->name)); - if ($settings->public_ipv4) { - $ipv4 = 'http://' . $settings->public_ipv4 . ':' . config('app.port'); - } - if ($settings->public_ipv6) { - $ipv6 = 'http://' . $settings->public_ipv6 . ':' . config('app.port'); - } - if ($github_app->installation_id && session('from')) { - $source_id = data_get(session('from'), 'source_id'); - if (!$source_id || $github_app->id !== $source_id) { - session()->forget('from'); - } else { - $parameters = data_get(session('from'), 'parameters'); - $back = data_get(session('from'), 'back'); - $environment_name = data_get($parameters, 'environment_name'); - $project_uuid = data_get($parameters, 'project_uuid'); - $type = data_get($parameters, 'type'); - $destination = data_get($parameters, 'destination'); - session()->forget('from'); - return redirect()->route($back, [ - 'environment_name' => $environment_name, - 'project_uuid' => $project_uuid, - 'type' => $type, - 'destination' => $destination, - ]); - } - } - return view('source.github.show', [ - 'github_app' => $github_app, - 'name' => $name, - 'ipv4' => $ipv4 ?? null, - 'ipv6' => $ipv6 ?? null, - 'fqdn' => $settings->fqdn, - ]); - })->name('source.github.show'); - + Route::get('/source/github/{github_app_uuid}', GitHubChange::class)->name('source.github.show'); Route::get('/source/gitlab/{gitlab_app_uuid}', function (Request $request) { $gitlab_app = GitlabApp::where('uuid', request()->gitlab_app_uuid)->first(); return view('source.gitlab.show', [ diff --git a/versions.json b/versions.json index 4ebbef973..cff2caaf6 100644 --- a/versions.json +++ b/versions.json @@ -4,7 +4,7 @@ "version": "3.12.36" }, "v4": { - "version": "4.0.0-beta.111" + "version": "4.0.0-beta.112" } } }