Skip to content

Commit

Permalink
Merge pull request #217 from HubSpot/convert/ts-5
Browse files Browse the repository at this point in the history
chore: Refactor types for fetching GitHub content
  • Loading branch information
kemmerle authored Dec 5, 2024
2 parents 893572c + 02f193d commit 3593bb9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
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,19 +22,19 @@ 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`, {
path: `${repoPath}/${ref}/${filePath}`,
})
);

const { data } = await fetchRepoFile(repoPath, filePath, ref);
const { data } = await fetchRepoFile<T>(repoPath, filePath, ref);
return data;
} catch (err) {
throw new Error(
Expand Down
1 change: 1 addition & 0 deletions types/developerTestAccounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export type DeveloperTestAccount = {
createdAt: string;
updatedAt: string;
status: string;
id: number;
};

export type FetchDeveloperTestAccountsResponse = {
Expand Down

0 comments on commit 3593bb9

Please sign in to comment.