Merge pull request #1936 from Stijnus/feature/github-deployment-cleanup
feat: github deployment cleanup
This commit is contained in:
@@ -129,7 +129,9 @@ export const DeployButton = ({ onVercelDeploy, onNetlifyDeploy, onGitHubDeploy }
|
||||
crossOrigin="anonymous"
|
||||
src="https://cdn.simpleicons.org/netlify"
|
||||
/>
|
||||
<span className="mx-auto">{!netlifyConn.user ? 'No Netlify Account Connected' : 'Deploy to Netlify'}</span>
|
||||
<span className="mx-auto">
|
||||
{!netlifyConn.user ? 'No Netlify Account Connected' : 'Deploy to Netlify'}
|
||||
</span>
|
||||
{netlifyConn.user && <NetlifyDeploymentLink />}
|
||||
</DropdownMenu.Item>
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ export function useGitHubDeploy() {
|
||||
|
||||
// Notify that build succeeded and deployment preparation is starting
|
||||
deployArtifact.runner.handleDeployAction('deploying', 'running', {
|
||||
source: 'github'
|
||||
source: 'github',
|
||||
});
|
||||
|
||||
// Get all project files instead of just the build directory since we're deploying to a repository
|
||||
@@ -89,31 +89,32 @@ export function useGitHubDeploy() {
|
||||
|
||||
for (const entry of entries) {
|
||||
const fullPath = path.join(dirPath, entry.name);
|
||||
|
||||
// Create a relative path without the leading slash for GitHub
|
||||
const relativePath = basePath ? `${basePath}/${entry.name}` : entry.name;
|
||||
|
||||
// Skip node_modules, .git directories and other common excludes
|
||||
if (entry.isDirectory() && (
|
||||
entry.name === 'node_modules' ||
|
||||
if (
|
||||
entry.isDirectory() &&
|
||||
(entry.name === 'node_modules' ||
|
||||
entry.name === '.git' ||
|
||||
entry.name === 'dist' ||
|
||||
entry.name === 'build' ||
|
||||
entry.name === '.cache' ||
|
||||
entry.name === '.next'
|
||||
)) {
|
||||
entry.name === '.next')
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (entry.isFile()) {
|
||||
// Skip binary files, large files and other common excludes
|
||||
if (entry.name.endsWith('.DS_Store') ||
|
||||
entry.name.endsWith('.log') ||
|
||||
entry.name.startsWith('.env')) {
|
||||
if (entry.name.endsWith('.DS_Store') || entry.name.endsWith('.log') || entry.name.startsWith('.env')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
const content = await container.fs.readFile(fullPath, 'utf-8');
|
||||
|
||||
// Store the file with its relative path, not the full system path
|
||||
files[relativePath] = content;
|
||||
} catch (error) {
|
||||
@@ -131,23 +132,28 @@ export function useGitHubDeploy() {
|
||||
|
||||
const fileContents = await getAllFiles('/');
|
||||
|
||||
// Show GitHub deployment dialog here - it will handle the actual deployment
|
||||
// and will receive these files to deploy
|
||||
/*
|
||||
* Show GitHub deployment dialog here - it will handle the actual deployment
|
||||
* and will receive these files to deploy
|
||||
*/
|
||||
|
||||
// For now, we'll just complete the deployment with a success message
|
||||
// Notify that deployment preparation is complete
|
||||
/*
|
||||
* For now, we'll just complete the deployment with a success message
|
||||
* Notify that deployment preparation is complete
|
||||
*/
|
||||
deployArtifact.runner.handleDeployAction('deploying', 'complete', {
|
||||
source: 'github'
|
||||
source: 'github',
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
files: fileContents,
|
||||
projectName: artifact.title || 'bolt-project'
|
||||
projectName: artifact.title || 'bolt-project',
|
||||
};
|
||||
} catch (err) {
|
||||
console.error('GitHub deploy error:', err);
|
||||
toast.error(err instanceof Error ? err.message : 'GitHub deployment preparation failed');
|
||||
|
||||
return false;
|
||||
} finally {
|
||||
setIsDeploying(false);
|
||||
|
||||
@@ -80,6 +80,7 @@ export function GitHubDeploymentDialog({ isOpen, onClose, projectName, files }:
|
||||
if (!token) {
|
||||
logStore.logError('No GitHub token available');
|
||||
toast.error('GitHub authentication required');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -105,7 +106,7 @@ export function GitHubDeploymentDialog({ isOpen, onClose, projectName, files }:
|
||||
|
||||
try {
|
||||
errorData = await response.json();
|
||||
} catch (e) {
|
||||
} catch {
|
||||
errorData = { message: 'Could not parse error response' };
|
||||
}
|
||||
|
||||
@@ -149,6 +150,7 @@ export function GitHubDeploymentDialog({ isOpen, onClose, projectName, files }:
|
||||
logStore.logError('Failed to parse GitHub repositories response', { parseError });
|
||||
toast.error('Failed to parse repository data');
|
||||
setRecentRepos([]);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -218,10 +220,9 @@ export function GitHubDeploymentDialog({ isOpen, onClose, projectName, files }:
|
||||
await octokit.repos.update({
|
||||
owner: connection.user.login,
|
||||
repo: repoName,
|
||||
private: isPrivate
|
||||
private: isPrivate,
|
||||
});
|
||||
}
|
||||
|
||||
} catch (error: any) {
|
||||
// 404 means repo doesn't exist, which is what we want for new repos
|
||||
if (error.status !== 404) {
|
||||
@@ -234,10 +235,12 @@ export function GitHubDeploymentDialog({ isOpen, onClose, projectName, files }:
|
||||
const { data: newRepo } = await octokit.repos.createForAuthenticatedUser({
|
||||
name: repoName,
|
||||
private: isPrivate,
|
||||
|
||||
// Initialize with a README to avoid empty repository issues
|
||||
auto_init: true,
|
||||
|
||||
// Create a .gitignore file for the project
|
||||
gitignore_template: "Node",
|
||||
gitignore_template: 'Node',
|
||||
});
|
||||
|
||||
// Set the URL for success dialog
|
||||
@@ -247,7 +250,7 @@ export function GitHubDeploymentDialog({ isOpen, onClose, projectName, files }:
|
||||
console.log('Created new repository with auto_init, waiting for GitHub to initialize it...');
|
||||
|
||||
// Wait a moment for GitHub to set up the initial commit
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
await new Promise((resolve) => setTimeout(resolve, 2000));
|
||||
} else {
|
||||
// Set URL for existing repo
|
||||
setCreatedRepoUrl(`https://github.com/${connection.user.login}/${repoName}`);
|
||||
@@ -267,8 +270,10 @@ export function GitHubDeploymentDialog({ isOpen, onClose, projectName, files }:
|
||||
|
||||
setPushedFiles(fileList);
|
||||
|
||||
// Now we need to handle the repository, whether it's new or existing
|
||||
// Get the default branch for the repository
|
||||
/*
|
||||
* Now we need to handle the repository, whether it's new or existing
|
||||
* Get the default branch for the repository
|
||||
*/
|
||||
let defaultBranch: string;
|
||||
let baseSha: string | null = null;
|
||||
|
||||
@@ -353,6 +358,7 @@ export function GitHubDeploymentDialog({ isOpen, onClose, projectName, files }:
|
||||
|
||||
// Create a commit with the tree
|
||||
console.log('Creating commit');
|
||||
|
||||
const { data: commitData } = await octokit.git.createCommit({
|
||||
owner: connection.user.login,
|
||||
repo: repoName,
|
||||
@@ -388,22 +394,33 @@ export function GitHubDeploymentDialog({ isOpen, onClose, projectName, files }:
|
||||
console.log('Reference created successfully');
|
||||
} catch (createRefError) {
|
||||
console.error('Error creating reference:', createRefError);
|
||||
const errorMsg = typeof createRefError === 'object' && createRefError !== null && 'message' in createRefError ? String(createRefError.message) : 'Unknown error';
|
||||
|
||||
const errorMsg =
|
||||
typeof createRefError === 'object' && createRefError !== null && 'message' in createRefError
|
||||
? String(createRefError.message)
|
||||
: 'Unknown error';
|
||||
throw new Error(`Failed to create Git reference: ${errorMsg}`);
|
||||
}
|
||||
}
|
||||
} catch (gitError) {
|
||||
console.error('Error with git operations:', gitError);
|
||||
const gitErrorMsg = typeof gitError === 'object' && gitError !== null && 'message' in gitError ? String(gitError.message) : 'Unknown error';
|
||||
|
||||
const gitErrorMsg =
|
||||
typeof gitError === 'object' && gitError !== null && 'message' in gitError
|
||||
? String(gitError.message)
|
||||
: 'Unknown error';
|
||||
throw new Error(`Failed during git operations: ${gitErrorMsg}`);
|
||||
}
|
||||
|
||||
// Save the repository information for this chat
|
||||
localStorage.setItem(`github-repo-${currentChatId}`, JSON.stringify({
|
||||
localStorage.setItem(
|
||||
`github-repo-${currentChatId}`,
|
||||
JSON.stringify({
|
||||
owner: connection.user.login,
|
||||
name: repoName,
|
||||
url: `https://github.com/${connection.user.login}/${repoName}`,
|
||||
}));
|
||||
}),
|
||||
);
|
||||
|
||||
// Show success dialog
|
||||
setShowSuccessDialog(true);
|
||||
@@ -446,6 +463,7 @@ export function GitHubDeploymentDialog({ isOpen, onClose, projectName, files }:
|
||||
|
||||
// Refresh user data after auth
|
||||
const connection = getLocalStorage('github_connection');
|
||||
|
||||
if (connection?.user && connection?.token) {
|
||||
setUser(connection.user);
|
||||
fetchRecentRepos(connection.token);
|
||||
|
||||
@@ -22,7 +22,7 @@ import { renderLogger } from '~/utils/logger';
|
||||
import { EditorPanel } from './EditorPanel';
|
||||
import { Preview } from './Preview';
|
||||
import useViewport from '~/lib/hooks';
|
||||
import { PushToGitHubDialog } from '~/components/@settings/tabs/connections/components/PushToGitHubDialog';
|
||||
|
||||
import * as DropdownMenu from '@radix-ui/react-dropdown-menu';
|
||||
import { usePreviewStore } from '~/lib/stores/previews';
|
||||
import { chatStore } from '~/lib/stores/chat';
|
||||
@@ -279,11 +279,17 @@ const FileModifiedDropdown = memo(
|
||||
);
|
||||
|
||||
export const Workbench = memo(
|
||||
({ chatStarted, isStreaming, metadata, updateChatMestaData, setSelectedElement }: WorkspaceProps) => {
|
||||
({
|
||||
chatStarted,
|
||||
isStreaming,
|
||||
metadata: _metadata,
|
||||
updateChatMestaData: _updateChatMestaData,
|
||||
setSelectedElement,
|
||||
}: WorkspaceProps) => {
|
||||
renderLogger.trace('Workbench');
|
||||
|
||||
const [isSyncing, setIsSyncing] = useState(false);
|
||||
const [isPushDialogOpen, setIsPushDialogOpen] = useState(false);
|
||||
|
||||
const [fileHistory, setFileHistory] = useState<Record<string, FileHistory>>({});
|
||||
|
||||
// const modifiedFiles = Array.from(useStore(workbenchStore.unsavedFiles).keys());
|
||||
@@ -436,17 +442,6 @@ export const Workbench = memo(
|
||||
<span>{isSyncing ? 'Syncing...' : 'Sync Files'}</span>
|
||||
</div>
|
||||
</DropdownMenu.Item>
|
||||
<DropdownMenu.Item
|
||||
className={classNames(
|
||||
'cursor-pointer flex items-center w-full px-4 py-2 text-sm text-bolt-elements-textPrimary hover:bg-bolt-elements-item-backgroundActive gap-2 rounded-md group relative',
|
||||
)}
|
||||
onClick={() => setIsPushDialogOpen(true)}
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="i-ph:git-branch" />
|
||||
Push to GitHub
|
||||
</div>
|
||||
</DropdownMenu.Item>
|
||||
</DropdownMenu.Content>
|
||||
</DropdownMenu.Root>
|
||||
</div>
|
||||
@@ -493,31 +488,6 @@ export const Workbench = memo(
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<PushToGitHubDialog
|
||||
isOpen={isPushDialogOpen}
|
||||
onClose={() => setIsPushDialogOpen(false)}
|
||||
onPush={async (repoName, username, token, isPrivate) => {
|
||||
try {
|
||||
console.log('Dialog onPush called with isPrivate =', isPrivate);
|
||||
|
||||
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({
|
||||
...(metadata || {}),
|
||||
gitUrl: repoUrl,
|
||||
});
|
||||
}
|
||||
|
||||
return repoUrl;
|
||||
} catch (error) {
|
||||
console.error('Error pushing to GitHub:', error);
|
||||
toast.error('Failed to push to GitHub');
|
||||
throw error;
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</motion.div>
|
||||
)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user