fix: improve push to github option (#1111)
* feat: better push to githubbutton * added url update on push to github
This commit is contained in:
@@ -18,6 +18,7 @@ import { EditorPanel } from './EditorPanel';
|
||||
import { Preview } from './Preview';
|
||||
import useViewport from '~/lib/hooks';
|
||||
import Cookies from 'js-cookie';
|
||||
import { chatMetadata, useChatHistory } from '~/lib/persistence';
|
||||
|
||||
interface WorkspaceProps {
|
||||
chatStarted?: boolean;
|
||||
@@ -66,6 +67,8 @@ export const Workbench = memo(({ chatStarted, isStreaming }: WorkspaceProps) =>
|
||||
const unsavedFiles = useStore(workbenchStore.unsavedFiles);
|
||||
const files = useStore(workbenchStore.files);
|
||||
const selectedView = useStore(workbenchStore.currentView);
|
||||
const metadata = useStore(chatMetadata);
|
||||
const { updateChatMestaData } = useChatHistory();
|
||||
|
||||
const isSmallViewport = useViewport(1024);
|
||||
|
||||
@@ -171,18 +174,28 @@ export const Workbench = memo(({ chatStarted, isStreaming }: WorkspaceProps) =>
|
||||
<PanelHeaderButton
|
||||
className="mr-1 text-sm"
|
||||
onClick={() => {
|
||||
const repoName = prompt(
|
||||
'Please enter a name for your new GitHub repository:',
|
||||
'bolt-generated-project',
|
||||
);
|
||||
let repoName = metadata?.gitUrl?.split('/').slice(-1)[0]?.replace('.git', '') || null;
|
||||
let repoConfirmed: boolean = true;
|
||||
|
||||
if (repoName) {
|
||||
repoConfirmed = confirm(`Do you want to push to the repository ${repoName}?`);
|
||||
}
|
||||
|
||||
if (!repoName || !repoConfirmed) {
|
||||
repoName = prompt(
|
||||
'Please enter a name for your new GitHub repository:',
|
||||
'bolt-generated-project',
|
||||
);
|
||||
} else {
|
||||
}
|
||||
|
||||
if (!repoName) {
|
||||
alert('Repository name is required. Push to GitHub cancelled.');
|
||||
return;
|
||||
}
|
||||
|
||||
const githubUsername = Cookies.get('githubUsername');
|
||||
const githubToken = Cookies.get('githubToken');
|
||||
let githubUsername = Cookies.get('githubUsername');
|
||||
let githubToken = Cookies.get('githubToken');
|
||||
|
||||
if (!githubUsername || !githubToken) {
|
||||
const usernameInput = prompt('Please enter your GitHub username:');
|
||||
@@ -193,9 +206,26 @@ export const Workbench = memo(({ chatStarted, isStreaming }: WorkspaceProps) =>
|
||||
return;
|
||||
}
|
||||
|
||||
workbenchStore.pushToGitHub(repoName, usernameInput, tokenInput);
|
||||
} else {
|
||||
workbenchStore.pushToGitHub(repoName, githubUsername, githubToken);
|
||||
githubUsername = usernameInput;
|
||||
githubToken = tokenInput;
|
||||
|
||||
Cookies.set('githubUsername', usernameInput);
|
||||
Cookies.set('githubToken', tokenInput);
|
||||
Cookies.set(
|
||||
'git:github.com',
|
||||
JSON.stringify({ username: tokenInput, password: 'x-oauth-basic' }),
|
||||
);
|
||||
}
|
||||
|
||||
const commitMessage =
|
||||
prompt('Please enter a commit message:', 'Initial commit') || 'Initial commit';
|
||||
workbenchStore.pushToGitHub(repoName, commitMessage, githubUsername, githubToken);
|
||||
|
||||
if (!metadata?.gitUrl) {
|
||||
updateChatMestaData({
|
||||
...(metadata || {}),
|
||||
gitUrl: `https://github.com/${githubUsername}/${repoName}.git`,
|
||||
});
|
||||
}
|
||||
}}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user