Skip to content

Commit

Permalink
feat(plugin): added ability to set branch name
Browse files Browse the repository at this point in the history
  • Loading branch information
boyney123 committed Dec 17, 2024
1 parent 8df90cb commit 3a675a5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.

Expand Down
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
14 changes: 14 additions & 0 deletions src/test/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down

0 comments on commit 3a675a5

Please sign in to comment.