syncData(); $this->getPrivateKeys(); } catch (\Throwable $e) { handleError($e, $this); } } public function syncData(bool $toModel = false) { if ($toModel) { $this->validate(); $this->application->update([ 'git_repository' => $this->gitRepository, 'git_branch' => $this->gitBranch, 'git_commit_sha' => $this->gitCommitSha, 'private_key_id' => $this->privateKeyId, ]); } else { $this->gitRepository = $this->application->git_repository; $this->gitBranch = $this->application->git_branch; $this->gitCommitSha = $this->application->git_commit_sha; $this->privateKeyId = $this->application->private_key_id; $this->privateKeyName = data_get($this->application, 'private_key.name'); } } private function getPrivateKeys() { $this->privateKeys = PrivateKey::whereTeamId(currentTeam()->id)->get()->reject(function ($key) { return $key->id == $this->privateKeyId; }); } public function setPrivateKey(int $privateKeyId) { try { $this->privateKeyId = $privateKeyId; $this->syncData(true); $this->getPrivateKeys(); $this->application->refresh(); $this->privateKeyName = $this->application->private_key->name; $this->dispatch('success', 'Private key updated!'); } catch (\Throwable $e) { return handleError($e, $this); } } public function submit() { try { if (str($this->gitCommitSha)->isEmpty()) { $this->gitCommitSha = 'HEAD'; } $this->syncData(true); $this->dispatch('success', 'Application source updated!'); } catch (\Throwable $e) { return handleError($e, $this); } } }