chore: support passing through token in fetchContents and fetchFile
Signed-off-by: blam <ben@blam.sh> Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
@@ -124,6 +124,20 @@ describe('fetchContents helper', () => {
|
||||
expect(fs.ensureDir).toHaveBeenCalledWith('foo');
|
||||
expect(dirFunction).toHaveBeenCalledWith({ targetDir: 'foo' });
|
||||
});
|
||||
|
||||
it('should pass through the token provided through to the URL reader', async () => {
|
||||
await fetchContents({
|
||||
...options,
|
||||
outputPath: 'mydir/foo',
|
||||
fetchUrl: 'https://github.com/backstage/foo',
|
||||
token: 'mockToken',
|
||||
});
|
||||
|
||||
expect(readTree).toHaveBeenCalledWith(
|
||||
'https://github.com/backstage/foo',
|
||||
expect.objectContaining({ token: 'mockToken' }),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('fetch file', () => {
|
||||
@@ -211,5 +225,19 @@ describe('fetchContents helper', () => {
|
||||
expect(fs.ensureDir).toHaveBeenCalledWith('mydir');
|
||||
expect(fs.outputFile).toHaveBeenCalledWith('mydir/foo', 'test');
|
||||
});
|
||||
|
||||
it('should pass through the token provided through to the URL reader', async () => {
|
||||
await fetchFile({
|
||||
...options,
|
||||
outputPath: 'mydir/foo',
|
||||
fetchUrl: 'https://github.com/backstage/foo',
|
||||
token: 'mockToken',
|
||||
});
|
||||
|
||||
expect(readUrl).toHaveBeenCalledWith(
|
||||
'https://github.com/backstage/foo',
|
||||
expect.objectContaining({ token: 'mockToken' }),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -32,8 +32,16 @@ export async function fetchContents(options: {
|
||||
baseUrl?: string;
|
||||
fetchUrl?: string;
|
||||
outputPath: string;
|
||||
token?: string;
|
||||
}) {
|
||||
const { reader, integrations, baseUrl, fetchUrl = '.', outputPath } = options;
|
||||
const {
|
||||
reader,
|
||||
integrations,
|
||||
baseUrl,
|
||||
fetchUrl = '.',
|
||||
outputPath,
|
||||
token,
|
||||
} = options;
|
||||
|
||||
const fetchUrlIsAbsolute = isFetchUrlAbsolute(fetchUrl);
|
||||
|
||||
@@ -45,7 +53,7 @@ export async function fetchContents(options: {
|
||||
} else {
|
||||
const readUrl = getReadUrl(fetchUrl, baseUrl, integrations);
|
||||
|
||||
const res = await reader.readTree(readUrl);
|
||||
const res = await reader.readTree(readUrl, { token });
|
||||
await fs.ensureDir(outputPath);
|
||||
await res.dir({ targetDir: outputPath });
|
||||
}
|
||||
@@ -63,8 +71,16 @@ export async function fetchFile(options: {
|
||||
baseUrl?: string;
|
||||
fetchUrl?: string;
|
||||
outputPath: string;
|
||||
token?: string;
|
||||
}) {
|
||||
const { reader, integrations, baseUrl, fetchUrl = '.', outputPath } = options;
|
||||
const {
|
||||
reader,
|
||||
integrations,
|
||||
baseUrl,
|
||||
fetchUrl = '.',
|
||||
outputPath,
|
||||
token,
|
||||
} = options;
|
||||
|
||||
const fetchUrlIsAbsolute = isFetchUrlAbsolute(fetchUrl);
|
||||
|
||||
@@ -76,7 +92,7 @@ export async function fetchFile(options: {
|
||||
} else {
|
||||
const readUrl = getReadUrl(fetchUrl, baseUrl, integrations);
|
||||
|
||||
const res = await reader.readUrl(readUrl);
|
||||
const res = await reader.readUrl(readUrl, { token });
|
||||
await fs.ensureDir(path.dirname(outputPath));
|
||||
const buffer = await res.buffer();
|
||||
await fs.outputFile(outputPath, buffer.toString());
|
||||
|
||||
Reference in New Issue
Block a user