Skip to content
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

chore: Refactor types for fetching GitHub content #217

Merged
merged 4 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions api/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ export function fetchRepoAsZip(zipUrl: string): HubSpotPromise<Buffer> {
}

// Returns the raw file contents via the raw.githubusercontent endpoint
export function fetchRepoFile(
export function fetchRepoFile<T = Buffer>(
repoPath: RepoPath,
filePath: string,
ref: string
): HubSpotPromise<Buffer> {
return axios.get<Buffer>(
): HubSpotPromise<T> {
return axios.get<T>(
`${GITHUB_RAW_CONTENT_API_PATH}/${repoPath}/${ref}/${filePath}`,
{
headers: {
Expand Down
6 changes: 3 additions & 3 deletions lib/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import { isHubSpotHttpError, isSystemError } from '../errors';

const i18nKey = 'lib.github';

export async function fetchFileFromRepository(
export async function fetchFileFromRepository<T = Buffer>(
repoPath: RepoPath,
filePath: string,
ref: string
): Promise<Buffer> {
): Promise<T> {
try {
logger.debug(
i18n(`${i18nKey}.fetchFileFromRepository.fetching`, {
Expand All @@ -35,7 +35,7 @@ export async function fetchFileFromRepository(
);

const { data } = await fetchRepoFile(repoPath, filePath, ref);
return data;
return data as T;
kemmerle marked this conversation as resolved.
Show resolved Hide resolved
} catch (err) {
throw new Error(
i18n(`${i18nKey}.fetchFileFromRepository.errors.fetchFail`),
Expand Down
Loading