|
|
@ -1,7 +1,7 @@ |
|
|
|
import React from 'react' |
|
|
|
import React from 'react' |
|
|
|
import { bufferToHex, keccakFromString } from 'ethereumjs-util' |
|
|
|
import { bufferToHex, keccakFromString } from 'ethereumjs-util' |
|
|
|
import axios, { AxiosResponse } from 'axios' |
|
|
|
import axios, { AxiosResponse } from 'axios' |
|
|
|
import { addInputFieldSuccess, createWorkspaceError, createWorkspaceRequest, createWorkspaceSuccess, displayNotification, displayPopUp, fetchWorkspaceDirectoryError, fetchWorkspaceDirectoryRequest, fetchWorkspaceDirectorySuccess, hideNotification, setCurrentWorkspace, setDeleteWorkspace, setMode, setReadOnlyMode, setRenameWorkspace } from './payload' |
|
|
|
import { addInputFieldSuccess, cloneRepositoryFailed, cloneRepositoryRequest, cloneRepositorySuccess, createWorkspaceError, createWorkspaceRequest, createWorkspaceSuccess, displayNotification, displayPopUp, fetchWorkspaceDirectoryError, fetchWorkspaceDirectoryRequest, fetchWorkspaceDirectorySuccess, hideNotification, setCurrentWorkspace, setDeleteWorkspace, setMode, setReadOnlyMode, setRenameWorkspace } from './payload' |
|
|
|
import { checkSlash, checkSpecialChars, createNonClashingTitle } from '@remix-ui/helper' |
|
|
|
import { checkSlash, checkSpecialChars, createNonClashingTitle } from '@remix-ui/helper' |
|
|
|
|
|
|
|
|
|
|
|
import { JSONStandardInput, WorkspaceTemplate } from '../types' |
|
|
|
import { JSONStandardInput, WorkspaceTemplate } from '../types' |
|
|
@ -42,13 +42,13 @@ export const addInputField = async (type: 'file' | 'folder', path: string, cb?: |
|
|
|
return promise |
|
|
|
return promise |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export const createWorkspace = async (workspaceName: string, workspaceTemplateName: WorkspaceTemplate, isEmpty = false, cb?: (err: Error, result?: string | number | boolean | Record<string, any>) => void) => { |
|
|
|
export const createWorkspace = async (workspaceName: string, workspaceTemplateName: WorkspaceTemplate, isEmpty = false, cb?: (err: Error, result?: string | number | boolean | Record<string, any>) => void, isGitRepo: boolean = false) => { |
|
|
|
await plugin.fileManager.closeAllFiles() |
|
|
|
await plugin.fileManager.closeAllFiles() |
|
|
|
const promise = createWorkspaceTemplate(workspaceName, workspaceTemplateName) |
|
|
|
const promise = createWorkspaceTemplate(workspaceName, workspaceTemplateName) |
|
|
|
|
|
|
|
|
|
|
|
dispatch(createWorkspaceRequest(promise)) |
|
|
|
dispatch(createWorkspaceRequest(promise)) |
|
|
|
promise.then(async () => { |
|
|
|
promise.then(async () => { |
|
|
|
dispatch(createWorkspaceSuccess({ name: workspaceName, isGitRepo: false })) |
|
|
|
dispatch(createWorkspaceSuccess({ name: workspaceName, isGitRepo })) |
|
|
|
await plugin.setWorkspace({ name: workspaceName, isLocalhost: false }) |
|
|
|
await plugin.setWorkspace({ name: workspaceName, isLocalhost: false }) |
|
|
|
await plugin.setWorkspaces(await getWorkspaces()) |
|
|
|
await plugin.setWorkspaces(await getWorkspaces()) |
|
|
|
await plugin.workspaceCreated(workspaceName) |
|
|
|
await plugin.workspaceCreated(workspaceName) |
|
|
@ -334,12 +334,26 @@ export const cloneRepository = async (url: string) => { |
|
|
|
const token = config.get('currentFile') |
|
|
|
const token = config.get('currentFile') |
|
|
|
const repoConfig = { url, token } |
|
|
|
const repoConfig = { url, token } |
|
|
|
const urlArray = url.split('/') |
|
|
|
const urlArray = url.split('/') |
|
|
|
let repoName = urlArray[urlArray.length - 1] |
|
|
|
let repoName = urlArray.length > 0 ? urlArray[urlArray.length - 1] : '' |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
repoName = await createNonClashingTitle(repoName, plugin.fileManager) |
|
|
|
repoName = await createNonClashingTitle(repoName, plugin.fileManager) |
|
|
|
await plugin.call('dGitProvider', 'clone', repoConfig, repoName) |
|
|
|
await createWorkspace(repoName, 'blank', true, null, true) |
|
|
|
await plugin.call('manager', 'activatePlugin', 'dgit') |
|
|
|
const promise = plugin.call('dGitProvider', 'clone', repoConfig, repoName, true) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dispatch(cloneRepositoryRequest()) |
|
|
|
|
|
|
|
promise.then(async () => { |
|
|
|
|
|
|
|
const isActive = await plugin.call('manager', 'isActive', 'dgit') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!isActive) await plugin.call('manager', 'activatePlugin', 'dgit') |
|
|
|
|
|
|
|
await fetchWorkspaceDirectory(repoName) |
|
|
|
|
|
|
|
dispatch(cloneRepositorySuccess()) |
|
|
|
|
|
|
|
}).catch((e) => { |
|
|
|
|
|
|
|
dispatch(displayNotification('Clone Git Repository', 'An error occured: ' + e, 'Ok', null, async () => { |
|
|
|
|
|
|
|
await deleteWorkspace(repoName) |
|
|
|
|
|
|
|
dispatch(cloneRepositoryFailed()) |
|
|
|
|
|
|
|
})) |
|
|
|
|
|
|
|
}) |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
dispatch(displayPopUp('An error occured: ' + e)) |
|
|
|
dispatch(displayPopUp('An error occured: ' + e)) |
|
|
|
} |
|
|
|
} |
|
|
|