Merge pull request #1594 from spotify/blam/tidy-up-scaffolder

Use the Templater Property in the Template Definition to choose the templater
This commit is contained in:
Ben Lambert
2020-07-13 14:00:21 +02:00
committed by GitHub
17 changed files with 268 additions and 26 deletions
+1
View File
@@ -29,6 +29,7 @@
"@backstage/plugin-scaffolder-backend": "^0.1.1-alpha.13",
"@backstage/plugin-sentry-backend": "^0.1.1-alpha.13",
"@backstage/plugin-techdocs-backend": "^0.1.1-alpha.13",
"@octokit/rest": "^18.0.0",
"dockerode": "^3.2.0",
"express": "^4.17.1",
"knex": "^0.21.1",
+18 -3
View File
@@ -20,19 +20,34 @@ import {
FilePreparer,
GithubPreparer,
Preparers,
GithubPublisher,
Templaters,
} from '@backstage/plugin-scaffolder-backend';
import { Octokit } from '@octokit/rest';
import type { PluginEnvironment } from '../types';
import Docker from 'dockerode';
export default async function createPlugin({ logger }: PluginEnvironment) {
const templater = new CookieCutter();
const cookiecutterTemplater = new CookieCutter();
const templaters = new Templaters();
templaters.register('cookiecutter', cookiecutterTemplater);
const filePreparer = new FilePreparer();
const githubPreparer = new GithubPreparer();
const preparers = new Preparers();
const dockerClient = new Docker();
preparers.register('file', filePreparer);
preparers.register('github', githubPreparer);
return await createRouter({ preparers, templater, logger, dockerClient });
const githubClient = new Octokit({ auth: process.env.GITHUB_ACCESS_TOKEN });
const publisher = new GithubPublisher({ client: githubClient });
const dockerClient = new Docker();
return await createRouter({
preparers,
templaters,
publisher,
logger,
dockerClient,
});
}
@@ -32,7 +32,8 @@ describe('TemplateEntityV1alpah1', () => {
name: 'test',
},
spec: {
type: 'cookiecutter',
type: 'website',
templater: 'cookiecutter',
schema: {
$schema: 'http://json-schema.org/draft-07/schema#',
required: ['storePath', 'owner'],
@@ -78,7 +79,7 @@ describe('TemplateEntityV1alpah1', () => {
await expect(policy.enforce(entity)).rejects.toThrow(/type/);
});
it('acceptps any other type', async () => {
it('accepts any other type', async () => {
(entity as any).spec.type = 'hallo';
await expect(policy.enforce(entity)).resolves.toBe(entity);
});
@@ -87,4 +88,9 @@ describe('TemplateEntityV1alpah1', () => {
(entity as any).spec.type = '';
await expect(policy.enforce(entity)).rejects.toThrow(/type/);
});
it('rejects missing templater', async () => {
(entity as any).spec.templater = '';
await expect(policy.enforce(entity)).rejects.toThrow(/templater/);
});
});
@@ -26,6 +26,7 @@ export interface TemplateEntityV1alpha1 extends Entity {
kind: typeof KIND;
spec: {
type: string;
templater: string;
path?: string;
schema: JSONSchema;
};
@@ -43,6 +44,7 @@ export class TemplateEntityV1alpha1Policy implements EntityPolicy {
type: yup.string().required().min(1),
path: yup.string(),
schema: yup.object().required(),
templater: yup.string().required(),
})
.required(),
});