From 0b3ca2396752b513adfa52a5e59a16decb68ba38 Mon Sep 17 00:00:00 2001 From: Khushboo Verma Date: Tue, 10 Jun 2025 20:15:37 +0530 Subject: [PATCH] Add ref to list contents --- src/VCS/Adapter.php | 3 ++- src/VCS/Adapter/Git/GitHub.php | 6 +++++- tests/VCS/Base.php | 7 ++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/VCS/Adapter.php b/src/VCS/Adapter.php index 939b9a1..1479fbe 100644 --- a/src/VCS/Adapter.php +++ b/src/VCS/Adapter.php @@ -227,9 +227,10 @@ abstract public function listRepositoryLanguages(string $owner, string $reposito * @param string $owner Owner name of the repository * @param string $repositoryName Name of the repository * @param string $path Path to list contents from + * @param string $ref The name of the commit/branch/tag * @return array List of contents at the specified path */ - abstract public function listRepositoryContents(string $owner, string $repositoryName, string $path = ''): array; + abstract public function listRepositoryContents(string $owner, string $repositoryName, string $path = '', string $ref = ''): array; /** * Get details of a commit using commit hash diff --git a/src/VCS/Adapter/Git/GitHub.php b/src/VCS/Adapter/Git/GitHub.php index 3208423..054772e 100644 --- a/src/VCS/Adapter/Git/GitHub.php +++ b/src/VCS/Adapter/Git/GitHub.php @@ -202,14 +202,18 @@ public function listRepositoryLanguages(string $owner, string $repositoryName): * @param string $owner Owner name of the repository * @param string $repositoryName Name of the GitHub repository * @param string $path Path to list contents from + * @param string $ref The name of the commit/branch/tag * @return array List of contents at the specified path */ - public function listRepositoryContents(string $owner, string $repositoryName, string $path = ''): array + public function listRepositoryContents(string $owner, string $repositoryName, string $path = '', string $ref = ''): array { $url = "/repos/$owner/$repositoryName/contents"; if (!empty($path)) { $url .= "/$path"; } + if (!empty($ref)) { + $url .= "?ref=$ref"; + } $response = $this->call(self::METHOD_GET, $url, ['Authorization' => "Bearer $this->accessToken"]); diff --git a/tests/VCS/Base.php b/tests/VCS/Base.php index e31ef61..ef07a5a 100644 --- a/tests/VCS/Base.php +++ b/tests/VCS/Base.php @@ -85,12 +85,17 @@ public function testListRepositoryContents(): void $this->assertIsArray($contents); $this->assertNotEmpty($contents); - $contents = $this->vcsAdapter->listRepositoryContents('appwrite', 'appwrite', ''); $this->assertIsArray($contents); $this->assertNotEmpty($contents); $this->assertGreaterThan(0, \count($contents)); + // Test with ref parameter + $contents = $this->vcsAdapter->listRepositoryContents('appwrite', 'appwrite', '', 'main'); + $this->assertIsArray($contents); + $this->assertNotEmpty($contents); + $this->assertGreaterThan(0, \count($contents)); + $fileContent = null; foreach ($contents as $content) { if ($content['type'] === GitHub::CONTENTS_FILE) {