Skip to content

Commit 0b3ca23

Browse files
committed
Add ref to list contents
1 parent f635b36 commit 0b3ca23

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

src/VCS/Adapter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,10 @@ abstract public function listRepositoryLanguages(string $owner, string $reposito
227227
* @param string $owner Owner name of the repository
228228
* @param string $repositoryName Name of the repository
229229
* @param string $path Path to list contents from
230+
* @param string $ref The name of the commit/branch/tag
230231
* @return array<mixed> List of contents at the specified path
231232
*/
232-
abstract public function listRepositoryContents(string $owner, string $repositoryName, string $path = ''): array;
233+
abstract public function listRepositoryContents(string $owner, string $repositoryName, string $path = '', string $ref = ''): array;
233234

234235
/**
235236
* Get details of a commit using commit hash

src/VCS/Adapter/Git/GitHub.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,18 @@ public function listRepositoryLanguages(string $owner, string $repositoryName):
202202
* @param string $owner Owner name of the repository
203203
* @param string $repositoryName Name of the GitHub repository
204204
* @param string $path Path to list contents from
205+
* @param string $ref The name of the commit/branch/tag
205206
* @return array<mixed> List of contents at the specified path
206207
*/
207-
public function listRepositoryContents(string $owner, string $repositoryName, string $path = ''): array
208+
public function listRepositoryContents(string $owner, string $repositoryName, string $path = '', string $ref = ''): array
208209
{
209210
$url = "/repos/$owner/$repositoryName/contents";
210211
if (!empty($path)) {
211212
$url .= "/$path";
212213
}
214+
if (!empty($ref)) {
215+
$url .= "?ref=$ref";
216+
}
213217

214218
$response = $this->call(self::METHOD_GET, $url, ['Authorization' => "Bearer $this->accessToken"]);
215219

tests/VCS/Base.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,17 @@ public function testListRepositoryContents(): void
8585
$this->assertIsArray($contents);
8686
$this->assertNotEmpty($contents);
8787

88-
8988
$contents = $this->vcsAdapter->listRepositoryContents('appwrite', 'appwrite', '');
9089
$this->assertIsArray($contents);
9190
$this->assertNotEmpty($contents);
9291
$this->assertGreaterThan(0, \count($contents));
9392

93+
// Test with ref parameter
94+
$contents = $this->vcsAdapter->listRepositoryContents('appwrite', 'appwrite', '', 'main');
95+
$this->assertIsArray($contents);
96+
$this->assertNotEmpty($contents);
97+
$this->assertGreaterThan(0, \count($contents));
98+
9499
$fileContent = null;
95100
foreach ($contents as $content) {
96101
if ($content['type'] === GitHub::CONTENTS_FILE) {

0 commit comments

Comments
 (0)