From 79d4c0c6d2284320973c4ee09496ba8bec44c40a Mon Sep 17 00:00:00 2001 From: arthurbazzz Date: Wed, 24 Jun 2026 10:47:56 -0300 Subject: [PATCH 1/3] feat(integration-github): add repository purpose filtering --- ...d_purpose_to_github_repositories_table.php | 17 +++++++++ .../src/Models/GithubRepository.php | 1 + .../src/Webhook/ProjectGithubEvent.php | 1 + .../tests/Feature/GithubWebhookTest.php | 38 +++++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 app-modules/integration-github/database/migrations/2026_06_24_125428_add_purpose_to_github_repositories_table.php diff --git a/app-modules/integration-github/database/migrations/2026_06_24_125428_add_purpose_to_github_repositories_table.php b/app-modules/integration-github/database/migrations/2026_06_24_125428_add_purpose_to_github_repositories_table.php new file mode 100644 index 00000000..e769772c --- /dev/null +++ b/app-modules/integration-github/database/migrations/2026_06_24_125428_add_purpose_to_github_repositories_table.php @@ -0,0 +1,17 @@ +string('purpose')->default('contributions'); + }); + } +}; diff --git a/app-modules/integration-github/src/Models/GithubRepository.php b/app-modules/integration-github/src/Models/GithubRepository.php index 0c4181dd..de13211a 100644 --- a/app-modules/integration-github/src/Models/GithubRepository.php +++ b/app-modules/integration-github/src/Models/GithubRepository.php @@ -21,6 +21,7 @@ * @property string $tenant_id * @property string $full_name * @property bool $enabled + * @property string $purpose * @property CarbonInterface|null $last_backfilled_at * @property CarbonInterface|null $created_at * @property CarbonInterface|null $updated_at diff --git a/app-modules/integration-github/src/Webhook/ProjectGithubEvent.php b/app-modules/integration-github/src/Webhook/ProjectGithubEvent.php index 946a8725..e64051cf 100644 --- a/app-modules/integration-github/src/Webhook/ProjectGithubEvent.php +++ b/app-modules/integration-github/src/Webhook/ProjectGithubEvent.php @@ -56,6 +56,7 @@ private function tenantsTracking(string $repo): array return array_values(GithubRepository::query() ->enabled() ->where('full_name', $repo) + ->where('purpose', 'contributions') ->pluck('tenant_id') ->map(static fn (mixed $tenantId): string => (string) $tenantId) ->all()); diff --git a/app-modules/integration-github/tests/Feature/GithubWebhookTest.php b/app-modules/integration-github/tests/Feature/GithubWebhookTest.php index 6cae2617..26a21e5e 100644 --- a/app-modules/integration-github/tests/Feature/GithubWebhookTest.php +++ b/app-modules/integration-github/tests/Feature/GithubWebhookTest.php @@ -159,3 +159,41 @@ function prWebhookPayload(string $repo = 'he4rt/heartdevs.com', int $number = 1, expect(GithubContribution::query()->where('external_ref', 'issue:10')->exists())->toBeTrue() ->and(GithubContribution::query()->where('external_ref', 'commit:sha1')->exists())->toBeTrue(); }); + +it('grava no lake mas NÃO projeta contribuição para repo de challenge', function (): void { + Event::fake([GithubContributionRecorded::class]); + + GithubRepository::factory()->create([ + 'full_name' => 'he4rt/heartdevs.com', + 'purpose' => 'challenge', + ]); + + postGithubWebhook('pull_request', prWebhookPayload())->assertSuccessful(); + + expect(GithubEventLog::query()->count())->toBe(1) + ->and(GithubContribution::query()->count())->toBe(0); + + Event::assertNotDispatched(GithubContributionRecorded::class); +}); + +it('grava no lake e projeta a contribuição para repo de contributions, emitindo o evento', function (): void { + Event::fake([GithubContributionRecorded::class]); + + $repo = GithubRepository::factory()->create([ + 'full_name' => 'he4rt/heartdevs.com', + 'purpose' => 'contributions', + ]); + + postGithubWebhook('pull_request', prWebhookPayload())->assertSuccessful(); + + expect(GithubEventLog::query()->count())->toBe(1); + + $contribution = GithubContribution::query()->where('external_ref', 'pr:1')->sole(); + + expect($contribution->type)->toBe(ContributionType::Pr) + ->and($contribution->tenant_id)->toBe($repo->tenant_id) + ->and($contribution->actor_login)->toBe('maria') + ->and($contribution->metadata['additions'])->toBe(5); + + Event::assertDispatched(GithubContributionRecorded::class); +}); From 896834ecf579ba14fe9e20ef07522769b155030b Mon Sep 17 00:00:00 2001 From: arthurbazzz Date: Fri, 26 Jun 2026 21:12:25 -0300 Subject: [PATCH 2/3] feat(integration-github): add repository purpose enum and filtering --- .../database/factories/GithubRepositoryFactory.php | 2 ++ ...25428_add_purpose_to_github_repositories_table.php | 5 ++++- .../integration-github/src/Enums/PurposeType.php | 11 +++++++++++ .../src/Models/GithubRepository.php | 2 +- .../src/Webhook/ProjectGithubEvent.php | 3 ++- .../tests/Feature/GithubWebhookTest.php | 5 +++-- 6 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 app-modules/integration-github/src/Enums/PurposeType.php diff --git a/app-modules/integration-github/database/factories/GithubRepositoryFactory.php b/app-modules/integration-github/database/factories/GithubRepositoryFactory.php index eb09c0c1..374c7d25 100644 --- a/app-modules/integration-github/database/factories/GithubRepositoryFactory.php +++ b/app-modules/integration-github/database/factories/GithubRepositoryFactory.php @@ -5,6 +5,7 @@ namespace He4rt\IntegrationGithub\Database\Factories; use He4rt\Identity\Tenant\Models\Tenant; +use He4rt\IntegrationGithub\Enums\PurposeType; use He4rt\IntegrationGithub\Models\GithubRepository; use Illuminate\Database\Eloquent\Factories\Factory; @@ -25,6 +26,7 @@ public function definition(): array 'full_name' => 'he4rt/'.fake()->unique()->slug(2), 'enabled' => true, 'last_backfilled_at' => null, + 'purpose' => PurposeType::Contributions->value, ]; } diff --git a/app-modules/integration-github/database/migrations/2026_06_24_125428_add_purpose_to_github_repositories_table.php b/app-modules/integration-github/database/migrations/2026_06_24_125428_add_purpose_to_github_repositories_table.php index e769772c..f759ca1c 100644 --- a/app-modules/integration-github/database/migrations/2026_06_24_125428_add_purpose_to_github_repositories_table.php +++ b/app-modules/integration-github/database/migrations/2026_06_24_125428_add_purpose_to_github_repositories_table.php @@ -4,6 +4,7 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; return new class extends Migration @@ -11,7 +12,9 @@ public function up(): void { Schema::table('github_repositories', static function (Blueprint $table): void { - $table->string('purpose')->default('contributions'); + $table->string('purpose')->nullable(); }); + + DB::table('github_repositories')->update(['purpose' => 'contributions']); } }; diff --git a/app-modules/integration-github/src/Enums/PurposeType.php b/app-modules/integration-github/src/Enums/PurposeType.php new file mode 100644 index 00000000..a8ea3475 --- /dev/null +++ b/app-modules/integration-github/src/Enums/PurposeType.php @@ -0,0 +1,11 @@ +enabled() ->where('full_name', $repo) - ->where('purpose', 'contributions') + ->where('purpose', PurposeType::Contributions->value) ->pluck('tenant_id') ->map(static fn (mixed $tenantId): string => (string) $tenantId) ->all()); diff --git a/app-modules/integration-github/tests/Feature/GithubWebhookTest.php b/app-modules/integration-github/tests/Feature/GithubWebhookTest.php index 26a21e5e..6b46aa0d 100644 --- a/app-modules/integration-github/tests/Feature/GithubWebhookTest.php +++ b/app-modules/integration-github/tests/Feature/GithubWebhookTest.php @@ -3,6 +3,7 @@ declare(strict_types=1); use He4rt\IntegrationGithub\Enums\ContributionType; +use He4rt\IntegrationGithub\Enums\PurposeType; use He4rt\IntegrationGithub\Events\GithubContributionRecorded; use He4rt\IntegrationGithub\Models\GithubContribution; use He4rt\IntegrationGithub\Models\GithubEventLog; @@ -165,7 +166,7 @@ function prWebhookPayload(string $repo = 'he4rt/heartdevs.com', int $number = 1, GithubRepository::factory()->create([ 'full_name' => 'he4rt/heartdevs.com', - 'purpose' => 'challenge', + 'purpose' => PurposeType::Challenge->value, ]); postGithubWebhook('pull_request', prWebhookPayload())->assertSuccessful(); @@ -181,7 +182,7 @@ function prWebhookPayload(string $repo = 'he4rt/heartdevs.com', int $number = 1, $repo = GithubRepository::factory()->create([ 'full_name' => 'he4rt/heartdevs.com', - 'purpose' => 'contributions', + 'purpose' => PurposeType::Contributions->value, ]); postGithubWebhook('pull_request', prWebhookPayload())->assertSuccessful(); From 80967c2b7f46720a83eef9e9e3a462a3d49b0f9f Mon Sep 17 00:00:00 2001 From: arthurbazzz Date: Fri, 26 Jun 2026 21:20:15 -0300 Subject: [PATCH 3/3] fix(integration-github): add enum import in repository --- app-modules/integration-github/src/Models/GithubRepository.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app-modules/integration-github/src/Models/GithubRepository.php b/app-modules/integration-github/src/Models/GithubRepository.php index 8f16d593..2a590513 100644 --- a/app-modules/integration-github/src/Models/GithubRepository.php +++ b/app-modules/integration-github/src/Models/GithubRepository.php @@ -7,6 +7,7 @@ use Carbon\CarbonInterface; use He4rt\Identity\Tenant\Models\Tenant; use He4rt\IntegrationGithub\Database\Factories\GithubRepositoryFactory; +use He4rt\IntegrationGithub\Enums\PurposeType; use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Casts\Attribute;