From 1570e8699981839848e74313ab3e75a1c2eb4fc4 Mon Sep 17 00:00:00 2001 From: westy12dan Date: Fri, 25 Mar 2022 14:47:01 +0800 Subject: [PATCH] Adding headFile --- src/Api/AbstractApi.php | 32 ++++++++++++++++++++++++++++++++ src/Api/RepositoryFiles.php | 14 ++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/src/Api/AbstractApi.php b/src/Api/AbstractApi.php index f21c498e7..1a5cff1e6 100644 --- a/src/Api/AbstractApi.php +++ b/src/Api/AbstractApi.php @@ -64,6 +64,26 @@ public function __construct(Client $client) $this->client = $client; } + /** + * Send a HEAD request with query params and return the raw response. + * + * @param string $uri + * @param array $params + * @param array $headers + * + * @throws \Http\Client\Exception + * + * @return \Psr\Http\Message\ResponseInterface + */ + protected function headAsResponse(string $uri, array $params = [], array $headers = []): ResponseInterface + { + if (null !== $this->perPage && !isset($params['per_page'])) { + $params['per_page'] = $this->perPage; + } + + return $this->client->getHttpClient()->head(self::prepareUri($uri, $params), $headers); + } + /** * Send a GET request with query params and return the raw response. * @@ -84,6 +104,18 @@ protected function getAsResponse(string $uri, array $params = [], array $headers return $this->client->getHttpClient()->get(self::prepareUri($uri, $params), $headers); } + /** + * @param string $uri + * @param array $params + * @param array $headers + * + * @return mixed + */ + protected function head(string $uri, array $params = [], array $headers = []) + { + return $this->headAsResponse($uri, $params, $headers); + } + /** * @param string $uri * @param array $params diff --git a/src/Api/RepositoryFiles.php b/src/Api/RepositoryFiles.php index a339c993c..6800ded2c 100644 --- a/src/Api/RepositoryFiles.php +++ b/src/Api/RepositoryFiles.php @@ -18,6 +18,20 @@ class RepositoryFiles extends AbstractApi { + /** + * @param int|string $project_id + * @param string $file_path + * @param string $ref + * + * @return \Psr\Http\Message\ResponseInterface + */ + public function headFile($project_id, string $file_path, string $ref) + { + return $this->head($this->getProjectPath($project_id, 'repository/files/'.self::encodePath($file_path)), [ + 'ref' => $ref, + ]); + } + /** * @param int|string $project_id * @param string $file_path