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: add new BitbucketCloudEntityProvider and common/shared client lib #11345

Merged

Conversation

pjungermann
Copy link
Contributor

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)
  • All your commits have a Signed-off-by line in the message. (more info)

@pjungermann pjungermann requested review from a team and backstage-service as code owners May 5, 2022 23:18
@github-actions github-actions bot added awaiting-review area:catalog Related to the Catalog Project Area documentation Improvements or additions to documentation microsite Changes to backstage.io labels May 5, 2022
@github-actions
Copy link
Contributor

github-actions bot commented May 5, 2022

Changed Packages

Package Name Package Path Changeset Bump Current Version
@backstage/plugin-bitbucket-cloud-common plugins/bitbucket-cloud-common minor v0.0.0
@backstage/plugin-catalog-backend-module-bitbucket-cloud plugins/catalog-backend-module-bitbucket-cloud minor v0.0.0
@backstage/plugin-catalog-backend-module-bitbucket plugins/catalog-backend-module-bitbucket minor v0.1.4-next.0

Copy link
Member

@freben freben left a comment

Choose a reason for hiding this comment

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

This is huge work, thank you. I hope the comments don't deter.

.changeset/fluffy-cherries-own.md Outdated Show resolved Hide resolved
docs/integrations/bitbucketCloud/locations.md Outdated Show resolved Hide resolved
docs/integrations/bitbucketCloud/locations.md Outdated Show resolved Hide resolved
docs/integrations/bitbucketCloud/discovery.md Outdated Show resolved Hide resolved
docs/integrations/bitbucketCloud/discovery.md Outdated Show resolved Hide resolved
plugins/bitbucket-cloud-common/src/BitbucketCloudConfig.ts Outdated Show resolved Hide resolved
plugins/bitbucket-cloud-common/src/BitbucketCloud.ts Outdated Show resolved Hide resolved
plugins/catalog-backend-module-bitbucket-cloud/config.d.ts Outdated Show resolved Hide resolved
Copy link
Member

@jhaals jhaals left a comment

Choose a reason for hiding this comment

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

As already mentioned, great work(as always) Patrick!

The one thing that really complicates this PR is the client generation making the PR gigantic with all the schemas and generated API report.
I'm slightly worried that this ties us too close to the generated code and client. In most cases we try hard not tying ourselves too hard to for other libraries to be able to switch out the client when a new one pops up which is fairly common in javascript land.

Secondly we have very little tooling and common knowledge with schema generation in the repository making this a big risk of technical depth if you decide to work on other things in the future. Is there alternatives to the generation approach proposed in this PR?

I hope you don't take take this as negativity as introducing this method of generation is a big deal for the repository and tooling so it require careful consideration if we go down this path :)

@pjungermann
Copy link
Contributor Author

pjungermann commented May 20, 2022

@jhaals all fair points!

Let's start with alternatives:

  • use an external client library as dependency
  • manual written DTOs
  • generating models and the client/operations
  • other form of generation and/or alignment with the API schema

The one thing that really complicates this PR is the client generation making the PR gigantic with all the schemas and generated API report.

Yes, you are right. It got big due to it being the first time and including all models.
I even decided not to generate the operations. Mostly due influence the design. And start small. Probably, it can be generated, too, by creating a template accordingly. This would make it even bigger, too, though.

Only including the models which are actually used by the client implementation would reduce it considerably, though. Maybe a bit harder to add additional endpoints (without existing models).

I'm slightly worried that this ties us too close to the generated code and client. In most cases we try hard not tying ourselves too hard to for other libraries to be able to switch out the client when a new one pops up which is fairly common in javascript land.

At the end, we control the client and how it looks like by the templates used to generate them. The client lib is inside the backstage project, too. It is easier to change compared to external client libraries.

Secondly we have very little tooling and common knowledge with schema generation in the repository making this a big risk of technical depth if you decide to work on other things in the future.

Picking up the generator didn't took me long. Code generators for OpenAPI schema (client and/or server) are not that uncommon. Still, it takes a moment to get into this, of course.

Is there alternatives to the generation approach proposed in this PR?
Active maintenance, security, etc. are less of concern/more controlled compared to external libraries.

External libraries are likely more feature complete. Extensibility depends on the implementation.
Actually, I even looked for external ones and briefly considered one. Atlassian itself started one, but discontinued the project. Bitbucket.js is quite feature rich and complete considering the API coverage, but has only one maintainer, etc. Implementation regarding loading of data is a bit different, but ok. Also, it didn't work well in Backstage's project env.

Or, we could handwrite all models and APIs. Only those we need at the moment. Manually creating the models vs generating is more error prone though.

The generation is just a means to stay in sync and correct. It should help reduce maintenance efforts.

As you saw, I was doing some improvements to the API schema (has a few bugs; other parts make it easier for generating the right output).

it require careful consideration

Fully agree and open for discussion and open for changing the approach, too.

