feat: fix for push private repo (#1618)
Some checks failed
Docker Publish / docker-build-publish (push) Has been cancelled
Update Stable Branch / prepare-release (push) Has been cancelled
Mark Stale Issues and Pull Requests / stale (push) Has been cancelled

* feat: push private repo

# GitHub Integration Changelog

## Fixed
- Fixed issue where repositories marked as private weren't being created with private visibility
- Added support for changing repository visibility (public/private) when pushing to existing repositories
- Fixed 404 errors when pushing files after changing repository visibility

## Added
- Added clear user warnings when changing repository visibility from public to private or vice versa
- Implemented delays after visibility changes to allow GitHub API to fully process the change
- Added retry mechanism (up to 3 attempts with increasing delays) for pushing files after visibility changes
- Added repository data refresh before pushing to ensure latest reference data

## Improved
- Enhanced error logging and handling for all GitHub API operations
- Updated return value handling to use actual repository URLs from the API response
- Added comprehensive logging to track repository creation and update operations

* cleanup

* Update Workbench.client.tsx
This commit is contained in:
Stijnus
2025-04-08 22:20:54 +02:00
committed by GitHub
parent 552f08acea
commit 0202aefad9
8 changed files with 484 additions and 79 deletions

View File

@@ -136,15 +136,24 @@ export function PushToGitHubDialog({ isOpen, onClose, onPush }: PushToGitHubDial
const octokit = new Octokit({ auth: connection.token });
try {
await octokit.repos.get({
const { data: existingRepo } = await octokit.repos.get({
owner: connection.user.login,
repo: repoName,
});
// If we get here, the repo exists
const confirmOverwrite = window.confirm(
`Repository "${repoName}" already exists. Do you want to update it? This will add or modify files in the repository.`,
);
let confirmMessage = `Repository "${repoName}" already exists. Do you want to update it? This will add or modify files in the repository.`;
// Add visibility change warning if needed
if (existingRepo.private !== isPrivate) {
const visibilityChange = isPrivate
? 'This will also change the repository from public to private.'
: 'This will also change the repository from private to public.';
confirmMessage += `\n\n${visibilityChange}`;
}
const confirmOverwrite = window.confirm(confirmMessage);
if (!confirmOverwrite) {
setIsLoading(false);

View File

@@ -1,6 +1,18 @@
import { useCallback } from 'react';
import { toast as toastify } from 'react-toastify';
// Configure standard toast settings
export const configuredToast = {
success: (message: string, options = {}) => toastify.success(message, { autoClose: 3000, ...options }),
error: (message: string, options = {}) => toastify.error(message, { autoClose: 3000, ...options }),
info: (message: string, options = {}) => toastify.info(message, { autoClose: 3000, ...options }),
warning: (message: string, options = {}) => toastify.warning(message, { autoClose: 3000, ...options }),
loading: (message: string, options = {}) => toastify.loading(message, { autoClose: 3000, ...options }),
};
// Export the original toast for cases where specific configuration is needed
export { toastify as toast };
interface ToastOptions {
type?: 'success' | 'error' | 'info' | 'warning';
duration?: number;
@@ -36,5 +48,19 @@ export function useToast() {
[toast],
);
return { toast, success, error };
const info = useCallback(
(message: string, options: Omit<ToastOptions, 'type'> = {}) => {
toast(message, { ...options, type: 'info' });
},
[toast],
);
const warning = useCallback(
(message: string, options: Omit<ToastOptions, 'type'> = {}) => {
toast(message, { ...options, type: 'warning' });
},
[toast],
);
return { toast, success, error, info, warning };
}

View File

@@ -388,11 +388,9 @@ export const Workbench = memo(
Toggle Terminal
</PanelHeaderButton>
<DropdownMenu.Root>
<DropdownMenu.Trigger className="bg-transparent">
<button className="text-sm flex items-center gap-1 text-bolt-elements-item-contentDefault bg-transparent enabled:hover:text-bolt-elements-item-contentActive rounded-md p-1 enabled:hover:bg-bolt-elements-item-backgroundActive disabled:cursor-not-allowed">
<div className="i-ph:box-arrow-up" />
Sync & Export
</button>
<DropdownMenu.Trigger className="text-sm flex items-center gap-1 text-bolt-elements-item-contentDefault bg-transparent enabled:hover:text-bolt-elements-item-contentActive rounded-md p-1 enabled:hover:bg-bolt-elements-item-backgroundActive disabled:cursor-not-allowed">
<div className="i-ph:box-arrow-up" />
Sync & Export
</DropdownMenu.Trigger>
<DropdownMenu.Content
className={classNames(
@@ -491,12 +489,12 @@ export const Workbench = memo(
<PushToGitHubDialog
isOpen={isPushDialogOpen}
onClose={() => setIsPushDialogOpen(false)}
onPush={async (repoName, username, token) => {
onPush={async (repoName, username, token, isPrivate) => {
try {
const commitMessage = prompt('Please enter a commit message:', 'Initial commit') || 'Initial commit';
await workbenchStore.pushToGitHub(repoName, commitMessage, username, token);
console.log('Dialog onPush called with isPrivate =', isPrivate);
const repoUrl = `https://github.com/${username}/${repoName}`;
const commitMessage = prompt('Please enter a commit message:', 'Initial commit') || 'Initial commit';
const repoUrl = await workbenchStore.pushToGitHub(repoName, commitMessage, username, token, isPrivate);
if (updateChatMestaData && !metadata?.gitUrl) {
updateChatMestaData({