diff --git a/.env.example b/.env.example index 16190dd..6b79944 100644 --- a/.env.example +++ b/.env.example @@ -59,4 +59,10 @@ VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" GITHUB_CLIENT_ID= GITHUB_CLIENT_SECRET= -GITHUB_REDIRECT= \ No newline at end of file +GITHUB_REDIRECT= + +DISCORD_APP_ID= +DISCORD_PUBLIC_KEY= +DISCORD_BOT_TOKEN= +DISCORD_GUILD_ID= +DISCORD_CODE_REVIEW_CHANNELS_ID= diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index e593d8a..2c803ec 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -21,4 +21,4 @@ jobs: run: | npm i -g @liara/cli@3 liara deploy --app="codereviewpals" --api-token="$LIARA_TOKEN" --detach - liara shell --app="codereviewpals" --api-token="$LIARA_TOKEN" --command="php artisan migrate --force && php artisan horizon:terminate --wait && php artisan discord:terminate" + liara shell --app="codereviewpals" --api-token="$LIARA_TOKEN" --command="bash deploy.sh" diff --git a/app/Actions/Channel/GetOrCreateAChannelByPullRequestAction.php b/app/Actions/Channel/GetOrCreateAChannelByPullRequestAction.php new file mode 100644 index 0000000..f8f4f7e --- /dev/null +++ b/app/Actions/Channel/GetOrCreateAChannelByPullRequestAction.php @@ -0,0 +1,38 @@ +repository->language; + + $channel = Channel::name($mainLang)->first(); + if ($channel instanceof Channel) { + return $channel; + } + $channelData = app(CreateChannel::class) + ->execute( + name: $mainLang, + channelType: ChannelType::FORUM, + parentId: config('services.discord.channels.code_reviews') + ) + ->dtoOrFail(); + + return Channel::create($channelData->toArray()); + } +} diff --git a/app/Actions/Discord/AddPullRequestCommandAction.php b/app/Actions/Discord/AddPullRequestCommandAction.php index 9c6fcd9..080a3d1 100644 --- a/app/Actions/Discord/AddPullRequestCommandAction.php +++ b/app/Actions/Discord/AddPullRequestCommandAction.php @@ -2,6 +2,7 @@ namespace App\Actions\Discord; +use App\Jobs\CreatePullRequestByUrlJob; use App\Models\User; use App\Services\Github\PullRequestService; use Discord\Builders\MessageBuilder; @@ -19,16 +20,12 @@ public function __invoke(Message $message, Discord $discord, array $matches) { $url = $matches[1] ?? ''; $user = $this->getUser($message->author); - try { - $this->service->createFromUrl($url, $user); - $message->reply( - "Thank you for your interest ❤️ \n Your Pull Request submitted successfully." - ); - } catch (\Throwable $th) { - $message->reply( - 'error occurred on creating PR. please check your URL and if everything is ok contact with admins 😉' - ); - } + + CreatePullRequestByUrlJob::dispatch($url, $user); + + $message->reply( + "Thank you for your interest ❤️ \n Your Pull Request submitted successfully." + ); } public function getUser(DiscordUser $discordUser): User diff --git a/app/Actions/Discord/Channels/CreateChannel.php b/app/Actions/Discord/Channels/CreateChannel.php new file mode 100644 index 0000000..610dbc2 --- /dev/null +++ b/app/Actions/Discord/Channels/CreateChannel.php @@ -0,0 +1,35 @@ +connector->send($request); + } +} diff --git a/app/Actions/Discord/CreateThreadFromPullRequest.php b/app/Actions/Discord/CreateThreadFromPullRequest.php new file mode 100644 index 0000000..690d221 --- /dev/null +++ b/app/Actions/Discord/CreateThreadFromPullRequest.php @@ -0,0 +1,39 @@ +repository; + $tags = $repository->topics; + $tags[] = $repository->language; + $message = $this->makeMessage($pullRequest); + $request = new CreateForumPost( + name: $pullRequest->title, + message: $message, + channelId: $channel->channel_id + ); + + return $this->connector->send($request); + } + + public function makeMessage(PullRequest $pullRequest): MessageObject + { + return new MessageObject('HELLO'); + } +} diff --git a/app/Actions/Discord/DiscordAction.php b/app/Actions/Discord/DiscordAction.php new file mode 100644 index 0000000..9e3df67 --- /dev/null +++ b/app/Actions/Discord/DiscordAction.php @@ -0,0 +1,15 @@ +connector = new DiscordAPIConnector; + } +} diff --git a/app/Actions/Github/Repository/CreateWebhook.php b/app/Actions/Github/Repository/CreateWebhook.php index 4bdb700..273831f 100644 --- a/app/Actions/Github/Repository/CreateWebhook.php +++ b/app/Actions/Github/Repository/CreateWebhook.php @@ -2,9 +2,7 @@ namespace App\Actions\Github\Repository; -use App\Models\Webhook; use ReflectionException; -use App\Models\Repository; use Saloon\Contracts\Response; use App\Actions\Github\GithubAction; use Saloon\Exceptions\PendingRequestException; @@ -20,12 +18,15 @@ class CreateWebhook * @throws ReflectionException * @throws PendingRequestException */ - public function execute(Repository $repository): Response - { + public function execute( + string $username, + string $repository, + string $secret, + ): Response { $request = new CreateRepositoryWebhook( - username: $repository->username, - repository: $repository->repository, - secret: $repository->node_id + username: $username, + repository: $repository, + secret: $secret, ); return $this->connector->send($request); diff --git a/app/Actions/Github/Repository/CreateWebhookFromRepository.php b/app/Actions/Github/Repository/CreateWebhookFromRepository.php new file mode 100644 index 0000000..e9108d0 --- /dev/null +++ b/app/Actions/Github/Repository/CreateWebhookFromRepository.php @@ -0,0 +1,37 @@ +execute( + username: $repository->username, + repository: $repository->repository_name, + secret: Hash::make($repository->node_id) + ) + ->dtoOrFail(); + + return $repository->webhooks()->save( + new Webhook([ + 'title' => $repository->full_name . ' hook', + 'hook_id' => $webhookData->id, + ]) + ); + } catch (Exception) { + return false; + } + } +} diff --git a/app/Actions/Github/Webhook/FetchWebhook.php b/app/Actions/Github/Webhook/FetchWebhook.php index 68bb0c8..748ebf8 100644 --- a/app/Actions/Github/Webhook/FetchWebhook.php +++ b/app/Actions/Github/Webhook/FetchWebhook.php @@ -42,7 +42,7 @@ public function getUsernameAndRepository(Repository|PullRequest $model): array if ($model instanceof Repository) { return [ 'username' => $model->username, - 'repository' => $model->repository, + 'repository' => $model->repository_name, ]; } return app(PullRequestService::class)->getRegexMatch($model->html_url); diff --git a/app/Actions/Repository/CreateRepositoryByPullRequest.php b/app/Actions/Repository/CreateRepositoryByPullRequest.php index 1f7ad2d..eca3b7c 100644 --- a/app/Actions/Repository/CreateRepositoryByPullRequest.php +++ b/app/Actions/Repository/CreateRepositoryByPullRequest.php @@ -23,7 +23,9 @@ public function __construct(protected RepositoryService $repositoryService) */ public function execute(PullRequest $pullRequest): Repository { - $repository = $this->repositoryService->getRepositoryByFullName($pullRequest->repository); + $repository = $this->repositoryService->getRepositoryByFullName( + $pullRequest->repository_name + ); if (!is_null($repository)) { return $repository; } diff --git a/app/Console/Commands/Discord/RunDiscordBotCommand.php b/app/Console/Commands/Discord/RunDiscordBotCommand.php index 2ac7fb9..75d8669 100644 --- a/app/Console/Commands/Discord/RunDiscordBotCommand.php +++ b/app/Console/Commands/Discord/RunDiscordBotCommand.php @@ -8,6 +8,7 @@ use Discord\WebSockets\Intents; use Illuminate\Console\Command; use Illuminate\Support\Facades\Cache; +use Illuminate\Support\Facades\Log; class RunDiscordBotCommand extends Command { @@ -64,6 +65,7 @@ protected function messageRouting(Message $inputMessage, Discord $discord) } continue; } + $inputMessage->reply('Your command is not valid.'); } private function storeProcess() diff --git a/app/Console/Commands/Discord/TerminateDiscordCommand.php b/app/Console/Commands/Discord/TerminateDiscordCommand.php index bffa5cc..701b68d 100644 --- a/app/Console/Commands/Discord/TerminateDiscordCommand.php +++ b/app/Console/Commands/Discord/TerminateDiscordCommand.php @@ -34,6 +34,8 @@ public function handle(): void posix_strerror(posix_get_last_error()) . ')' ); + return; } + cache()->delete(config('cache.discord.process_id')); } } diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 713e7cb..45df8e5 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -15,6 +15,7 @@ protected function schedule(Schedule $schedule): void $schedule->command('github:fetch-pull-request')->hourly(); $schedule->command('github:disable-unavailable-webhooks')->daily(); $schedule->command('queue:flush --hours=24')->daily(); + $schedule->command('horizon:snapshot')->everyFiveMinutes(); } /** diff --git a/app/DTO/Discord/ChannelData.php b/app/DTO/Discord/ChannelData.php new file mode 100644 index 0000000..ae517ac --- /dev/null +++ b/app/DTO/Discord/ChannelData.php @@ -0,0 +1,23 @@ +channelId); + } + + protected function defaultBody(): array + { + return [ + 'auto_archive_duration' => config('services.discord.configs.auto_archive_time'), + 'name' => $this->name, + 'message' => $this->message, + 'applied_tags' => $this->tags, + ]; + } + + /** + * @param Response $response + * + * @return ChannelData + */ + public function createDtoFromResponse(Response $response): ForumThreadData + { + return ForumThreadData::from($response->collect()); + } +} diff --git a/app/Http/Integrations/Discord/Channel/Requests/CreateGuildChannel.php b/app/Http/Integrations/Discord/Channel/Requests/CreateGuildChannel.php new file mode 100644 index 0000000..fcaeab0 --- /dev/null +++ b/app/Http/Integrations/Discord/Channel/Requests/CreateGuildChannel.php @@ -0,0 +1,60 @@ + $this->name, + 'type' => $this->channelType->value, + 'parent_id' => $this->parentId, + ]; + } + + /** + * @param Response $response + * + * @return ChannelData + */ + public function createDtoFromResponse(Response $response): ChannelData + { + return ChannelData::from($response->collect()); + } +} diff --git a/app/Http/Integrations/Discord/DiscordAPIConnector.php b/app/Http/Integrations/Discord/DiscordAPIConnector.php new file mode 100644 index 0000000..d21f484 --- /dev/null +++ b/app/Http/Integrations/Discord/DiscordAPIConnector.php @@ -0,0 +1,48 @@ + 'application/json', + 'Content-Type' => 'application/json', + ]; + } + + /** + * @return TokenAuthenticator + */ + protected function defaultAuth(): TokenAuthenticator + { + return new TokenAuthenticator( + token: (string)config('services.discord.bot_token'), + prefix: 'Bot' + ); + } +} diff --git a/app/Http/Integrations/Github/GithubApiConnector.php b/app/Http/Integrations/Github/GithubApiConnector.php index 2ec9146..8cd2e9f 100644 --- a/app/Http/Integrations/Github/GithubApiConnector.php +++ b/app/Http/Integrations/Github/GithubApiConnector.php @@ -23,7 +23,7 @@ class GithubApiConnector extends Connector */ public function resolveBaseUrl(): string { - return (string) config('github.api.base_path'); + return (string) config('services.github.base_path'); } /** diff --git a/app/Jobs/CreatePullRequestByUrlJob.php b/app/Jobs/CreatePullRequestByUrlJob.php new file mode 100644 index 0000000..f60394d --- /dev/null +++ b/app/Jobs/CreatePullRequestByUrlJob.php @@ -0,0 +1,32 @@ +createFromUrl($this->url, $this->user); + } +} diff --git a/app/Jobs/Discord/Channels/CreateThreadFromPullRequestJob.php b/app/Jobs/Discord/Channels/CreateThreadFromPullRequestJob.php new file mode 100644 index 0000000..2f54106 --- /dev/null +++ b/app/Jobs/Discord/Channels/CreateThreadFromPullRequestJob.php @@ -0,0 +1,45 @@ +execute($this->pullRequest); + + app(CreateThreadFromPullRequest::class)->execute($this->pullRequest, $channel); + } +} diff --git a/app/Jobs/Github/Repository/CreateWebhookFromRepositoryJob.php b/app/Jobs/Github/Repository/CreateWebhookFromRepositoryJob.php new file mode 100644 index 0000000..069d896 --- /dev/null +++ b/app/Jobs/Github/Repository/CreateWebhookFromRepositoryJob.php @@ -0,0 +1,31 @@ +execute($this->repository); + } +} diff --git a/app/Jobs/Github/Repository/FetchAllPullRequestFromRepository.php b/app/Jobs/Github/Repository/FetchAllPullRequestFromRepository.php index ca0e985..22a73f2 100644 --- a/app/Jobs/Github/Repository/FetchAllPullRequestFromRepository.php +++ b/app/Jobs/Github/Repository/FetchAllPullRequestFromRepository.php @@ -35,7 +35,7 @@ public function handle(): void $pullRequests = app(GetAllPullRequest::class) ->execute( username: $this->repository->username, - repository: $this->repository->repository + repository: $this->repository->repository_name ) ->dtoOrFail(); diff --git a/app/Models/Channel.php b/app/Models/Channel.php new file mode 100644 index 0000000..7021f98 --- /dev/null +++ b/app/Models/Channel.php @@ -0,0 +1,23 @@ + ChannelType::class, + ]; + + public function scopeName(Builder $query, string $name): Builder + { + return $query->where('name', $name); + } +} diff --git a/app/Models/PullRequest.php b/app/Models/PullRequest.php index 8227300..6bdc0e7 100644 --- a/app/Models/PullRequest.php +++ b/app/Models/PullRequest.php @@ -17,12 +17,13 @@ class PullRequest extends Model */ protected $fillable = [ 'node_id', - 'repository', + 'repository_name', 'title', 'html_url', 'status', 'description', 'user_id', + 'repository_id', ]; /** @@ -39,4 +40,9 @@ public function user(): BelongsTo { return $this->belongsTo(User::class); } + + public function repository(): BelongsTo + { + return $this->belongsTo(Repository::class); + } } diff --git a/app/Models/Repository.php b/app/Models/Repository.php index e8d9b95..0f28998 100644 --- a/app/Models/Repository.php +++ b/app/Models/Repository.php @@ -3,10 +3,13 @@ namespace App\Models; use App\Concerns\Model\HasPermissions; +use App\Enums\Discord\ChannelType; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\Casts\Attribute; +use Illuminate\Database\Eloquent\Relations\HasOne; +use Illuminate\Database\Eloquent\Relations\MorphOne; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\MorphMany; @@ -26,12 +29,17 @@ class Repository extends Model 'description', 'language', 'html_url', + 'topics', + ]; + + protected $casts = [ + 'topics' => 'array', ]; /** * @var string[] */ - protected $appends = ['username', 'repository']; + protected $appends = ['username', 'repository_name']; /** * @return BelongsTo @@ -49,6 +57,26 @@ public function webhooks(): MorphMany return $this->morphMany(Webhook::class, 'webhookable'); } + /** + * @return MorphMany + */ + public function channels(): MorphMany + { + return $this->morphMany(Channel::class, 'channelable'); + } + + /** + * @return MorphOne + */ + public function threadChannel(): MorphOne + { + return $this->morphOne(Channel::class, 'channelable')->ofMany([], function ( + Builder $query + ) { + $query->whereType(ChannelType::FORUM); + }); + } + /** * @return Attribute */ @@ -60,7 +88,7 @@ public function username(): Attribute /** * @return Attribute */ - public function repository(): Attribute + public function repositoryName(): Attribute { return Attribute::make(get: fn() => explode('/', $this->full_name)[1]); } diff --git a/app/Observers/PullRequestObserver.php b/app/Observers/PullRequestObserver.php index d3aee37..f6bda1b 100644 --- a/app/Observers/PullRequestObserver.php +++ b/app/Observers/PullRequestObserver.php @@ -5,6 +5,7 @@ use App\Models\PullRequest; use App\Actions\PullRequest\GenerateRepositoryName; use App\Actions\Repository\CreateRepositoryByPullRequest; +use App\Jobs\Discord\Channels\CreateThreadFromPullRequestJob; class PullRequestObserver { @@ -13,10 +14,12 @@ class PullRequestObserver */ public function created(PullRequest $pullRequest): void { - $pullRequest->repository = app(GenerateRepositoryName::class)->execute($pullRequest); + $pullRequest->repository_name = app(GenerateRepositoryName::class)->execute($pullRequest); $repository = app(CreateRepositoryByPullRequest::class)->execute($pullRequest); $pullRequest->repository_id = $repository->id; $pullRequest->saveQuietly(); + + CreateThreadFromPullRequestJob::dispatch($pullRequest); } /** diff --git a/app/Observers/RepositoryObserver.php b/app/Observers/RepositoryObserver.php index 782dc8e..e66ee65 100644 --- a/app/Observers/RepositoryObserver.php +++ b/app/Observers/RepositoryObserver.php @@ -3,11 +3,9 @@ namespace App\Observers; use Exception; -use App\Models\Webhook; use App\Models\Repository; -use App\Actions\Github\Repository\CreateWebhook; use App\Actions\Github\Repository\DeleteWebhookFromRepository; -use App\DTO\Github\Repository\Webhook\WebhookCreatedData; +use App\Jobs\Github\Repository\CreateWebhookFromRepositoryJob; class RepositoryObserver { @@ -24,21 +22,7 @@ public function restoring(Repository $repository): bool */ public function created(Repository $repository): void { - try { - /** @var WebhookCreatedData $webhookData */ - $webhookData = app(CreateWebhook::class) - ->execute($repository) - ->dtoOrFail(); - - $repository->webhooks()->save( - new Webhook([ - 'title' => $repository->full_name . ' hook', - 'hook_id' => $webhookData->id, - ]) - ); - } catch (Exception $e) { - return; - } + CreateWebhookFromRepositoryJob::dispatch($repository); } /** diff --git a/app/Providers/HorizonServiceProvider.php b/app/Providers/HorizonServiceProvider.php index 76c42e5..9d30bdf 100644 --- a/app/Providers/HorizonServiceProvider.php +++ b/app/Providers/HorizonServiceProvider.php @@ -30,9 +30,7 @@ public function boot(): void protected function gate(): void { Gate::define('viewHorizon', function ($user) { - return in_array($user->email, [ - // - ]); + return in_array($user->email, config('horizon.admins', [])); }); } } diff --git a/app/Services/Github/PullRequestService.php b/app/Services/Github/PullRequestService.php index dea69d3..5fa811e 100644 --- a/app/Services/Github/PullRequestService.php +++ b/app/Services/Github/PullRequestService.php @@ -71,9 +71,7 @@ public function createFromUrl(string $url, User $user): ?PullRequest { $pullRequestData = $this->getDataFromUrl(url: $url); - if (!$pullRequestData instanceof PullRequestData) { - exit(); - } + throw_if(!$pullRequestData instanceof PullRequestData, 'invalid pull request'); return app(CreatePullRequest::class)->execute( pullRequestData: $pullRequestData, diff --git a/composer.json b/composer.json index 4999499..877464c 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "guzzlehttp/guzzle": "^7.2", "inertiajs/inertia-laravel": "^0.6.3", "laravel/framework": "^10.0", - "laravel/horizon": "^5.15", + "laravel/horizon": "^5.16", "laravel/sanctum": "^3.2", "laravel/socialite": "^5.6", "laravel/tinker": "^2.8", diff --git a/composer.lock b/composer.lock index f4ba6cf..e4d2d1f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "e845e16fa7d4738fbc00528e735bf5a4", + "content-hash": "8dff9937ea21c4bc1a3dff592f985f45", "packages": [ { "name": "brick/math", @@ -1501,16 +1501,16 @@ }, { "name": "laravel/horizon", - "version": "v5.15.0", + "version": "v5.16.1", "source": { "type": "git", "url": "https://github.com/laravel/horizon.git", - "reference": "b49be302566365e0e4d517aac9995a8fe20b580e" + "reference": "ddd6a49063ba3bdfdf5f8ce885d27a8368ad03c4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/horizon/zipball/b49be302566365e0e4d517aac9995a8fe20b580e", - "reference": "b49be302566365e0e4d517aac9995a8fe20b580e", + "url": "https://api.github.com/repos/laravel/horizon/zipball/ddd6a49063ba3bdfdf5f8ce885d27a8368ad03c4", + "reference": "ddd6a49063ba3bdfdf5f8ce885d27a8368ad03c4", "shasum": "" }, "require": { @@ -1573,9 +1573,9 @@ ], "support": { "issues": "https://github.com/laravel/horizon/issues", - "source": "https://github.com/laravel/horizon/tree/v5.15.0" + "source": "https://github.com/laravel/horizon/tree/v5.16.1" }, - "time": "2023-03-07T17:45:21+00:00" + "time": "2023-05-29T15:03:42+00:00" }, { "name": "laravel/sanctum", diff --git a/config/app.php b/config/app.php index ef76a7e..e01fa28 100644 --- a/config/app.php +++ b/config/app.php @@ -193,6 +193,7 @@ App\Providers\AuthServiceProvider::class, // App\Providers\BroadcastServiceProvider::class, App\Providers\EventServiceProvider::class, + App\Providers\HorizonServiceProvider::class, App\Providers\RouteServiceProvider::class, ], diff --git a/config/github.php b/config/github.php deleted file mode 100644 index 9a105d1..0000000 --- a/config/github.php +++ /dev/null @@ -1,7 +0,0 @@ - [ - 'base_path' => env('GITHUB_API_BASEPATH', 'https://api.github.com/'), - ] -]; \ No newline at end of file diff --git a/config/horizon.php b/config/horizon.php index 5101f6f..2167f5c 100644 --- a/config/horizon.php +++ b/config/horizon.php @@ -3,7 +3,6 @@ use Illuminate\Support\Str; return [ - /* |-------------------------------------------------------------------------- | Horizon Domain @@ -54,10 +53,7 @@ | */ - 'prefix' => env( - 'HORIZON_PREFIX', - Str::slug(env('APP_NAME', 'laravel'), '_').'_horizon:' - ), + 'prefix' => env('HORIZON_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_') . '_horizon:'), /* |-------------------------------------------------------------------------- @@ -210,4 +206,6 @@ ], ], ], + + 'admins' => ['geeksesi@gmail.com'], ]; diff --git a/config/logging.php b/config/logging.php index c44d276..389d873 100644 --- a/config/logging.php +++ b/config/logging.php @@ -54,7 +54,7 @@ 'channels' => [ 'stack' => [ 'driver' => 'stack', - 'channels' => ['single'], + 'channels' => ['single', 'stderr', 'errorlog', 'syslog'], 'ignore_exceptions' => false, ], diff --git a/config/services.php b/config/services.php index 0436fca..178f069 100644 --- a/config/services.php +++ b/config/services.php @@ -1,7 +1,6 @@ [ - 'client_id' => env('GITHUB_CLIENT_ID'), + 'client_id' => env('GITHUB_CLIENT_ID'), 'client_secret' => env('GITHUB_CLIENT_SECRET'), - 'redirect' => env('GITHUB_REDIRECT'), - 'scopes' => env('GITHUB_SCOPES', 'admin:repo_hook'), - 'base_path' => env('GITHUB_API_BASEPATH', 'https://api.github.com/'), + 'redirect' => env('GITHUB_REDIRECT'), + 'scopes' => env('GITHUB_SCOPES', 'admin:repo_hook'), + 'base_path' => env('GITHUB_API_BASEPATH', 'https://api.github.com/'), ], 'discord' => [ - 'app_id' => env('DISCORD_APP_ID'), + 'app_id' => env('DISCORD_APP_ID'), 'public_key' => env('DISCORD_PUBLIC_KEY'), - 'bot_token' => env('DISCORD_BOT_TOKEN'), - 'guild_id' => env('DISCORD_GUILD_ID'), - 'channels' => [ + 'bot_token' => env('DISCORD_BOT_TOKEN'), + 'guild_id' => env('DISCORD_GUILD_ID'), + 'channels' => [ 'code_reviews' => env('DISCORD_CODE_REVIEW_CHANNELS_ID'), ], - 'base_path' => env('DISCORD_API_BASEPATH', 'https://discord.com/api/v10/') + 'base_path' => env('DISCORD_API_BASEPATH', 'https://discord.com/api/v10/'), ], - ]; diff --git a/database/migrations/2023_04_16_141842_create_channels_table.php b/database/migrations/2023_04_16_141842_create_channels_table.php new file mode 100644 index 0000000..cdc1fa7 --- /dev/null +++ b/database/migrations/2023_04_16_141842_create_channels_table.php @@ -0,0 +1,34 @@ +id(); + $table->string('channel_id'); + $table->string('parent_id')->nullable(); + $table->string('guild_id')->nullable(); + /** @see ChannelType */ + $table->integer('type'); + $table->string('name'); + $table->morphs('channelable'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('channels'); + } +}; diff --git a/database/migrations/2023_06_18_102733_change_repository_to_repository_name_on_pull_requests_table.php b/database/migrations/2023_06_18_102733_change_repository_to_repository_name_on_pull_requests_table.php new file mode 100644 index 0000000..da912aa --- /dev/null +++ b/database/migrations/2023_06_18_102733_change_repository_to_repository_name_on_pull_requests_table.php @@ -0,0 +1,27 @@ +renameColumn('repository', 'repository_name')->change(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('pull_requests', function (Blueprint $table) { + $table->renameColumn('repository_name', 'repository')->change(); + }); + } +}; diff --git a/database/migrations/2023_06_18_155908_add_topics_to_repositories_table.php b/database/migrations/2023_06_18_155908_add_topics_to_repositories_table.php new file mode 100644 index 0000000..2cb42f3 --- /dev/null +++ b/database/migrations/2023_06_18_155908_add_topics_to_repositories_table.php @@ -0,0 +1,27 @@ +json('topics')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('repositories', function (Blueprint $table) { + $table->dropColumn('topics'); + }); + } +}; diff --git a/database/migrations/2023_06_18_160726_change_description_to_pull_requests_table.php b/database/migrations/2023_06_18_160726_change_description_to_pull_requests_table.php new file mode 100644 index 0000000..c27500d --- /dev/null +++ b/database/migrations/2023_06_18_160726_change_description_to_pull_requests_table.php @@ -0,0 +1,27 @@ +text('description')->change(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('pull_requests', function (Blueprint $table) { + $table->string('description')->change(); + }); + } +}; diff --git a/database/migrations/2023_06_18_161328_create_jobs_table.php b/database/migrations/2023_06_18_161328_create_jobs_table.php new file mode 100644 index 0000000..6098d9b --- /dev/null +++ b/database/migrations/2023_06_18_161328_create_jobs_table.php @@ -0,0 +1,32 @@ +bigIncrements('id'); + $table->string('queue')->index(); + $table->longText('payload'); + $table->unsignedTinyInteger('attempts'); + $table->unsignedInteger('reserved_at')->nullable(); + $table->unsignedInteger('available_at'); + $table->unsignedInteger('created_at'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('jobs'); + } +}; diff --git a/database/migrations/2023_06_18_163222_remove_channelable_to_channels_table.php b/database/migrations/2023_06_18_163222_remove_channelable_to_channels_table.php new file mode 100644 index 0000000..05d1b4e --- /dev/null +++ b/database/migrations/2023_06_18_163222_remove_channelable_to_channels_table.php @@ -0,0 +1,27 @@ +dropMorphs('channelable'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('channels', function (Blueprint $table) { + $table->morphs('channelable'); + }); + } +}; diff --git a/database/seeders/ChannelSeeder.php b/database/seeders/ChannelSeeder.php new file mode 100644 index 0000000..dc7a28f --- /dev/null +++ b/database/seeders/ChannelSeeder.php @@ -0,0 +1,22 @@ +