Repository navigation
Add Bitbucket Cloud support - #7076
Shubhammete wants to merge 17 commits into
Conversation
…d access bitbucket.proxyPath via config.d.ts Signed-off-by: Shubhammete <[email protected]>
…d access bitbucket.proxyPath via config.d.ts Signed-off-by: Shubhammete <[email protected]>
…d access bitbucket.proxyPath via config.d.ts Signed-off-by: Shubhammete <[email protected]>
…d access bitbucket.proxyPath via config.d.ts Signed-off-by: Shubhammete <[email protected]>
Signed-off-by: Shubhammete <[email protected]>
Signed-off-by: Shubhammete <[email protected]>
Signed-off-by: Shubhammete <[email protected]>
Changed Packages
|
Signed-off-by: Shubhammete <[email protected]>
Signed-off-by: Shubhammete <[email protected]>
mbruhin
left a comment
There was a problem hiding this comment.
Thanks for tackling this! I left a few comments—some of the Bitbucket Cloud endpoints/fields used here don’t appear to match the official docs, and I can’t validate the behavior locally. Please add evidence of Cloud testing (e.g., screenshots or logs) and/or tests covering the new Cloud paths before merge.
|
Hi @mbruhin |
|
This PR has been automatically marked as stale because it has not had recent activity from the author. It will be closed if no further activity occurs. If the PR was closed and you want it re-opened, let us know and we'll re-open the PR so that you can continue the contribution! |
|
Hi @Shubhammete, this closed due to stale and I've reopened it, will you be able to follow up? |
|
HI @awanlin, |
|
This PR has been automatically marked as stale because it has not had recent activity from the author. It will be closed if no further activity occurs. If the PR was closed and you want it re-opened, let us know and we'll re-open the PR so that you can continue the contribution! |
|
Hi @mbruhin |
There was a problem hiding this comment.
Pull request overview
This PR adds initial Bitbucket Cloud support to the Bitbucket Pull Requests plugin while preserving the existing Bitbucket Server/Data Center path.
Changes:
- Adds Cloud/server config detection and separate Cloud fetch/mapping logic.
- Adds Cloud annotation handling and response stubs.
- Updates documentation and release metadata for Cloud support.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
src/utils/isBitbucketSlugSet.ts |
Adds separate Server and Cloud annotation constants. |
src/responseStubs.ts |
Adds Cloud entity and pull request response stubs. |
src/components/Router.tsx |
Uses the shared slug helper for plugin availability. |
src/components/HomePage/HomePagePullRequestsTable.test.tsx |
Updates test mapper usage after mapper rename. |
src/api/BitbucketApi.ts |
Adds Cloud/server routing, Cloud fetch methods, and Cloud response mapping. |
README.md |
Documents Cloud configuration and annotations. |
config.d.ts |
Adds bitbucket.type frontend config schema. |
.changeset/tiny-files-fix.md |
Adds release note for Cloud support. |
Comments suppressed due to low confidence (1)
workspaces/bitbucket-pull-requests/plugins/bitbucket-pull-requests/README.md:56
- The newly documented Cloud mode still uses the proxy block above with
target: https://bitbucket.org, but Bitbucket Cloud REST API calls in this PR are under thehttps://api.bitbucket.org/2.0host. Users copying this configuration for Cloud will proxy requests to the wrong host.
# Defaults to server, set type for cloud hosted bitbucket
type: cloud or server
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…endpoints and added tests Signed-off-by: Shubham Mete <[email protected]>
|
Hi @mbruhin |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 9 changed files in this pull request and generated 5 comments.
Comments suppressed due to low confidence (3)
workspaces/bitbucket-pull-requests/plugins/bitbucket-pull-requests/src/api/BitbucketApi.ts:401
fetchPullRequestListForRepoforwards the UI state directly asstatequery param. The UI usesALLby default, but Bitbucket Cloud does not supportstate=ALL, so the default view will 400/return nothing for cloud instances. TranslateALLto either (a) omit thestateparam or (b) expand to multiplestateparams (OPEN/MERGED/DECLINED/SUPERSEDED) before calling the Cloud endpoint.
const params = new URLSearchParams();
if (state) {
// Cloud uses different state values: OPEN, MERGED, DECLINED, SUPERSEDED
params.append('state', state);
}
params.append('pagelen', limit.toString());
workspaces/bitbucket-pull-requests/plugins/bitbucket-pull-requests/src/api/BitbucketApi.ts:407
- Bitbucket Cloud
pagelenhas an upper bound (commonly 100). Settingpagelento an arbitrarylimitcan cause request failures if callers pass a larger limit. Consider clampinglimitto the Cloud maximum (and/or using paging) before settingpagelen.
const params = new URLSearchParams();
if (state) {
// Cloud uses different state values: OPEN, MERGED, DECLINED, SUPERSEDED
params.append('state', state);
}
params.append('pagelen', limit.toString());
const response = await this.fetchApi.fetch(`${url}?${params}`, {
headers: {
'Content-Type': 'application/json',
},
});
if (!response.ok) {
workspaces/bitbucket-pull-requests/plugins/bitbucket-pull-requests/README.md:57
- Cloud homepage/user PR fetching requires configured workspaces (
bitbucket.cloudWorkspaces), but the configuration section only documentsproxyPathandtype. Add documentation forbitbucket.cloudWorkspaces(and what it should contain) so Cloud users can successfully use the homepage card/user PR features.
bitbucket:
# Defaults to /bitbucket/api and can be omitted if proxy is configured for that url
proxyPath: /bitbucket/api
# Defaults to server, set type for cloud hosted bitbucket
type: cloud or server
</details>
| const proxyUrl = await this.getProxyUrl(); | ||
| const repos: string[] = []; | ||
| let nextUrl: | ||
| | string | ||
| | undefined = `${proxyUrl}${this.proxyPath}/2.0/repositories/${workspace}?pagelen=100`; | ||
|
|
||
| while (nextUrl) { | ||
| const response: Response = await this.fetchApi.fetch(nextUrl, { | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| }); | ||
|
|
||
| if (!response.ok) { | ||
| throw new Error( | ||
| `Failed to fetch repositories for workspace '${workspace}'`, | ||
| ); | ||
| } | ||
|
|
||
| const data: any = await response.json(); | ||
| const pageRepos = (data.values || []) | ||
| .map((repo: any) => repo.slug) | ||
| .filter((slug: any) => typeof slug === 'string'); | ||
| repos.push(...pageRepos); | ||
| nextUrl = data.next; | ||
| } |
|
|
||
| const allPullRequests: PullRequest[] = []; | ||
| for (const workspace of this.cloudWorkspaces) { | ||
| const repos = await this.fetchWorkspaceRepositories(workspace); | ||
| for (const repo of repos) { | ||
| const repoPullRequests = await this.fetchRepoPullRequests( | ||
| workspace, | ||
| repo, | ||
| states, | ||
| Math.min(limit, DEFAULT_LIMIT), | ||
| ); | ||
| allPullRequests.push(...repoPullRequests); | ||
| } | ||
| } | ||
|
|
||
| let pullRequests = allPullRequests; | ||
|
|
||
| // Cloud API returns all PRs for the user, so we filter by role client-side. | ||
| if (role === 'AUTHOR') { | ||
| pullRequests = pullRequests.filter(pr => pr.author.slug === name); | ||
| } else if (role === 'REVIEWER') { | ||
| pullRequests = pullRequests.filter(pr => | ||
| pr.reviewers.some(reviewer => reviewer.slug === name), | ||
| ); | ||
| } | ||
|
|
| # Defaults to server, set type for cloud hosted bitbucket | ||
| type: cloud or server |
| annotations: | ||
| bitbucket.com/project-slug: <example-bitbucket-project-name>/<example-bitbucket-repo-name> | ||
| # For Bitbucket cloud use | ||
| bitbucket.org/repo-slug: my-workspace/my-repo |
| @@ -173,52 +203,45 @@ describe('PullRequestList', () => { | |||
| </TestApiProvider>, | |||
| ); | |||
|
|
|||
| // Wait for initial load and confirm default state is ALL | |||
| // Verify table still renders with no data | |||
| await waitFor(() => { | |||
| expect(screen.getByText('Bitbucket Pull Requests')).toBeInTheDocument(); | |||
| expect(lastStateParam).toBe('ALL'); | |||
| }); | |||
|
|
|||
| // Click on the Merged filter button and ensure subsequent call uses MERGED | |||
| const mergedButton = screen.getByRole('button', { name: /Merged/i }); | |||
| await userEvent.click(mergedButton); | |||
|
|
|||
| await waitFor(() => { | |||
| expect(lastStateParam).toBe('MERGED'); | |||
| // No data text should be visible (or similar empty state indicator) | |||
| // This depends on what the component shows when there's no data | |||
| expect(screen.queryByText(/^#\d+$/)).not.toBeInTheDocument(); | |||
| }); | |||
| }); | |||
|
|
|||
| it('should handle empty PR list', async () => { | |||
| // Mock empty response | |||
| const emptyResponseStub = { | |||
| size: 0, | |||
| limit: 25, | |||
| isLastPage: true, | |||
| values: [], | |||
| start: 0, | |||
| }; | |||
|
|
|||
| it('should display cloud pull requests for cloud-annotated entities', async () => { | |||
| worker.use( | |||
| rest.get( | |||
| 'http://exampleapi.com/bitbucket/api/projects/testproject/repos/testrepo/pull-requests', | |||
| (_, res, ctx) => res(ctx.json(emptyResponseStub)), | |||
| 'http://exampleapi.com/bitbucket/api/2.0/repositories/myworkspace/example-project/pullrequests', | |||
| (_, res, ctx) => res(ctx.json(pullRequestsCloudResponseStub)), | |||
| ), | |||
| ); | |||
|
|
|||
| render( | |||
| <TestApiProvider apis={apis}> | |||
| <EntityProvider entity={entityStub}> | |||
| <TestApiProvider apis={cloudApis}> | |||
| <EntityProvider entity={entityCloudStub}> | |||
| <PullRequestList /> | |||
| </EntityProvider> | |||
| </TestApiProvider>, | |||
| ); | |||
|
|
|||
| // Verify table still renders with no data | |||
| await waitFor(() => { | |||
| expect(screen.getByText('Bitbucket Pull Requests')).toBeInTheDocument(); | |||
| // No data text should be visible (or similar empty state indicator) | |||
| // This depends on what the component shows when there's no data | |||
| expect(screen.queryByText(/^#\d+$/)).not.toBeInTheDocument(); | |||
| }); | |||
|
|
|||
| await waitFor(() => { | |||
| pullRequestsCloudResponseStub.values.forEach(pr => { | |||
| expect(screen.getByText(pr.title)).toBeInTheDocument(); | |||
| }); | |||
| }); | |||
|
|
|||
| expect( | |||
| screen.getByText( | |||
| pullRequestsCloudResponseStub.values[0].author.display_name, | |||
| ), | |||
| ).toBeInTheDocument(); | |||
| }); | |||
| }); | |||
|
Hi @awanlin @mbruhin @Parsifal-M
The setup is working as expected with the following configuration: apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
name: bitbucket
annotations:
# Format: workspace/repo for Cloud, PROJECT/repo for Server
bitbucket.org/repo-slug: demo-project/demo-repo
spec:
type: website
lifecycle: experimental
owner: guests
system: examples
app-config.yaml ....
type: cloud
proxyPath: /bitbucket/api
proxy:
'/bitbucket/api':
target: https://api.bitbucket.org
changeOrigin: true
headers:
Authorization: Basic ${BITBUCKET_TOKEN}
Accept: 'application/json'
Content-Type: 'application/json'
....Please let me know if this aligns with the expected approach or if I should explore any additional scenarios. |
|
This PR has been automatically marked as stale because it has not had recent activity from the author. It will be closed if no further activity occurs. If the PR was closed and you want it re-opened, let us know and we'll re-open the PR so that you can continue the contribution! |
|
Hi @awanlin @mbruhin @smymoon @Parsifal-M |
awanlin
left a comment
There was a problem hiding this comment.
Hi @Shubhammete, there's a few outstanding comments that need to be addressed:
- Pagination bypasses proxy —
data.nextreturns absolute Bitbucket URLs that skip the Backstage proxy, breaking auth/CORS - Sequential repo enumeration is slow — Cloud user PRs iterate every repo in every workspace sequentially; will hit rate limits on large workspaces
- Invalid YAML example —
type: cloud or serveris a literal string, not a valid config value - Annotation key mismatch — README says
bitbucket.org/repo-slug, code usesbitbucket.com/repo-slug - Missing state filter test — The test verifying state query params was removed and not replaced
I've also added two of my own. 👍
| options.configApi?.getOptionalString('bitbucket.proxyPath') || | ||
| DEFAULT_PROXY_PATH; | ||
| const cloudWorkspaces = | ||
| options.configApi?.getOptionalStringArray('bitbucket.cloudWorkspaces') || |
There was a problem hiding this comment.
This - bitbucket.cloudWorkspaces - isn't in the config.d.ts or the README.
|
|
||
| public mapServerPullRequests(data: any): PullRequest[] { | ||
| return mapServerPullRequests(data); | ||
| } |
There was a problem hiding this comment.
This seems a little odd, why is this here?
|
Thanks @awanlin for the review. I will review all the comments and resolve them! |
|
Hi @awanlin, @mbruhin, @Parsifal-M, @smymoon |

Hey, I just made a Pull Request!
This PR adds initial support for Bitbucket Cloud to the Bitbucket Pull Requests plugin, which previously only supported Bitbucket Data Center.
Organizations using Bitbucket Cloud can now fetch and view pull requests inside Backstage using the official Bitbucket Cloud REST API, while keeping full backward compatibility with existing Data Center users.
✔️ Checklist
Signed-off-byline in the message. (more info)Fixes #6814