Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(plugin): owner and repo are now persisted between builds and vers… #107

Merged
merged 3 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading