mirror of
https://github.com/Sea-Haven-Industries/open-swe.git
synced 2026-09-30 10:23:14 +00:00
fix: Reset branch query param when switching repositories (#519)
* Apply patch * Apply patch * Apply patch * Apply patch * Apply patch * fix: clear branch when switching repos to set correct default branch * fix branch selector logic --------- Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com> Co-authored-by: Dylan Boudro <121908331+starmorph@users.noreply.github.com> Co-authored-by: starmorph <dylan@starmorph.com> Co-authored-by: Brace Sproul <braceasproul@gmail.com>
This commit is contained in:
parent
bd9e1969b3
commit
576d2553e3
3 changed files with 15 additions and 23 deletions
|
|
@ -90,7 +90,7 @@ export function BranchSelector({
|
|||
}
|
||||
setSelectedBranch(findDefaultBranch(branches, defaultBranch));
|
||||
});
|
||||
} else if (!selectedBranch || !currentBranchExists) {
|
||||
} else if (!selectedBranch) {
|
||||
setSelectedBranch(findDefaultBranch(branches, defaultBranch));
|
||||
}
|
||||
}
|
||||
|
|
@ -99,7 +99,6 @@ export function BranchSelector({
|
|||
selectedRepository?.repo,
|
||||
branchesLoading,
|
||||
branchesError,
|
||||
branches.length,
|
||||
selectedBranch,
|
||||
setSelectedBranch,
|
||||
defaultBranch,
|
||||
|
|
|
|||
|
|
@ -164,9 +164,9 @@ export function useGitHubApp(): UseGitHubAppReturn {
|
|||
|
||||
useEffect(() => {
|
||||
if (selectedRepository && !branchesLoading) {
|
||||
fetchBranches();
|
||||
// Reset branch pagination when repository changes
|
||||
setBranches([]);
|
||||
setBranchesPage(1);
|
||||
fetchBranches();
|
||||
} else if (!selectedRepository) {
|
||||
setBranches([]);
|
||||
setSelectedBranchParam(null);
|
||||
|
|
@ -181,12 +181,10 @@ export function useGitHubApp(): UseGitHubAppReturn {
|
|||
// Persist to localStorage whenever repository is selected
|
||||
saveRepositoryToLocalStorage(repo);
|
||||
|
||||
if (!repo) {
|
||||
setSelectedBranchParam(null);
|
||||
setBranches([]);
|
||||
setBranchesPage(1);
|
||||
setBranchesHasMore(false);
|
||||
}
|
||||
setSelectedBranchParam(null);
|
||||
setBranches([]);
|
||||
setBranchesPage(1);
|
||||
setBranchesHasMore(false);
|
||||
},
|
||||
[setSelectedRepositoryParam, setSelectedBranchParam],
|
||||
);
|
||||
|
|
@ -314,7 +312,6 @@ export function useGitHubApp(): UseGitHubAppReturn {
|
|||
);
|
||||
|
||||
if (branch) {
|
||||
// Add the found branch to the existing branches list if it's not already there
|
||||
setBranches((prev) => {
|
||||
const exists = prev.some((b) => b.name === branch.name);
|
||||
if (!exists) {
|
||||
|
|
@ -354,15 +351,12 @@ export function useGitHubApp(): UseGitHubAppReturn {
|
|||
hasCheckedLocalStorageRef.current = false;
|
||||
}
|
||||
|
||||
// Update the previous installation ID reference
|
||||
previousInstallationIdRef.current = currentInstallationId;
|
||||
|
||||
// Fetch repositories for the current installation
|
||||
checkInstallation();
|
||||
}
|
||||
}, [currentInstallationId]);
|
||||
|
||||
// Check localStorage for previously selected repository
|
||||
useEffect(() => {
|
||||
if (
|
||||
!hasCheckedLocalStorageRef.current &&
|
||||
|
|
@ -432,13 +426,13 @@ export function useGitHubApp(): UseGitHubAppReturn {
|
|||
// Auto-select first repository on initial page load
|
||||
useEffect(() => {
|
||||
if (
|
||||
!hasAutoSelectedRef.current && // Haven't auto-selected yet
|
||||
!selectedRepository && // No repo currently selected
|
||||
!isLoading && // Not loading repositories
|
||||
!error && // No error occurred
|
||||
isInstalled === true && // GitHub App is installed
|
||||
repositories.length > 0 && // Repositories are available
|
||||
hasCheckedLocalStorageRef.current // Only after localStorage check is complete
|
||||
!hasAutoSelectedRef.current &&
|
||||
!selectedRepository &&
|
||||
!isLoading &&
|
||||
!error &&
|
||||
isInstalled === true &&
|
||||
repositories.length > 0 &&
|
||||
hasCheckedLocalStorageRef.current
|
||||
) {
|
||||
const firstRepo = repositories[0];
|
||||
const targetRepo = {
|
||||
|
|
|
|||
|
|
@ -105,8 +105,7 @@ export async function getRepositoryBranches(
|
|||
const defaultBranchData = branches[defaultBranchIndex];
|
||||
branches.splice(defaultBranchIndex, 1);
|
||||
branches.unshift(defaultBranchData);
|
||||
} else {
|
||||
// Need to fetch default branch
|
||||
} else if (defaultBranchIndex === -1) {
|
||||
const defaultBranchResponse = await fetch(
|
||||
`${getBaseApiUrl()}github/proxy/repos/${owner}/${repo}/branches/${defaultBranch}`,
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue