* List contents of a directory in a repository
(
owner: string,
repo: string,
path: string,
ref?: string,
)
| 107 | * List contents of a directory in a repository |
| 108 | */ |
| 109 | async listDirectory( |
| 110 | owner: string, |
| 111 | repo: string, |
| 112 | path: string, |
| 113 | ref?: string, |
| 114 | ): Promise<GitHubFileEntry[]> { |
| 115 | try { |
| 116 | const { data } = await this.octokit.repos.getContent({ |
| 117 | owner, |
| 118 | repo, |
| 119 | path, |
| 120 | ref, |
| 121 | }); |
| 122 | |
| 123 | // API returns single object for files, array for directories |
| 124 | if (!Array.isArray(data)) { |
| 125 | throw new GitHubClientError(`Path "${path}" is not a directory`); |
| 126 | } |
| 127 | |
| 128 | const entries: GitHubFileEntry[] = []; |
| 129 | for (const item of data) { |
| 130 | const parsed = GitHubFileEntrySchema.safeParse(item); |
| 131 | if (parsed.success) { |
| 132 | entries.push(parsed.data); |
| 133 | } |
| 134 | } |
| 135 | return entries; |
| 136 | } catch (error) { |
| 137 | throw this.handleError(error); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Get raw file content from a repository |
no test coverage detected