Loosen up the type some more
This commit is contained in:
@@ -78,7 +78,7 @@ describe('AzurePreparer', () => {
|
||||
|
||||
it('calls the clone command with the correct arguments for a repository', async () => {
|
||||
const preparer = new AzurePreparer(ConfigReader.fromConfigs([]));
|
||||
await preparer.prepare(mockEntity, { workingDirectory: '/workDir' });
|
||||
await preparer.prepare(mockEntity);
|
||||
expect(mocks.Clone.clone).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
'https://dev.azure.com/backstage-org/backstage-project/_git/template-repo',
|
||||
@@ -104,7 +104,7 @@ describe('AzurePreparer', () => {
|
||||
},
|
||||
]),
|
||||
);
|
||||
await preparer.prepare(mockEntity, { workingDirectory: '/workDir' });
|
||||
await preparer.prepare(mockEntity);
|
||||
expect(mocks.Clone.clone).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
'https://dev.azure.com/backstage-org/backstage-project/_git/template-repo',
|
||||
@@ -122,7 +122,7 @@ describe('AzurePreparer', () => {
|
||||
it('calls the clone command with the correct arguments for a repository when no path is provided', async () => {
|
||||
const preparer = new AzurePreparer(ConfigReader.fromConfigs([]));
|
||||
delete mockEntity.spec.path;
|
||||
await preparer.prepare(mockEntity, { workingDirectory: '/workDir' });
|
||||
await preparer.prepare(mockEntity);
|
||||
expect(mocks.Clone.clone).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
'https://dev.azure.com/backstage-org/backstage-project/_git/template-repo',
|
||||
@@ -134,7 +134,7 @@ describe('AzurePreparer', () => {
|
||||
it('return the temp directory with the path to the folder if it is specified', async () => {
|
||||
const preparer = new AzurePreparer(ConfigReader.fromConfigs([]));
|
||||
mockEntity.spec.path = './template/test/1/2/3';
|
||||
const response = await preparer.prepare(mockEntity, {});
|
||||
const response = await preparer.prepare(mockEntity);
|
||||
|
||||
expect(response.split('\\').join('/')).toMatch(
|
||||
/\/template\/test\/1\/2\/3$/,
|
||||
|
||||
@@ -34,10 +34,10 @@ export class AzurePreparer implements PreparerBase {
|
||||
|
||||
async prepare(
|
||||
template: TemplateEntityV1alpha1,
|
||||
opts: { workingDirectory?: string },
|
||||
opts?: { workingDirectory?: string },
|
||||
): Promise<string> {
|
||||
const { protocol, location } = parseLocationAnnotation(template);
|
||||
const workingDirectory = opts.workingDirectory ?? os.tmpdir();
|
||||
const workingDirectory = opts?.workingDirectory ?? os.tmpdir();
|
||||
|
||||
if (!['azure/api', 'url'].includes(protocol)) {
|
||||
throw new InputError(
|
||||
|
||||
@@ -24,10 +24,10 @@ import { PreparerBase } from './types';
|
||||
export class FilePreparer implements PreparerBase {
|
||||
async prepare(
|
||||
template: TemplateEntityV1alpha1,
|
||||
opts: { workingDirectory?: string },
|
||||
opts?: { workingDirectory?: string },
|
||||
): Promise<string> {
|
||||
const { protocol, location } = parseLocationAnnotation(template);
|
||||
const workingDirectory = opts.workingDirectory ?? os.tmpdir();
|
||||
const workingDirectory = opts?.workingDirectory ?? os.tmpdir();
|
||||
|
||||
if (protocol !== 'file') {
|
||||
throw new InputError(
|
||||
|
||||
@@ -76,7 +76,7 @@ describe('GitHubPreparer', () => {
|
||||
});
|
||||
it('calls the clone command with the correct arguments for a repository', async () => {
|
||||
const preparer = new GithubPreparer();
|
||||
await preparer.prepare(mockEntity, { workingDirectory: '/workDir' });
|
||||
await preparer.prepare(mockEntity);
|
||||
expect(mocks.Clone.clone).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
'https://github.com/benjdlambert/backstage-graphql-template',
|
||||
@@ -89,7 +89,7 @@ describe('GitHubPreparer', () => {
|
||||
it('calls the clone command with the correct arguments for a repository when no path is provided', async () => {
|
||||
const preparer = new GithubPreparer();
|
||||
delete mockEntity.spec.path;
|
||||
await preparer.prepare(mockEntity, { workingDirectory: '/workDir' });
|
||||
await preparer.prepare(mockEntity);
|
||||
expect(mocks.Clone.clone).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
'https://github.com/benjdlambert/backstage-graphql-template',
|
||||
@@ -103,7 +103,7 @@ describe('GitHubPreparer', () => {
|
||||
it('return the temp directory with the path to the folder if it is specified', async () => {
|
||||
const preparer = new GithubPreparer();
|
||||
mockEntity.spec.path = './template/test/1/2/3';
|
||||
const response = await preparer.prepare(mockEntity, {});
|
||||
const response = await preparer.prepare(mockEntity);
|
||||
|
||||
expect(response.split('\\').join('/')).toMatch(
|
||||
/\/template\/test\/1\/2\/3$/,
|
||||
@@ -124,7 +124,7 @@ describe('GitHubPreparer', () => {
|
||||
|
||||
it('calls the clone command with the token when provided', async () => {
|
||||
const preparer = new GithubPreparer({ token: 'abc' });
|
||||
await preparer.prepare(mockEntity, { workingDirectory: '/workDir' });
|
||||
await preparer.prepare(mockEntity);
|
||||
expect(mocks.Clone.clone).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
'https://github.com/benjdlambert/backstage-graphql-template',
|
||||
|
||||
@@ -32,10 +32,10 @@ export class GithubPreparer implements PreparerBase {
|
||||
|
||||
async prepare(
|
||||
template: TemplateEntityV1alpha1,
|
||||
opts: { workingDirectory?: string },
|
||||
opts?: { workingDirectory?: string },
|
||||
): Promise<string> {
|
||||
const { protocol, location } = parseLocationAnnotation(template);
|
||||
const workingDirectory = opts.workingDirectory ?? os.tmpdir();
|
||||
const workingDirectory = opts?.workingDirectory ?? os.tmpdir();
|
||||
const { token } = this;
|
||||
|
||||
if (!['github', 'url'].includes(protocol)) {
|
||||
|
||||
@@ -79,7 +79,7 @@ describe('GitLabPreparer', () => {
|
||||
it(`calls the clone command with the correct arguments for a repository using the ${protocol} protocol`, async () => {
|
||||
const preparer = new GitlabPreparer(ConfigReader.fromConfigs([]));
|
||||
mockEntity = mockEntityWithProtocol(protocol);
|
||||
await preparer.prepare(mockEntity, { workingDirectory: '/workDir' });
|
||||
await preparer.prepare(mockEntity);
|
||||
expect(mocks.Clone.clone).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
'https://gitlab.com/benjdlambert/backstage-graphql-template',
|
||||
@@ -106,7 +106,7 @@ describe('GitLabPreparer', () => {
|
||||
]),
|
||||
);
|
||||
mockEntity = mockEntityWithProtocol(protocol);
|
||||
await preparer.prepare(mockEntity, { workingDirectory: '/workDir' });
|
||||
await preparer.prepare(mockEntity);
|
||||
expect(mocks.Clone.clone).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
'https://gitlab.com/benjdlambert/backstage-graphql-template',
|
||||
@@ -125,7 +125,7 @@ describe('GitLabPreparer', () => {
|
||||
const preparer = new GitlabPreparer(ConfigReader.fromConfigs([]));
|
||||
mockEntity = mockEntityWithProtocol(protocol);
|
||||
delete mockEntity.spec.path;
|
||||
await preparer.prepare(mockEntity, { workingDirectory: '/workDir' });
|
||||
await preparer.prepare(mockEntity);
|
||||
expect(mocks.Clone.clone).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
'https://gitlab.com/benjdlambert/backstage-graphql-template',
|
||||
@@ -138,7 +138,7 @@ describe('GitLabPreparer', () => {
|
||||
const preparer = new GitlabPreparer(ConfigReader.fromConfigs([]));
|
||||
mockEntity = mockEntityWithProtocol(protocol);
|
||||
mockEntity.spec.path = './template/test/1/2/3';
|
||||
const response = await preparer.prepare(mockEntity, {});
|
||||
const response = await preparer.prepare(mockEntity);
|
||||
|
||||
expect(response.split('\\').join('/')).toMatch(
|
||||
/\/template\/test\/1\/2\/3$/,
|
||||
|
||||
@@ -35,10 +35,10 @@ export class GitlabPreparer implements PreparerBase {
|
||||
|
||||
async prepare(
|
||||
template: TemplateEntityV1alpha1,
|
||||
opts: { workingDirectory?: string },
|
||||
opts?: { workingDirectory?: string },
|
||||
): Promise<string> {
|
||||
const { protocol, location } = parseLocationAnnotation(template);
|
||||
const workingDirectory = opts.workingDirectory ?? os.tmpdir();
|
||||
const workingDirectory = opts?.workingDirectory ?? os.tmpdir();
|
||||
|
||||
if (!['gitlab', 'gitlab/api', 'url'].includes(protocol)) {
|
||||
throw new InputError(
|
||||
|
||||
@@ -25,7 +25,7 @@ export type PreparerBase = {
|
||||
*/
|
||||
prepare(
|
||||
template: TemplateEntityV1alpha1,
|
||||
opts: { logger: Logger; workingDirectory?: string },
|
||||
opts?: { logger: Logger; workingDirectory?: string },
|
||||
): Promise<string>;
|
||||
};
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
import { TemplateEntityV1alpha1 } from '@backstage/catalog-model';
|
||||
import { Config, JsonValue } from '@backstage/config';
|
||||
import os from 'os';
|
||||
import fs from 'fs-extra';
|
||||
import Docker from 'dockerode';
|
||||
import express from 'express';
|
||||
|
||||
Reference in New Issue
Block a user