Use fetchContents direectly instead of a fetchPlainAction

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2023-07-25 09:55:38 +02:00
parent 639bbea9f0
commit 0d347efc8f
3 changed files with 15 additions and 11 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-scaffolder-backend-module-confluence-to-markdown': patch
---
Use `fetchContents` directly instead of a `fetchPlainAction`
@@ -157,7 +157,7 @@ describe('confluence:transform:markdown', () => {
expect(logger.info).toHaveBeenCalledWith(
`Fetching the mkdocs.yml catalog from https://notreal.github.com/space/backstage/mkdocs.yml`,
);
expect(logger.info).toHaveBeenCalledTimes(6);
expect(logger.info).toHaveBeenCalledTimes(5);
expect(createWriteStream).toHaveBeenCalledTimes(1);
expect(readFile).toHaveBeenCalledTimes(1);
expect(writeFile).toHaveBeenCalledTimes(1);
@@ -204,7 +204,7 @@ describe('confluence:transform:markdown', () => {
expect(logger.info).toHaveBeenCalledWith(
`Fetching the mkdocs.yml catalog from https://notreal.github.com/space/backstage/mkdocs.yml`,
);
expect(logger.info).toHaveBeenCalledTimes(6);
expect(logger.info).toHaveBeenCalledTimes(5);
expect(createWriteStream).not.toHaveBeenCalled();
expect(readFile).toHaveBeenCalledTimes(1);
@@ -16,7 +16,7 @@
import { Config } from '@backstage/config';
import { UrlReader } from '@backstage/backend-common';
import { ScmIntegrations } from '@backstage/integration';
import { createFetchPlainAction } from '@backstage/plugin-scaffolder-backend';
import { fetchContents } from '@backstage/plugin-scaffolder-backend';
import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
import { InputError, ConflictError } from '@backstage/errors';
import { NodeHtmlMarkdown } from 'node-html-markdown';
@@ -41,7 +41,6 @@ export const createConfluenceToMarkdownAction = (options: {
config: Config;
}) => {
const { config, reader, integrations } = options;
const fetchPlainAction = createFetchPlainAction({ reader, integrations });
type Obj = {
[key: string]: string;
};
@@ -82,18 +81,18 @@ export const createConfluenceToMarkdownAction = (options: {
parsedRepoUrl.filepath.lastIndexOf('/') + 1,
);
const dirPath = ctx.workspacePath;
const repoFileDir = `${dirPath}/${parsedRepoUrl.filepath}`;
let productArray: string[][] = [];
ctx.logger.info(`Fetching the mkdocs.yml catalog from ${repoUrl}`);
// This grabs the files from Github
const repoFileDir = `${dirPath}/${parsedRepoUrl.filepath}`;
await fetchPlainAction.handler({
...ctx,
input: {
url: `https://${parsedRepoUrl.resource}/${parsedRepoUrl.owner}/${parsedRepoUrl.name}`,
targetPath: dirPath,
},
await fetchContents({
reader,
integrations,
baseUrl: ctx.templateInfo?.baseUrl,
fetchUrl: `https://${parsedRepoUrl.resource}/${parsedRepoUrl.owner}/${parsedRepoUrl.name}`,
outputPath: ctx.workspacePath,
});
for (const url of confluenceUrls) {