This commit is contained in:
Andras Bacsai 2023-05-08 21:56:44 +02:00
parent d3bf1137d7
commit ec3fe284b6
6 changed files with 68 additions and 20 deletions

View File

@ -55,7 +55,6 @@ public function mount()
$this->host = $settings->fqdn;
}
$this->parameters = getParameters();
$this->github_app = GithubApp::where('uuid', $this->parameters['github_app_uuid'])->first();
$this->is_system_wide = $this->github_app->is_system_wide;
}
public function createGithubApp()

View File

@ -22,6 +22,6 @@ static public function public()
}
static public function private()
{
return GithubApp::where('team_id', session('currentTeam')->id)->where('is_public', false)->get();
return GithubApp::where('team_id', session('currentTeam')->id)->where('is_public', false)->whereNotNull('app_id')->whereNotNull('installation_id')->get();
}
}

View File

@ -21,6 +21,8 @@
</head>
<body>
@livewireScripts
@auth
<x-navbar />
@endauth
@ -28,7 +30,6 @@
{{ $slot }}
</main>
@livewireScripts
@auth
<script>
function checkIfIamDead() {
@ -80,6 +81,7 @@ function checkHealth() {
})
</script>
@endauth
</body>
</html>

View File

@ -23,22 +23,9 @@
@else
<div class="py-2">
<x-inputs.button type="submit">Save</x-inputs.button>
</div>
@endif
</form>
<form x-data="ContactForm()" @submit.prevent="submitForm">
<x-inputs.input id="host" noLabel />
<button type="submit">Create GitHub Application</button>
</form>
<script>
function ContactForm() {
return {
host: "",
submitForm() {
console.log(JSON.stringify(this.host));
},
};
}
</script>
</div>

View File

@ -1,4 +1,53 @@
<x-layout>
<h1>GitHub App</h1>
<livewire:source.github.change :host="$host" />
<livewire:source.github.change :github_app="$github_app" />
<form x-data>
<x-inputs.button x-on:click.prevent="createGithubApp">Create GitHub Application</x-inputs.button>
</form>
<script>
function createGithubApp() {
const {
organization,
uuid,
html_url
} = @json($github_app);
const host = @js($host);
const name = @js($name);
let url = 'settings/apps/new';
if (organization) {
organization = `'organizations/${organization}/settings/apps/new`;
}
const data = {
name,
url: host,
hook_attributes: {
url: `${host}/webhooks/github/events`
},
redirect_url: `${host}/webhooks/github`,
callback_urls: [`${host}/login/github/app`],
public: false,
request_oauth_on_install: false,
setup_url: `${host}/webhooks/github/install?source=${uuid}`,
setup_on_update: true,
default_permissions: {
contents: 'read',
metadata: 'read',
pull_requests: 'read',
emails: 'read'
},
default_events: ['pull_request', 'push']
};
const form = document.createElement('form');
form.setAttribute('method', 'post');
form.setAttribute('action', `${html_url}/${url}?state=${uuid}`);
const input = document.createElement('input');
input.setAttribute('id', 'manifest');
input.setAttribute('name', 'manifest');
input.setAttribute('type', 'hidden');
input.setAttribute('value', data);
form.appendChild(input);
document.getElementsByTagName('body')[0].appendChild(form);
form.submit();
}
</script>
</x-layout>

View File

@ -13,6 +13,7 @@
use App\Models\Server;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Str;
/*
|--------------------------------------------------------------------------
@ -84,7 +85,17 @@
Route::middleware(['auth'])->group(function () {
Route::get('/source/new', fn () => view('source.new'))->name('source.new');
Route::get('/source/github/{github_app_uuid}', function (Request $request) {
return view('source.github.show', ['host' => $request->schemeAndHttpHost()]);
$settings = InstanceSettings::first();
$host = $request->schemeAndHttpHost();
if ($settings->fqdn) {
$host = $settings->fqdn;
}
$github_app = GithubApp::where('uuid', request()->github_app_uuid)->first();
return view('source.github.show', [
'github_app' => $github_app,
'host' => $host,
'name' => Str::kebab('coolify' . $github_app->name)
]);
})->name('source.github.show');
});
Route::middleware(['auth'])->group(function () {