@pjungermann pjungermann force-pushed the PJ_bitbucketCloud-provider branch 2 times, most recently from 42be7a6 to d7de3e6 Compare May 22, 2022 23:18
@pjungermann pjungermann requested a review from jhaals May 23, 2022 08:47
@pjungermann pjungermann force-pushed the PJ_bitbucketCloud-provider branch 2 times, most recently from 3b88954 to 02a291a Compare May 25, 2022 23:16
@pjungermann
Copy link
Contributor Author

E2E test/cypress is timing out a lot. Trying to retrigger the build by reuploading the last commit

Copy link
Member

@Rugvip Rugvip left a comment

Choose a reason for hiding this comment

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

Awesome stuff overall 😁 ❤️

Brought up some concerns about the code generation, but I think we should be able to figure out a way to ship this.

I'm feeling that if we do end up stuck in the future where we can't update the model, there is always the option of to drop the generation and continue with hand crafted models, especially if needed for a temporary fix.

Btw, a middle-ground that I want to hear your thoughts on is: what do you think about using the code generation only as a tool for authoring code? So rather using the generated model directly, we copy over the subset that we have the need for in the project right now? That'd reduce the API surface a lot. We could still keep the generated types and modifications so that it's as close to a simple copy-paste as possible, even in source control for easy diffing. Then over time if we eventually feel we just want the entire thing we could start using the generated code directly instead?

Not gonna block this on the failing cypress tests btw, but will keep an eye on that.

@pjungermann
Copy link
Contributor Author

Btw, a middle-ground that I want to hear your thoughts on is: what do you think about using the code generation only as a tool for authoring code? So rather using the generated model directly, we copy over the subset that we have the need for in the project right now? That'd reduce the API surface a lot. We could still keep the generated types and modifications so that it's as close to a simple copy-paste as possible, even in source control for easy diffing. Then over time if we eventually feel we just want the entire thing we could start using the generated code directly instead?

Sure, we can do that. Manually is easy, automatic a bit more tricky.

..but yeah.. I guess it makes sense. I was a bit in-between as generating the full model makes adding new endpoints a little easier. But smaller API surface is great, too.

Add `bitbucket-cloud-common`
(`@backstage/plugin-bitbucket-cloud-common`)
with a new client for Bitbucket Cloud.

The lib contains auto-generated models
which got generated using `@openapitools/openapi-generator-cli`.

Signed-off-by: Patrick Jungermann <Patrick.Jungermann@gmail.com>
…itbucket`

Signed-off-by: Patrick Jungermann <Patrick.Jungermann@gmail.com>
@pjungermann
Copy link
Contributor Author

@Rugvip I took care of all points including reducing the models to have the minimal API surface possible. It is automated (yarn reduce-models) and I wrote it in a way that it is easy to add new methods/endpoints to the client (documented, too).

As this is my first use of ts-morph, let me know if you see any potential improvements. :)

@pjungermann pjungermann requested a review from Rugvip May 29, 2022 23:12
@pjungermann pjungermann force-pushed the PJ_bitbucketCloud-provider branch 2 times, most recently from d9e2c7a to caab993 Compare May 29, 2022 23:23
Copy link
Member

@Rugvip Rugvip left a comment

Choose a reason for hiding this comment

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

Thank you! 🎉

Reduced model does look nicer, and I'm able to verify that it's stable too, at least in my environment. Feeling it's time to :shipit:

Tiny nit to fix but not a blocker, just giving @backstage/maintainers some extra time to have a look again 😁

microsite/sidebars.json Show resolved Hide resolved
Add a new entity provider `BitbucketCloudEntityProvider`
as a new plugin `@backstage/plugin-catalog-backend-module-bitbucket-cloud`.

The new plugin utilizes `@backstage/plugin-bitbucket-cloud-common`
and it fully independent of `@backstage/plugin-catalog-backend-module-bitbucket`
which provides a catalog processors supporting Bitbucket Cloud and Bitbucket Server.

Relates-to: backstage#9923
Relates-to: backstage#10183
Signed-off-by: Patrick Jungermann <Patrick.Jungermann@gmail.com>
Copy link
Member

@benjdlambert benjdlambert left a comment

Choose a reason for hiding this comment

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

Yep - ok. Let's get this in 🚢

@Rugvip Rugvip merged commit d54a7d0 into backstage:master May 30, 2022
@pjungermann pjungermann deleted the PJ_bitbucketCloud-provider branch May 30, 2022 13:14
@benjdlambert benjdlambert mentioned this pull request Jun 14, 2022
@diegomarangoni
Copy link
Contributor

diegomarangoni commented Jul 27, 2022

In the bitbucket-discovery plugin I could use parameter rules to limit the allowed entity kinds, is there a way to restrict entity kinds with this entity provider?

@pjungermann
Copy link
Contributor Author

@diegomarangoni Unfortunately, at the moment only default rules apply as these rules need to be added to the Location entities which is managed by the static config entity provider reading the locations from the app-config.yaml.

I mentioned this case at another PR, too
#10480 (comment)

I plan to add a feature for it, but it still does not exist. And there is no issue yet.

@pjungermann
Copy link
Contributor Author

@diegomarangoni I created issue #12880 as follow up related to the "allow" rule

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:catalog Related to the Catalog Project Area documentation Improvements or additions to documentation microsite Changes to backstage.io
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants