feat(x2a): bitbucket git repos support#2510
feat(x2a): bitbucket git repos support#2510mareklibra wants to merge 3 commits intoredhat-developer:mainfrom
Conversation
Changed Packages
|
Review Summary by QodoAdd Bitbucket cloud repository support with OAuth authentication
WalkthroughsDescription• Add Bitbucket cloud repository support for authentication and operations • Implement Bitbucket-specific token formatting and OAuth scope handling • Support Bitbucket URL normalization in RepoUrlPicker component • Add Bitbucket branch and artifact URL builders with proper formatting Diagramflowchart LR
A["Bitbucket OAuth"] -->|"Auth Module"| B["Backend Registration"]
C["Repository URL"] -->|"getScmProvider"| D["Detect Bitbucket"]
D -->|"getAuthTokenDescriptor"| E["OAuth Scopes"]
E -->|"augmentRepoToken"| F["x-token-auth: token"]
C -->|"normalizeRepoUrl"| G["Clone URL"]
G -->|"buildRepoBranchUrl"| H["Branch URL"]
G -->|"buildArtifactUrl"| I["Artifact URL"]
F -->|"useRepoAuth"| J["Authenticated Operations"]
File Changes1. workspaces/x2a/packages/backend/src/index.ts
|
Code Review by Qodo
1. Repo URL leaked to logs
|
adb1860 to
ddf3fd8
Compare
ddf3fd8 to
ebecdaf
Compare
eloycoto
left a comment
There was a problem hiding this comment.
I have the feeling that we should move this to auth/provider/github.ts, auth/provider/gitlab.ts and auth/provider/bitbucket.ts
This is getting super complicated, and we should implement some kind of traits, on how the AuthN is done.
We have enough time to deliver this, can you do a refactor here?
workspaces/x2a/plugins/x2a-common/src/utils/getAuthTokenDescriptor.ts
Outdated
Show resolved
Hide resolved
|
I can do such refactoring, it will be easier to maintain if we need to add another provider. I will explore how to detect the provider in a more robust way than just via URL matching. |
Signed-off-by: Marek Libra <marek.libra@gmail.com>
da0c9ec to
c36b94d
Compare
Review Summary by QodoAdd Bitbucket Cloud support with SCM provider abstraction layer
WalkthroughsDescription• Add Bitbucket Cloud repository support for authentication and scaffolding • Refactor SCM provider abstraction layer with configurable host detection • Support custom-domain SCM hosts via integrations: config section • Update token augmentation and URL building for provider-specific formats Diagramflowchart LR
Config["Backstage Config<br/>integrations:"]
BuildMap["buildScmHostMap()"]
ResolveProvider["resolveScmProvider()"]
Provider["ScmProvider<br/>github/gitlab/bitbucket"]
Token["augmentToken()"]
URL["buildBranchUrl()<br/>buildArtifactUrl()"]
Config -->|reads| BuildMap
BuildMap -->|creates| ResolveProvider
ResolveProvider -->|returns| Provider
Provider -->|formats| Token
Provider -->|generates| URL
File Changes1. workspaces/x2a/plugins/x2a-common/src/scm/ScmProvider.ts
|
Code Review by Qodo
1. Substring provider misdetection
|
An abstraction layer separating individual providers is introduced. The providers are detected based on configurable host name, keeping the URL matching for well-known SCM hostnames as a fallback. Signed-off-by: Marek Libra <marek.libra@gmail.com>
c36b94d to
fd9c93b
Compare
| buildArtifactUrl: (origin, path, encodedBranch, filePath) => | ||
| `${origin}${path}/-/blob/${encodedBranch}/${filePath}`, |
There was a problem hiding this comment.
I'm wondering - is the /blob/ path formation the same across providers? or is it github specific
There was a problem hiding this comment.
bitbucket has /src/, but github and gitlab use /blob/.
Worked for me... :-)
| if (repo.startsWith('https://') || repo.startsWith('http://')) { | ||
| const repoUrl = new URL(repo); | ||
| const segments = repoUrl.pathname.split('/').filter(Boolean); | ||
| repo = segments[segments.length - 1] ?? repo; |
There was a problem hiding this comment.
should we also strip the .git part?
There was a problem hiding this comment.
This is what goes from the RepoUrlPicker component which is without the ending .git.
This function is called just once from the createProject scaffolder action. Since then, we use the value returned here, so with .git already.
| try { | ||
| const trimmed = repoUrl.trim(); | ||
| const urlStr = trimmed.includes('://') ? trimmed : `https://${trimmed}`; | ||
| return new URL(urlStr).hostname; |
There was a problem hiding this comment.
edge case: two internal providers (gitlab on port 8080 and gitlab on port 9090) will collide on the map, as the URL() strips the port
we can do new URL(urlStr).host instead
There was a problem hiding this comment.
good point, fixing it
49d1a2b to
503f882
Compare
|



Fixes: FLPATH-3389
The application authentication plus source and target repos newly support the Bitbucket.
App authentication configuration works by following https://backstage.io/docs/auth/bitbucket/provider/.
OAuth token scopes and other requirements are documented in the README, there are specifics especially regarding username and resolver.
Tested on a private Bitbucket project (so requiring authenticated access), both
git pushandgit pull.Works well against cloud-based Bitbucket.
In case there is a requirement for a Bitbucket server (self-hosted, custom domain), additional work is needed, especially around SCN provider detection (so far naive implementation via parsing URL).
The source and target repos can be freely combined or reused.
Test matrix: