fix pr source repo selection(#156)#1630
Open
jeremyfiel wants to merge 1 commit intoatlassian:mainfrom
Open
Conversation
ee661f2 to
3626cfa
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Is This Change?
Pull Request Source Repository Selection Bug Fix - Implementation Summary
Overview
Fixed a critical bug in the PR creation UI where selecting a different remote repository in the dropdown did not update the actual source repository used in the API call. This blocked users from creating pull requests from forked repositories to upstream repositories.
Problem Statement
Root Cause
In CreatePullRequestPage.tsx:151, the submit handler always passed
mainSiteRemoteregardless of the user's selection in the remote dropdown.Bug Flow
sourceRemoteNamestate updates ✓mainSiteRemote(e.g., "upstream") ✗sourceSitewith incorrectownerSlug/repoSlugfromRef.repository(pullRequests.ts:798-806)source.repository.full_name(pullRequests.ts:695-701)Impact
This bug completely blocked the forking workflow where users need to:
origin) to the upstream repositoryImplementation Details
1. Added Computed
sourceSiteRemoteValueFile: src/react/atlascode/pullrequest/CreatePullRequestPage.tsx
Location: After line 99 (after state declarations)
Code Added:
Rationale:
useMemoto reactively compute the correctSiteRemotebased onsourceRemoteNamesiteRemotesarraymainSiteRemotefor single-remote repos or if remote not found2. Added Filtered Source Branches
File: src/react/atlascode/pullrequest/CreatePullRequestPage.tsx
Location: After the
sourceSiteRemoteuseMemoCode Added:
Rationale:
upstream.remote)3. Updated Submit Handler
File: src/react/atlascode/pullrequest/CreatePullRequestPage.tsx
Location: Line 183 in
handleSubmitChange:
4. Updated Source Branch Autocomplete
File: src/react/atlascode/pullrequest/CreatePullRequestPage.tsx
Location: Line 348 in the Source branch Autocomplete component
Change:
5. Updated handleSubmit Dependency Array
File: src/react/atlascode/pullrequest/CreatePullRequestPage.tsx
Location: Line 202 (dependency array)
Change: Added
sourceSiteRemoteto the dependency array6. Added Comprehensive Tests
File: src/webview/pullrequest/vscCreatePullRequestActionImpl.test.ts
Tests Added:
Test 1: Bitbucket Cloud Fork Scenario
Test 2: Bitbucket Server Fork Scenario
How the Fix Works
Before (Broken)
After (Fixed)
Platform Support
The fix supports both Bitbucket Cloud and Bitbucket Server:
Bitbucket Cloud
source.repository.full_name(format:ownerSlug/repoSlug)/2.0/repositories/{workspace}/{repo_slug}/pullrequestsforkowner/forkrepoBitbucket Server
fromRef.repository.project.keyandslug(format:PROJECT/repo)/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requestsFORKPROJECTand slug:forkrepoTesting Scenarios
Test 1: Single Remote Repository
originremote configuredmainSiteRemoteTest 2: Fork Workflow (Multi-Remote) - Bitbucket Cloud
origin(fork) andupstream(parent) remotes configuredorigin's owner/repo insource.repositoryforkowner/forkreposent to APITest 3: Fork Workflow (Multi-Remote) - Bitbucket Server
origin(fork) andupstream(parent) remotes configuredorigin's project/repo infromRef.repositoryFORKPROJECT/forkreposent to APITest 4: Remote Selection Change
sourceSiteRemoteupdates reactively viauseMemoTest 5: Branch Filtering
Design Decisions
✅ Use Computed Value (useMemo)
✅ Filter Source Branches by Selected Remote
upstream.remote)❌ Alternatives Rejected
Store
sourceSiteRemoteas state:sourceRemoteNameLookup in submit handler:
Change API to accept string instead of object:
Fetch fresh branches from Git on remote change:
Risk Assessment
Low Risk
No Breaking Changes
mainSiteRemote)sourceSiteRemote, already correctFiles Modified
Primary Changes
src/react/atlascode/pullrequest/CreatePullRequestPage.tsx- Main bug fix (5 changes)Testing
src/webview/pullrequest/vscCreatePullRequestActionImpl.test.ts- Added 2 test casesVerification (No Changes Needed)
src/bitbucket/bitbucket-server/pullRequests.ts- UsessourceSiteinfromRefsrc/bitbucket/bitbucket-cloud/pullRequests.ts- UsessourceSiteinsource.repositorysrc/webview/pullrequest/vscCreatePullRequestActionImpl.ts- PassessourceSiteto clientssrc/lib/ipc/fromUI/createPullRequest.ts-SubmitCreateRequestActioninterfacesrc/bitbucket/model.ts-CreatePullRequestDatainterfaceConfiguration: preferredRemotes Setting
Users can configure which remote is selected as the "main" remote using the
preferredRemotessetting:{ "atlascode.bitbucket.preferredRemotes": ["upstream", "origin"] }How it works:
mainSiteRemoteused for default operations["upstream", "origin"]- Prefers upstream (common for fork contributors)["origin", "upstream"]- Prefers origin (common for direct repo access)This setting determines which remote is selected by default when the PR creation page opens, but users can still manually select any remote from the dropdown.
Contribution Guidelines Compliance
Following CONTRIBUTING.md:
useMemopattern (already used in codebase), consistent TypeScript typesSummary
This fix enables the full forking workflow in the PR creation UI by ensuring that:
The bug is now fixed, and users can successfully create pull requests from forked repositories to upstream repositories by selecting the appropriate remote in the UI dropdown.
Rovo Dev code review: Rovo Dev couldn't review this pull request
Upgrade to Rovo Dev Standard to continue using code review.