-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding listGithubRepoContents()
to lib
#84
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ import fs from 'fs-extra'; | |
import { throwError, throwErrorWithMessage } from '../errors/standardErrors'; | ||
import { extractZipArchive } from './archive'; | ||
import { logger } from './logging/logger'; | ||
import { BaseError } from '../types/Error'; | ||
import { GenericError, BaseError } from '../types/Error'; | ||
import { GithubReleaseData, GithubRepoFile } from '../types/Github'; | ||
import { | ||
fetchRepoFile, | ||
|
@@ -234,3 +234,36 @@ export async function downloadGithubRepoContents( | |
} | ||
} | ||
} | ||
|
||
// Lists content from a public repository at the specified path | ||
export async function listGithubRepoContents( | ||
repoPath: RepoPath, | ||
contentPath: string, | ||
fileFilter?: 'file' | 'dir' | ||
): Promise<GithubRepoFile[]> { | ||
try { | ||
const { data: contentsResp } = await fetchRepoContents( | ||
repoPath, | ||
contentPath | ||
); | ||
|
||
const filteredFiles = | ||
fileFilter && fileFilter != undefined | ||
? contentsResp.filter(item => item.type === fileFilter) | ||
: contentsResp; | ||
|
||
return filteredFiles; | ||
} catch (e) { | ||
const error = e as GenericError; | ||
if (error?.response?.data?.message) { | ||
throwErrorWithMessage( | ||
`${i18nKey}.downloadGithubRepoContents.errors.fetchFail`, | ||
{ | ||
errorMessage: error.response.data.message, | ||
} | ||
); | ||
} else { | ||
throwError(error); | ||
} | ||
Comment on lines
+257
to
+267
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Throwing the error with message here based on the github error response for fetching. Using |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strictly typing the options here that are relevant to the response from fetching GitHub repo contents