From 3a675a56870ffd8c0d25c5160612d9c13e86c64f Mon Sep 17 00:00:00 2001 From: David Boyne Date: Tue, 17 Dec 2024 12:30:01 +0000 Subject: [PATCH] feat(plugin): added ability to set branch name --- README.md | 4 ++-- src/index.ts | 5 +++-- src/test/plugin.test.ts | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c883470..4c163e7 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ - 🧑🏻‍💻 Let your teams control their own catalogs, and merge them into a master catalog - ⚡️ Git based generator, supports any git repo (e.g GitHub, GitLab, Bitbucket) - Specify the git repo, it's branch and the files you want to merge into your master catalog -- ✅ Configuration to override files and ensure all files in the catalog are unique +- ✅ Configuration to override files and ensure all files in the catalog are unique # How it works @@ -32,7 +32,7 @@ EventCatalog supports [generators](https://www.eventcatalog.dev/docs/development/plugins/generators). Generators are scripts are run to pre build to generate content in your catalog. Generators can use the [EventCatalog SDK](https://www.eventcatalog.dev/docs/sdk). -With this git generator you can connect to many git repos, and merge them into a master catalog. +With this git generator you can connect to many git repos, and merge them into a master catalog. This let's your teams control their own catalogs, and merge them into a master catalog, keeping the documentation close to the their code. diff --git a/src/index.ts b/src/index.ts index 04a394d..f5c6915 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,6 +13,7 @@ type EventCatalogConfig = any; // Configuration the users give your catalog type GeneratorProps = { source: string; + branch?: string; content: string | string[]; destination: string; debug?: boolean; @@ -123,8 +124,8 @@ export default async (_: EventCatalogConfig, options: GeneratorProps) => { await execSync(`git sparse-checkout set ${options.content} --no-cone`, { cwd: tmpDir }); } - // Checkout the main branch - await execSync(`git checkout main`, { cwd: tmpDir }); + // Checkout the branch + await execSync(`git checkout ${options.branch || 'main'}`, { cwd: tmpDir }); // Check for existing paths first if (!options.override) { diff --git a/src/test/plugin.test.ts b/src/test/plugin.test.ts index 8bff2bf..08caf7c 100644 --- a/src/test/plugin.test.ts +++ b/src/test/plugin.test.ts @@ -50,6 +50,20 @@ describe('generator-federation', () => { expect(services).toHaveLength(4); }); + describe('branch', () => { + it('clones the source directory (with the given branch) and copies the files specified in the content array to the destination directory', async () => { + await plugin(eventCatalogConfig, { + source: 'https://github.com/event-catalog/eventcatalog.git', + content: ['examples/basic/services'], + destination: path.join(catalogDir, 'services'), + branch: 'v1', + }); + + const services = await fs.readdir(path.join(catalogDir, 'services')); + expect(services).toHaveLength(2); + }); + }); + describe('override', () => { it('overrides the content if the destination directory already exists and override is true', async () => { await plugin(eventCatalogConfig, {