diff --git a/app/Jobs/SyncPluginReleases.php b/app/Jobs/SyncPluginReleases.php index 4fdd6317..513ef871 100644 --- a/app/Jobs/SyncPluginReleases.php +++ b/app/Jobs/SyncPluginReleases.php @@ -78,7 +78,17 @@ public function handle(SatisService $satisService): void } } - $this->plugin->update(['last_synced_at' => now()]); + $updateData = ['last_synced_at' => now()]; + + if ($this->hasNewReleases) { + $latestVersion = $this->plugin->versions()->latest('published_at')->first(); + + if ($latestVersion) { + $updateData['latest_version'] = $latestVersion->version; + } + } + + $this->plugin->update($updateData); Log::info('[SyncPluginReleases] Processing complete', [ 'plugin_id' => $this->plugin->id, diff --git a/package-lock.json b/package-lock.json index 1205e7c4..445d43ad 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "eager-ferret", + "name": "proud-mole", "lockfileVersion": 3, "requires": true, "packages": { diff --git a/tests/Feature/Jobs/SyncPluginReleasesTest.php b/tests/Feature/Jobs/SyncPluginReleasesTest.php new file mode 100644 index 00000000..d5d8ee87 --- /dev/null +++ b/tests/Feature/Jobs/SyncPluginReleasesTest.php @@ -0,0 +1,93 @@ + Http::response([ + [ + 'id' => 1, + 'tag_name' => 'v1.0.0', + 'body' => 'Initial release', + 'target_commitish' => 'abc123', + 'published_at' => '2026-01-01T00:00:00Z', + ], + [ + 'id' => 2, + 'tag_name' => 'v1.1.0', + 'body' => 'New features', + 'target_commitish' => 'def456', + 'published_at' => '2026-02-01T00:00:00Z', + ], + ]), + ]); + + $plugin = Plugin::factory()->create([ + 'name' => 'acme/test-plugin', + 'repository_url' => 'https://github.com/acme/test-plugin', + 'latest_version' => '0.9.0', + ]); + + $satisService = $this->mock(SatisService::class); + + $job = new SyncPluginReleases($plugin, triggerSatisBuild: false); + $job->handle($satisService); + + $plugin->refresh(); + + $this->assertEquals('1.1.0', $plugin->latest_version); + $this->assertCount(2, $plugin->versions); + } + + public function test_it_does_not_update_latest_version_when_no_new_releases(): void + { + Http::fake([ + 'api.github.com/repos/acme/test-plugin/releases*' => Http::response([ + [ + 'id' => 1, + 'tag_name' => 'v1.0.0', + 'body' => 'Initial release', + 'target_commitish' => 'abc123', + 'published_at' => '2026-01-01T00:00:00Z', + ], + ]), + ]); + + $plugin = Plugin::factory()->create([ + 'name' => 'acme/test-plugin', + 'repository_url' => 'https://github.com/acme/test-plugin', + 'latest_version' => '1.0.0', + ]); + + // Pre-create the version so nothing is "new" + PluginVersion::create([ + 'plugin_id' => $plugin->id, + 'version' => '1.0.0', + 'tag_name' => 'v1.0.0', + 'github_release_id' => '1', + 'published_at' => '2026-01-01T00:00:00Z', + ]); + + $satisService = $this->mock(SatisService::class); + + $job = new SyncPluginReleases($plugin, triggerSatisBuild: false); + $job->handle($satisService); + + $plugin->refresh(); + + $this->assertEquals('1.0.0', $plugin->latest_version); + } +}