Updated RequestChainable interface and trait

+ Added a new `findOrRequestRepository()` method
This commit is contained in:
Benjamin Blake
2020-02-26 22:52:21 -07:00
parent f5c7ed4962
commit 239b6b4748
2 changed files with 41 additions and 0 deletions

View File

@ -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;
}

View File

@ -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;
}
}