Skip to content

feat(bitbucket-pull-requests): add Bitbucket Cloud support - #10278

Merged
awanlin merged 21 commits into
backstage:mainfrom
Shubhammete:bitbucket-pull-requests-backup
Oct 2, 2026
Merged

awanlin merged 21 commits into
backstage:mainfrom
Shubhammete:bitbucket-pull-requests-backup

Conversation

@Shubhammete

@Shubhammete Shubhammete commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Hey, I just made a Pull Request!

Note: This is a replacement for my previous PR (#7076). I accidentally closed the previous PR while working on it by deleting the head repository. The changes have been restored and rebased , so I'm opening this PR again with the same intended functionality.

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

  • 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)

Fixes #6814

@backstage-goalie

Copy link
Copy Markdown
Contributor

Changed Packages

Package Name Package Path Changeset Bump Current Version
@backstage-community/plugin-bitbucket-pull-requests workspaces/bitbucket-pull-requests/plugins/bitbucket-pull-requests major v3.0.3

@Shubhammete

Copy link
Copy Markdown
Contributor Author

Hi @awanlin, @mbruhin, @Parsifal-M, @smymoon

I accidentally deleted the head repository for the previous PR (#7076). I've addressed all review comments and recreated the changes in this new PR.

Could you please take another look? Thank you!

@awanlin awanlin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the follow up @Shubhammete, with this being split up I ended up doing a deeper review trying to cross check these, sorry there's more comment and not simply an approval this time around. I do think if you follow up on these comments we should be very close! 👍

options.configApi?.getOptionalString('bitbucket.proxyPath') ||
DEFAULT_PROXY_PATH;
const cloudWorkspaces =
options.configApi?.getOptionalStringArray('bitbucket.cloudWorkspaces') ||

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is not in the config.d.ts file and would be great to have documented in the README

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

My bad, thanks for highlighting this! I have now added cloudWorkspaces to config.d.ts and included the setup documentation in the README

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Non-blocking: would be great to see tests for this, I know there are none currently which is why this comment is optional.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added unit tests for BitbucketApi covering the response mappers and the pagelen cap:

  • mapServerPullRequests / mapCloudPullRequests : verify Server and Cloud API responses are transformed to the internal PullRequest shape correctly, including the empty-list case and missing summary on Cloud PRs.
  • fetchPullRequestListForRepo : verifies pagelen is capped at 50 even when a higher limit is requested, covering the fix from the earlier comment.

Reused the existing pullRequestsResponseStub/pullRequestsCloudResponseStub fixtures from responseStubs.ts instead of new mock data, to stay consistent with PullRequestList.test.tsx.

.fetchPullRequestListForRepo(
projectName,
repoName,
stateFilter !== 'ALL' ? stateFilter : undefined,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Something feels off about this filter. Should we not use the same as this form about line 451?

const states = state === 'ALL' ? ['OPEN', 'MERGED', 'DECLINED', 'SUPERSEDED'] : [state];

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this is a mismatch between the UI abstraction and the Bitbucket Cloud API contract.
The UI exposes ALL/OPEN/MERGED/DECLINED, but Bitbucket Cloud does not support a literal [state=ALL]

The Cloud client expands ALL into the valid Bitbucket states (OPEN, MERGED, DECLINED, SUPERSEDED) before calling the API. The repo-level fetch path only passes a single concrete state, so the logic differs by endpoint. This is intentional API normalization, not a bug.

Docs - https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pullrequests/#api-repositories-workspace-repo-slug-pullrequests-get

const [status, setStatus] = useState('ALL');

const handleStatusChange = (newStatus: PullRequestState) => {
const handleStatusChange = (newStatus: any) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Really want to avoid using any

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added type for Status fliter

const response = await this.fetchApi.fetch(`${url}?${params}`, {
headers: {
'Content-Type': 'application/json',
function mapServerPullRequests(data: any): PullRequest[] {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These mappser only look to be used by tests, should they be elsewhere?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These mapper functions actually used in fetchUserPullRequests() and fetchPullRequestListForRepo() to transform the Bitbucket API responses into our internal PullRequest type


// Collect all repos across all workspaces first
const repoTasks: Array<{ workspace: string; repo: string }> = [];
for (const workspace of this.cloudWorkspaces) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should probably do Promise.all here as this workspace-level enumeration is sequential. Not a great experience for those with multiple workspaces.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated Implementation for fetcing repos across in parallel rather than sequetial


const params = new URLSearchParams();
states.forEach(s => params.append('state', s));
params.append('pagelen', pageLen.toString());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are there any limits for this API, will it take a umber greater than 50? My quick looks says that's the limit so we might want to add Math.min(limit, 50).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah! applied the same Math.min(limit, DEFAULT_LIMIT) cap
to fetchPullRequestListForRepo() to match what's already done in
fetchRepoPullRequests(). This ensures we never exceed the Bitbucket
Cloud API's 50-item limit for pagelen 👍🏻

@Shubhammete
Shubhammete force-pushed the bitbucket-pull-requests-backup branch from cc34f47 to 7b7538d Compare August 27, 2026 18:49
@awanlin

awanlin commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Hi @Shubhammete, I see some changes made but not all items have been addressed so I haven't done another review. Let me know when all the comments have been addressed so I can review again, please. 👍

@Shubhammete

Copy link
Copy Markdown
Contributor Author

Hi @awanlin, all comments have been addressed and ready for another review. Thanks! 👍

@vinzscam vinzscam left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this looks good to me!

* Required when `bitbucket.type: 'cloud'` and the homepage or API needs to filter cloud PRs by workspace
* @visibility frontend
*/
cloudWorkspaces?: string[];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Small suggestion we could remove cloud to make this less verbose

Suggested change
cloudWorkspaces?: string[];
workspaces?: string[];

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated, thanks!

# For Bitbucket Server / Data Center:
bitbucket.com/project-slug: <example-bitbucket-project-name>/<example-bitbucket-repo-name>
# For Bitbucket Cloud:
bitbucket.org/repo-slug: <my-workspace>/<my-repo>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

hey sorry one question: any specific reason why we are introducing another annotation instead of keeping a single annotation for both bb server and cloud as the format looks the same?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

just to keep things clear for both envs and make future changes easier if needed

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Asking because the format is the same and the existing one is used as a fallback, so literally there is no difference in using one over the other. I think we can avoid adding another annotation for now

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Okay sure I will make them one as they are structurally the same

Comment on lines +351 to +353
throw new Error(
`Failed to fetch repositories for workspace '${workspace}'`,
);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
throw new Error(
`Failed to fetch repositories for workspace '${workspace}'`,
);
throw await ResponseError.fromResponse(response);

Comment on lines +392 to +394
throw new Error(
`Failed to fetch pull requests from Bitbucket Cloud repo '${workspace}/${repo}'`,
);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same below otherwise we'll loose all the context

Suggested change
throw new Error(
`Failed to fetch pull requests from Bitbucket Cloud repo '${workspace}/${repo}'`,
);
throw await ResponseError.fromResponse(response);

@Shubhammete

Copy link
Copy Markdown
Contributor Author

Hi @vinzscam,
thanks for the review!

I have updated the error handling by introducing a helper function and unified the annotations across both implementations as suggested

Let me know if anything else needs to be changed!

@vinzscam vinzscam left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice work @Shubhammete 👏

…ests/src/utils/isBitbucketSlugSet.ts

Signed-off-by: Vincenzo Scamporlino <[email protected]>
@awanlin
awanlin merged commit d7c6fb5 into backstage:main Oct 2, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🚀 Bitbucket-Pull-Requests: Add Bitbucket Cloud support

4 participants