Repository navigation
feat(bitbucket-pull-requests): add Bitbucket Cloud support - #10278
Conversation
Signed-off-by: Shubhammete <[email protected]>
Changed Packages
|
…et Cloud pagination URLs Signed-off-by: Shubham Mete <[email protected]>
Signed-off-by: Shubham Mete <[email protected]>
Signed-off-by: Shubham Mete <[email protected]>
Signed-off-by: Shubham Mete <[email protected]>
Signed-off-by: Shubham Mete <[email protected]>
Signed-off-by: Shubham Mete <[email protected]>
|
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
left a comment
There was a problem hiding this comment.
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') || |
There was a problem hiding this comment.
This is not in the config.d.ts file and would be great to have documented in the README
There was a problem hiding this comment.
My bad, thanks for highlighting this! I have now added cloudWorkspaces to config.d.ts and included the setup documentation in the README
There was a problem hiding this comment.
Non-blocking: would be great to see tests for this, I know there are none currently which is why this comment is optional.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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];
There was a problem hiding this comment.
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.
| const [status, setStatus] = useState('ALL'); | ||
|
|
||
| const handleStatusChange = (newStatus: PullRequestState) => { | ||
| const handleStatusChange = (newStatus: any) => { |
There was a problem hiding this comment.
Really want to avoid using any
There was a problem hiding this comment.
Added type for Status fliter
| const response = await this.fetchApi.fetch(`${url}?${params}`, { | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| function mapServerPullRequests(data: any): PullRequest[] { |
There was a problem hiding this comment.
These mappser only look to be used by tests, should they be elsewhere?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
We should probably do Promise.all here as this workspace-level enumeration is sequential. Not a great experience for those with multiple workspaces.
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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 👍🏻
…or same Signed-off-by: Shubhammete <[email protected]>
cc34f47 to
7b7538d
Compare
|
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. 👍 |
Signed-off-by: Shubhammete <[email protected]>
Signed-off-by: Shubhammete <[email protected]>
Signed-off-by: Shubhammete <[email protected]>
Signed-off-by: Shubhammete <[email protected]>
Signed-off-by: Shubhammete <[email protected]>
|
Hi @awanlin, all comments have been addressed and ready for another review. Thanks! 👍 |
| * Required when `bitbucket.type: 'cloud'` and the homepage or API needs to filter cloud PRs by workspace | ||
| * @visibility frontend | ||
| */ | ||
| cloudWorkspaces?: string[]; |
There was a problem hiding this comment.
Small suggestion we could remove cloud to make this less verbose
| cloudWorkspaces?: string[]; | |
| workspaces?: string[]; |
There was a problem hiding this comment.
Updated, thanks!
Signed-off-by: Shubhammete <[email protected]>
…st.ts Signed-off-by: Shubhammete <[email protected]>
| # 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> |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
just to keep things clear for both envs and make future changes easier if needed
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Okay sure I will make them one as they are structurally the same
| throw new Error( | ||
| `Failed to fetch repositories for workspace '${workspace}'`, | ||
| ); |
There was a problem hiding this comment.
| throw new Error( | |
| `Failed to fetch repositories for workspace '${workspace}'`, | |
| ); | |
| throw await ResponseError.fromResponse(response); |
| throw new Error( | ||
| `Failed to fetch pull requests from Bitbucket Cloud repo '${workspace}/${repo}'`, | ||
| ); |
There was a problem hiding this comment.
same below otherwise we'll loose all the context
| throw new Error( | |
| `Failed to fetch pull requests from Bitbucket Cloud repo '${workspace}/${repo}'`, | |
| ); | |
| throw await ResponseError.fromResponse(response); |
Signed-off-by: Shubhammete <[email protected]>
Signed-off-by: Shubhammete <[email protected]>
Signed-off-by: Shubhammete <[email protected]>
|
Hi @vinzscam, 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! |
…ests/src/utils/isBitbucketSlugSet.ts Signed-off-by: Vincenzo Scamporlino <[email protected]>
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