mirror of
https://github.com/sitelease/sugar-cube-client.git
synced 2025-10-29 11:02:30 +01:00
Updated RequestChainable interface and trait
+ Added a new `findOrRequestRepository()` method
This commit is contained in:
@ -2,6 +2,9 @@
|
||||
|
||||
namespace Gitea\Core\Interfaces;
|
||||
|
||||
use Gitea\Client;
|
||||
use Gitea\Model\Repository;
|
||||
|
||||
/**
|
||||
* Interface that allows the tracking of request heirarchies
|
||||
*
|
||||
@ -65,4 +68,17 @@ interface RequestChainableInterface
|
||||
* @return array
|
||||
*/
|
||||
public function debugRequestChain(): string;
|
||||
|
||||
/**
|
||||
* Climb up the request chain searching for
|
||||
* a repository object. If a repository is found
|
||||
* it will be returned otherwise the method will
|
||||
* make an API request to retrieve it
|
||||
*
|
||||
* @author Benjamin Blake (sitelease.ca)
|
||||
* @param string $owner The owner of the repository
|
||||
* @param string $name The name of the repository
|
||||
* @return Repository|null
|
||||
*/
|
||||
public function findOrRequestRepository(string $owner, string $name): ?Repository;
|
||||
}
|
||||
|
||||
@ -3,6 +3,8 @@
|
||||
namespace Gitea\Core\Traits;
|
||||
|
||||
use Gitea\Client;
|
||||
use Gitea\Model\Repository;
|
||||
|
||||
use Gitea\Core\Interfaces\RequestChainableInterface;
|
||||
|
||||
/**
|
||||
@ -127,4 +129,27 @@ trait RequestChainable
|
||||
return $requestChainDebug;
|
||||
}
|
||||
|
||||
/**
|
||||
* Climb up the request chain searching for
|
||||
* a repository object. If a repository is found
|
||||
* it will be returned otherwise the method will
|
||||
* make an API request to retrieve it
|
||||
*
|
||||
* @author Benjamin Blake (sitelease.ca)
|
||||
* @param string $owner The owner of the repository
|
||||
* @param string $name The name of the repository
|
||||
* @return Repository|null
|
||||
*/
|
||||
public function findOrRequestRepository(string $owner, string $name): ?Repository
|
||||
{
|
||||
$repository = $this->searchRequestChain(Repository::class);
|
||||
|
||||
if (!$repository) {
|
||||
$client = $this->getClient();
|
||||
$repository = $client->repositories()->getByName($owner, $name);
|
||||
}
|
||||
|
||||
return $repository;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user