Get dev commit details from gitea
This commit is contained in:
parent
2d3ca833f9
commit
2c1e4543fd
@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\ClientException;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\{Cache,Log};
|
||||
use Illuminate\Support\Str;
|
||||
@ -15,10 +16,13 @@ class VersionController extends Controller
|
||||
{
|
||||
private const CACHE_TIME = 86400; // Time to cache version
|
||||
|
||||
private const GH_URL = 'https://api.github.com/repos'; // GitHub URL
|
||||
private const GH_URL = 'https://api.github.com/repos'; // GitHub URL (rel)
|
||||
private const GH_PROJECT = 'leenooks/phpldapadmin';
|
||||
private const GH_TREE = 'master';
|
||||
|
||||
private const GT_URL = 'https://gitea.dege.au/api/v1/repos'; // Gitea URL (dev)
|
||||
private const GT_PROJECT = 'deon/phpldapadmin';
|
||||
|
||||
private const VERSION_REGEX = '/^v([0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?)-([a-z]{3})-([a-z0-9]{8})$/';
|
||||
|
||||
public function main(Request $request,?string $version=NULL) {
|
||||
@ -41,28 +45,39 @@ class VersionController extends Controller
|
||||
// If xxx is "dev" we are a development version
|
||||
switch($matches[3]) {
|
||||
case 'dev':
|
||||
$current = Cache::remember('dev',self::CACHE_TIME,function() {
|
||||
$client = new Client;
|
||||
$url = sprintf('%s/%s/commits/%s',self::GH_URL,self::GH_PROJECT,self::GH_TREE);
|
||||
$v = explode('.',$matches[1]);
|
||||
|
||||
$response = $client->request('GET',$url,['form_params'=>['per_page'=>'1']]);
|
||||
$current = Cache::remember('dev',self::CACHE_TIME,function() use ($v) {
|
||||
$client = new Client;
|
||||
$url = sprintf('%s/%s/commits',self::GT_URL,self::GT_PROJECT);
|
||||
|
||||
try {
|
||||
$response = $client->request('GET',$url,['query'=>['sha'=>sprintf('%d.%d-dev',$v[0],$v[1]),'limit'=>1]]);
|
||||
} catch (ClientException $e) {
|
||||
return 404;
|
||||
}
|
||||
|
||||
if ($response->getStatusCode() === 200) {
|
||||
$result = collect(json_decode($response->getBody()));
|
||||
|
||||
return Str::limit($result->get('sha'),8,NULL);
|
||||
return Str::limit($result[0]->sha,8,NULL);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
});
|
||||
|
||||
if ($current) {
|
||||
if ($current === 404) {
|
||||
$response = ['action'=>'unknown','version'=>sprintf('%d.%d-dev-00000000',$v[0],$v[1])];
|
||||
|
||||
} else {
|
||||
$repository = sprintf('v%s-dev-%s',$matches[1],$current);
|
||||
|
||||
// Find the tag associated with version $matches[1] and see if it is more recent than $matches[4]
|
||||
$response = ($matches[4] === $current)
|
||||
? ['action'=>'current','version'=>$repository]
|
||||
: ['action'=>'upgrade','version'=>sprintf('v%s-%s-%s',$matches[1],$matches[3],$current)];
|
||||
}
|
||||
|
||||
} else
|
||||
$response = ['action'=>'unable','version'=>'vn.n.n-dev-hhhhhhhh'];
|
||||
|
Loading…
x
Reference in New Issue
Block a user