mirror of
https://github.com/axeloz/filesharing.git
synced 2025-05-06 01:53:55 +02:00
Adding command to check new releases
This commit is contained in:
parent
47fa3cb3f3
commit
5c46e16ef7
1 changed files with 71 additions and 0 deletions
71
app/Console/Commands/CheckRelease.php
Normal file
71
app/Console/Commands/CheckRelease.php
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
|
class CheckRelease extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'fs:check-release';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Command description';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$releases = [];
|
||||||
|
|
||||||
|
$this->newLine();
|
||||||
|
if (! $xml = @simplexml_load_file('https://github.com/axeloz/filesharing/releases.atom')) {
|
||||||
|
$this->error(' Unable to fetch the releases ');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
foreach ($xml->entry as $e) {
|
||||||
|
// Title must be a version
|
||||||
|
if (! preg_match('~^[0-9]+\.[0-9]+~', $e->title)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Looking for the release link
|
||||||
|
foreach ($e->link->attributes() as $k => $a) {
|
||||||
|
if ($k == 'href') {
|
||||||
|
$href = $a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Adding the info
|
||||||
|
array_push($releases, [
|
||||||
|
'version' => $e->title,
|
||||||
|
'updated_at' => (new Carbon($e->updated))->diffForHumans(),
|
||||||
|
'link' => $href ?? null
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Displaying the releases
|
||||||
|
if (count($releases) > 0) {
|
||||||
|
$this->table([
|
||||||
|
'Version', 'Updated', 'Link'
|
||||||
|
], $releases
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$this->error(' No release found ');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->newLine();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue