Skip to content

chore: add prototype/example code for adding dynamic entity tags #11

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

Merged
merged 13 commits into from
Mar 1, 2024

Conversation

Parkreiner
Copy link
Member

@Parkreiner Parkreiner commented Feb 28, 2024

Closes #49

Changes made

  • Adds backend plugin scaffolding
  • Adds logic for dynamically adding/removing devcontainers tags

Notes

  • The vast majority of the files were added by Backstage's scaffolder
    • If I didn't add a comment to the file, you can probably ignore it

@Parkreiner Parkreiner self-assigned this Feb 28, 2024
@@ -0,0 +1,130 @@
/**
Copy link
Member Author

@Parkreiner Parkreiner Feb 28, 2024

Choose a reason for hiding this comment

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

This is the main file. I'm sure the todo's aren't exhaustive, but I tried to cover as much ground as I could (though credit where it's due, a lot of them were added by Asher while we were doing the pair programming session)

Comment on lines +40 to +45
constructor(urlReader: UrlReader, options: ProcessorOptions) {
this.urlReader = urlReader;
this.options = options;
}

static fromConfig(readerConfig: Config, options: ProcessorSetupOptions) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a pattern that a lot of the plugins use, where they basically give you access to the raw constructor if you really need it, but you can also call the static fromConfig method to set things up with more sensible defaults

}
>;

export class DevcontainersProcessor implements CatalogProcessor {
Copy link
Member Author

@Parkreiner Parkreiner Feb 28, 2024

Choose a reason for hiding this comment

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

The CatalogProcessor interface has five methods on it:

  • getProcessorName (required)
  • readLocation (optional)
  • preProcessEntity(optional)
  • postProcessEntity(optional)
  • validateEntityKind(optional)

preProcessEntity is mainly for adding additional data right before the entity actually gets processed for real

We're also allowed to add any number of other methods/properties, but for safety, I'm keeping them all private

Comment on lines +25 to +30
builder.addProcessor(
DevcontainersProcessor.fromConfig(env.config, {
logger: env.logger,
eraseTags: false,
}),
);
Copy link
Member Author

Choose a reason for hiding this comment

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

This is where the plugin gets wired up to the deployment


const isGithubComponent = cleanUrl.includes('github.com');
if (!isGithubComponent) {
return this.eraseTag(entity, DEFAULT_TAG_NAME);
Copy link
Member

Choose a reason for hiding this comment

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

What's this part for?

Copy link
Member

Choose a reason for hiding this comment

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

Also, do we need to worry about other providers?

Copy link
Member Author

@Parkreiner Parkreiner Mar 1, 2024

Choose a reason for hiding this comment

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

It's mainly a quick check to see if the component even looks vaguely right, before we start kicking off more computationally-intense async requests with the search API

We will need to worry about other providers eventually, but I think the details are going to depend on what Asher turns up with the URLReader, so I didn't want to add extra code for Gitlab/Bitbucket just yet

Copy link
Member

Choose a reason for hiding this comment

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

@Parkreiner why do we erase the tag if it's not a Github component?

Copy link
Member Author

@Parkreiner Parkreiner Mar 1, 2024

Choose a reason for hiding this comment

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

Well, it's just a preemptive move. I guess I was erring on the side of kicking logic off to the eraseTags method whenever there isn't a match, and having it decide whether it should erase anything

It wouldn't be too bad to decentralize the logic, but doing it this way makes sure that the checks for whether an erase should happen all happen in one central method. The pre-process method doesn't need to know whether the tag actually gets erased – as long as it delegates to the other method, that method can choose what happens next

Copy link
Member

Choose a reason for hiding this comment

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

Ooo, I like the centralization! I was more curious why we were erasing at all. I would assume that if it's not a GitHub component (or Bitbucket component, or GitLab component) we return the entity as-is.

builder.addProcessor(
DevcontainersProcessor.fromConfig(env.config, {
logger: env.logger,
eraseTags: false,
Copy link
Member

Choose a reason for hiding this comment

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

Let's just double check with Ben about the default here. I'll add it to our check-in notes.

Copy link
Member

@Kira-Pilot Kira-Pilot left a comment

Choose a reason for hiding this comment

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

This looks great!

@Parkreiner Parkreiner merged commit 46bdea5 into main Mar 1, 2024
@Parkreiner Parkreiner deleted the devcontainers-tag branch March 1, 2024 20:02
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