Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show support for current Nova version #206

Merged
merged 14 commits into from
May 6, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,5 @@ SLACK_HORIZON_WEBHOOK_URL=

HORIZON_USER_EMAILS=
BUGSNAG_API_KEY=

NOVA_LATEST_MAJOR_VERSION=4
3 changes: 3 additions & 0 deletions app/Http/Livewire/PackageList.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ public function renderPackageList()
case 'popular':
$packages = Package::popular();
break;
case 'nova_current':
$packages = Package::novaCurrent();
break;
default:
$packages = Package::tagged($this->tag);
break;
Expand Down
11 changes: 11 additions & 0 deletions app/Http/Resources/PackageDetailResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ public function toArray($package)

if (! is_null($packagistData)) {
$composer_latest = $this->extractStableVersionsFromPackages($packagistData)->first();

if (! is_null($composer_latest)) {
$composer_requirements = $composer_latest['require'];
RhysLees marked this conversation as resolved.
Show resolved Hide resolved

if (! is_null($composer_requirements)) {
if (array_key_exists("laravel/nova", $composer_requirements)){
$novaVersion = $composer_requirements["laravel/nova"];
}
}
}
}
} catch (PackagistException $e) {
}
Expand Down Expand Up @@ -58,6 +68,7 @@ public function toArray($package)
'tags' => TagResource::from($package->tags),
'is_favorite' => $this->isFavorite($package),
'favorites_count' => $this->favoritesCount($package),
'nova_version' => $novaVersion ?? null,
]);
}

Expand Down
1 change: 1 addition & 0 deletions app/Http/Resources/PackageResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function toArray($package)
'avatar_url' => $package->author->avatar ?: 'https://api.adorable.io/avatars/285/'.Str::slug($package->author->name).'.png',
'github_username' => $package->author->github_username,
],
'nova_version' => $package->nova_version ?? null,
];
}

Expand Down
35 changes: 34 additions & 1 deletion app/Jobs/SyncPackagePackagistData.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,31 @@ public function handle()
{
try {
$packagistData = Packagist::make($this->package->composer_name)->data();

$novaVersion = null;

if (! is_null($packagistData)) {
$composer_latest = $this->extractStableVersionsFromPackages($packagistData)->first();
RhysLees marked this conversation as resolved.
Show resolved Hide resolved

RhysLees marked this conversation as resolved.
Show resolved Hide resolved

if (! is_null($composer_latest)) {
$composer_requirements = $composer_latest['require'];

if (! is_null($composer_requirements)) {
if (array_key_exists("laravel/nova", $composer_requirements)){
RhysLees marked this conversation as resolved.
Show resolved Hide resolved
$composer_requirements_nova_version = $composer_requirements["laravel/nova"];

// Filter numbers version
$composer_requirements_nova_version = preg_replace('/[^0-9]/', '', $composer_requirements_nova_version);

if (strlen($composer_requirements_nova_version) > 0) {
$novaVersion = substr($composer_requirements_nova_version, 0, 1);
}

}
}
}
}
} catch (PackagistException $e) {
return;
}
Expand All @@ -46,14 +71,22 @@ public function handle()
return;
}

Package::withoutSyncingToSearch(function () use ($packagistData) {
Package::withoutSyncingToSearch(function () use ($packagistData, $novaVersion) {
$this->package->update([
'packagist_downloads' => Arr::get($packagistData, 'package.downloads.total', 0) ?: 0,
'github_stars' => Arr::get($packagistData, 'package.github_stars', 0) ?: 0,
'repo_url' => $packagistData['package']['repository'],
'nova_version' => $novaVersion ?? null,
RhysLees marked this conversation as resolved.
Show resolved Hide resolved
]);
});

Log::info('Synced packagist data for package #' . $this->package->id . ' (' . $this->package->name . ')');
}

private function extractStableVersionsFromPackages($packagist)
{
return collect($packagist['package']['versions'])->reject(function ($version) {
return strpos($version['version'], 'dev') !== false;
});
}
}
8 changes: 8 additions & 0 deletions app/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ public function scopePopular($query)
->orderBy('popularity', 'desc');
}

public function scopeNovaCurrent($query)
{
return $query->select(
DB::Raw('packages.*, nova_version')
)
->where('nova_version', config('novapackages.nova.latest_major_version'));
}

public function toSearchableArray()
{
$packageAttributes = $this->toArray();
Expand Down
20 changes: 20 additions & 0 deletions config/novapackages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

return [

/*
|--------------------------------------------------------------------------
| Latest Version
|--------------------------------------------------------------------------
|
| This value defines the latest major version of Laravel Nova. This value is
| used when checking if a package is the compatible with the latest version
| of Nova.
|
*/
RhysLees marked this conversation as resolved.
Show resolved Hide resolved

'nova' => [
'latest_major_version' => env('NOVA_LATEST_MAJOR_VERSION', '4'),
],

];
RhysLees marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddNovaVersionColumnToPackagesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('packages', function (Blueprint $table) {
$table->integer('nova_version')->unsigned()->nullable()->after('latest_version');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('packages', function (Blueprint $table) {
$table->dropColumn('nova_version');
});
}
}
12 changes: 12 additions & 0 deletions public/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -1651,6 +1651,14 @@ html {
border-bottom-right-radius: 0.25rem;
}

.rounded-bl {
border-bottom-left-radius: 0.25rem;
}

.rounded-tr {
border-top-right-radius: 0.25rem;
}

.border {
border-width: 1px;
}
Expand Down Expand Up @@ -2138,6 +2146,10 @@ html {
letter-spacing: 0.025em;
}

.tracking-widest {
letter-spacing: 0.1em;
}

.text-brand-darker {
--tw-text-opacity: 1;
color: rgb(44 82 130 / var(--tw-text-opacity));
Expand Down
Loading