Skip to content

Commit

Permalink
chore(http/github): add utility function to fetch raw files
Browse files Browse the repository at this point in the history
  • Loading branch information
secustor committed Jul 12, 2024
1 parent 34478a6 commit 6a8aeb1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/util/http/github.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -786,4 +786,24 @@ describe('util/http/github', () => {
).rejects.toThrow(EXTERNAL_HOST_ERROR);
});
});

describe('getRawFile()', () => {
it('add header and return', async () => {
httpMock
.scope(githubApiHost)
.get('/foo/bar/contents/lore/ipsum.txt')
.matchHeader(
'accept',
'application/vnd.github.raw+json, application/vnd.github.v3+json',
)
.reply(200, 'foo');
await expect(
githubApi.getRawFile(
`${githubApiHost}/foo/bar/contents/lore/ipsum.txt`,
),
).resolves.toMatchObject({
body: 'foo',
});
});
});
});
8 changes: 8 additions & 0 deletions lib/util/http/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,4 +493,12 @@ export class GithubHttp extends Http<GithubHttpOptions> {

return result;
}

public getRawFile(url: string): Promise<HttpResponse> {
return this.get(url, {
headers: {
accept: 'application/vnd.github.raw+json',
},
});
}
}

0 comments on commit 6a8aeb1

Please sign in to comment.