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

feat(marketplace-cli): Create marketplace-cli subcommand to generate CSV files from YAML files #470

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

logonoff
Copy link
Contributor

@logonoff logonoff commented Mar 4, 2025

implements https://issues.redhat.com/browse/RHIDP-6231

Hey, I just made a Pull Request!

✔️ Checklist

  • A changeset describing the change and affected packages. (more info)
  • Added or Updated documentation
  • Tests for new functionality and regression tests for bug fixes
  • Screenshots attached (for UI changes)

@rhdh-gh-app
Copy link

rhdh-gh-app bot commented Mar 4, 2025

Important

This PR includes changes that affect public-facing API. Please ensure you are adding/updating documentation for new features or behavior.

Changed Packages

Package Name Package Path Changeset Bump Current Version
@red-hat-developer-hub/marketplace-cli workspaces/marketplace/packages/cli minor v0.2.0

@logonoff
Copy link
Contributor Author

logonoff commented Mar 4, 2025

WIP PR to implement the CSV subcommand.

@christoph-jerolimov am I on the right track/reading from the right files?

@logonoff logonoff force-pushed the csv branch 5 times, most recently from cb2e11c to cc183dd Compare March 4, 2025 22:24
@christoph-jerolimov
Copy link
Member

WIP PR to implement the CSV subcommand.

@christoph-jerolimov am I on the right track/reading from the right files?

Yeah that's a really good direction. 👍

Please extend this so that you read all YAMLs from theplugins and packages folder and see if we can have a combination of both.

We don't know the exact data we want export, but it would be great if you can show for each plugin (contains the most metadata) show the related frontend and backend package. Incl. the npm package name and version.

These are linked via their backstage catalog entity names.

Copy link

sonarqubecloud bot commented Mar 5, 2025

Copy link
Member

@christoph-jerolimov christoph-jerolimov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @logonoff, good work so far. I hope the comments below helps:

*/
key: string;
/** The getter function for each cell. The return value must be castable to a string */
getter: (plugin: T) => any;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tiny: if this CSVGenerator is generic, try to avoid "plugin" code or variables here.

I would also recommend to avoid any. Can it maybe return a string | number?

Comment on lines +136 to +143
const plugins = fileContent
.split('\n---\n')
.filter(Boolean)
.map((plugin: string) => {
return YAML.parse(plugin);
})
.filter(isEntity);
return plugins;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, the YAML library supports parsing multiple docs via YAML.parseAllDocuments. Each document should have something like toJSON.

Suggested change
const plugins = fileContent
.split('\n---\n')
.filter(Boolean)
.map((plugin: string) => {
return YAML.parse(plugin);
})
.filter(isEntity);
return plugins;
const plugins = YAML.parseAllDocuments(fileContent)
.map((doc => doc.toJSON())
.filter(isMarketplacePlugin)
return plugins;

Comment on lines +150 to +160
* Fetches a `package.json` from a given package from the npm registry.
* @param packageName The name of the package to fetch
* @returns The package.json object
*/
const fetchNpmPackageJson = async (packageName: string, version: string) => {
const response = await fetch(
`https://registry.npmjs.org/${packageName}/${version}`,
);

return await response.json();
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a "nice idea" but there is no need to fetch external information. All information should be part of the Plugin or Package YAML.

Esp. the descriptions and version strings. You can drop that code.

Comment on lines +162 to +165
type CombinedPackage = {
yaml: MarketplacePackage;
pkg: PackageJson;
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is good, but could be something like this:

Suggested change
type CombinedPackage = {
yaml: MarketplacePackage;
pkg: PackageJson;
};
type CombinedPackage = {
plugin: MarketplacePlugin;
frontendPackage?: MarketplacePackage;
backendPackage?: MarketplacePackage;
otherPackages?: MarketplcaePackage[];
};

The plugin and packages YAMLs contains many information and you should parse them, find the relationships and render "grouped information". The main entity == one row should be the plugin.

But a plugin can link zero, one or more packages.

For example:

https://github.com/redhat-developer/rhdh/blob/main/catalog-entities/marketplace/plugins/kubernetes.yaml#L91-L93
https://github.com/redhat-developer/rhdh/blob/main/catalog-entities/marketplace/packages/backstage-plugin-kubernetes.yaml#L4
https://github.com/redhat-developer/rhdh/blob/main/catalog-entities/marketplace/packages/backstage-plugin-kubernetes-backend.yaml#L4

So the CLI should load all plugins and all packages. At the end, you should iterate over all plugins and try to find related Packages.

The spec.backstage.role identifies if the Package is a a frontend or backend plugin:

https://github.com/redhat-developer/rhdh/blob/main/catalog-entities/marketplace/packages/backstage-plugin-kubernetes.yaml#L22-L23
https://github.com/redhat-developer/rhdh/blob/main/catalog-entities/marketplace/packages/backstage-plugin-kubernetes-backend.yaml#L22-L23

And then you can display in the CSV the Plugin name, description (and so one), and the frontend and backend package version.

Does this make sense to you?

'name',
'title',
'description',
'developer',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We used author and developer in some YAMLs. The final version uses "author"

Suggested change
'developer',
'author',

'developer',
'categories',
'lifecycle',
'icon',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We used "icon" with an URL while developing the plugin. In the current version we use inline base64 icons. I guess we should skip this information until we have another soliution.

Suggested change
'icon',

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants