Skip to content

Commit

Permalink
Merge pull request #107 from event-catalog/owner-and-repo-now-persisted
Browse files Browse the repository at this point in the history
fix(plugin): owner and repo are now persisted between builds and vers…
  • Loading branch information
boyney123 authored Jan 24, 2025
2 parents 0b7ffcb + 0c120fb commit 00f4c94
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/ten-knives-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@eventcatalog/generator-asyncapi": patch
---

fix(plugin): owner and repo are now persisted between builds versions
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"dependencies": {
"@asyncapi/avro-schema-parser": "^3.0.24",
"@asyncapi/parser": "^3.3.0",
"@eventcatalog/sdk": "^1.4.1",
"@eventcatalog/sdk": "^1.4.4",
"chalk": "^4",
"fs-extra": "^11.2.0",
"glob": "^11.0.0",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ export default async (config: any, options: Props) => {
let sends = [];
let receives = [];

let owners = null;
let repository = null;

let serviceSpecifications = {};
let serviceSpecificationsFiles = [];
let serviceMarkdown = generateMarkdownForService(document);
Expand Down Expand Up @@ -352,6 +355,9 @@ export default async (config: any, options: Props) => {

if (latestServiceInCatalog) {
serviceMarkdown = latestServiceInCatalog.markdown;
owners = latestServiceInCatalog.owners || ([] as any);
repository = latestServiceInCatalog.repository || null;

// Found a service, and versions do not match, we need to version the one already there
if (latestServiceInCatalog.version !== version) {
await versionService(serviceId);
Expand Down Expand Up @@ -386,6 +392,8 @@ export default async (config: any, options: Props) => {
...serviceSpecifications,
asyncapiPath: fileName || 'asyncapi.yml',
},
...(owners && { owners }),
...(repository && { repository }),
},
{
override: true,
Expand Down
47 changes: 47 additions & 0 deletions src/test/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,53 @@ describe('AsyncAPI EventCatalog Plugin', () => {
);
});

it('when the AsyncAPI service is already defined in EventCatalog and the versions match, the owners and repo are persisted', async () => {
// Create a service with the same name and version as the AsyncAPI file for testing
const { writeService, getService } = utils(catalogDir);

await writeService({
id: 'account-service',
version: '1.0.0',
name: 'Random Name',
owners: ['dboyne'],
repository: {
language: 'typescript',
url: 'https://github.com/dboyne/eventcatalog',
},
markdown: 'Here is my original markdown, please do not override this!',
});

await plugin(config, { services: [{ path: join(asyncAPIExamplesDir, 'simple.asyncapi.yml'), id: 'account-service' }] });

const service = await getService('account-service', '1.0.0');
expect(service).toEqual(
expect.objectContaining({
id: 'account-service',
name: 'Account Service',
version: '1.0.0',
summary: 'This service is in charge of processing user signups',
owners: ['dboyne'],
repository: {
language: 'typescript',
url: 'https://github.com/dboyne/eventcatalog',
},
markdown: 'Here is my original markdown, please do not override this!',
badges: [
{
content: 'Events',
textColor: 'blue',
backgroundColor: 'blue',
},
{
content: 'Authentication',
textColor: 'blue',
backgroundColor: 'blue',
},
],
})
);
});

it('when the AsyncAPI service is already defined in EventCatalog and the versions do not match, a new service is created and the old one is versioned', async () => {
// Create a service with the same name and version as the AsyncAPI file for testing
const { writeService, getService } = utils(catalogDir);
Expand Down

0 comments on commit 00f4c94

Please sign in to comment.