@ -1,7 +1,7 @@
import React from 'react'
import { bufferToHex , keccakFromString } from 'ethereumjs-util'
import axios , { AxiosResponse } from 'axios'
import { addInputFieldSuccess , cloneRepositoryFailed , cloneRepositoryRequest , cloneRepositorySuccess , createWorkspaceError , createWorkspaceRequest , createWorkspaceSuccess , displayNotification , displayPopUp , fetchWorkspaceDirectoryError , fetchWorkspaceDirectoryRequest , fetchWorkspaceDirectorySuccess , hideNotification , setCurrentWorkspace , setCurrentWorkspaceBranches , setCurrentWorkspaceCurrentBranch , setDeleteWorkspace , setMode , setReadOnlyMode , setRenameWorkspace , setCurrentWorkspaceIsGitRepo } from './payload'
import { addInputFieldSuccess , cloneRepositoryFailed , cloneRepositoryRequest , cloneRepositorySuccess , createWorkspaceError , createWorkspaceRequest , createWorkspaceSuccess , displayNotification , displayPopUp , fetchWorkspaceDirectoryError , fetchWorkspaceDirectoryRequest , fetchWorkspaceDirectorySuccess , hideNotification , setCurrentWorkspace , setCurrentWorkspaceBranches , setCurrentWorkspaceCurrentBranch , setDeleteWorkspace , setMode , setReadOnlyMode , setRenameWorkspace , setCurrentWorkspaceIsGitRepo , setGitConfig } from './payload'
import { addSlash , checkSlash , checkSpecialChars } from '@remix-ui/helper'
import { JSONStandardInput , WorkspaceTemplate } from '../types'
@ -41,6 +41,13 @@ export const setPlugin = (filePanelPlugin, reducerDispatch) => {
plugin . on ( 'dGitProvider' , 'branch' , async ( ) = > {
await checkGit ( )
} )
plugin . on ( 'config' , 'configChanged' , async ( ) = > {
await getGitConfig ( )
} )
plugin . on ( 'settings' , 'configChanged' , async ( ) = > {
await getGitConfig ( )
} )
getGitConfig ( )
}
export const addInputField = async ( type : 'file' | 'folder' , path : string , cb ? : ( err : Error , result? : string | number | boolean | Record < string , any > ) = > void ) = > {
@ -80,12 +87,7 @@ export const createWorkspace = async (workspaceName: string, workspaceTemplateNa
await plugin . workspaceCreated ( workspaceName )
if ( isGitRepo ) {
const workspacesPath = plugin . fileProviders . workspace . workspacesPath
const allBranches = await getGitRepoBranches ( workspacesPath + '/' + workspaceName )
// selected branch will be 'master' or 'main'
const selectedBranch = allBranches ? . length ? allBranches [ 0 ] . name : 'main'
await plugin . call ( 'dGitProvider' , 'init' , { branch : selectedBranch } )
dispatch ( setCurrentWorkspaceCurrentBranch ( selectedBranch ) )
await checkGit ( )
const isActive = await plugin . call ( 'manager' , 'isActive' , 'dgit' )
if ( ! isActive ) await plugin . call ( 'manager' , 'activatePlugin' , 'dgit' )
@ -95,9 +97,8 @@ export const createWorkspace = async (workspaceName: string, workspaceTemplateNa
if ( isGitRepo ) {
const name = await plugin . call ( 'settings' , 'get' , 'settings/github-user-name' )
const email = await plugin . call ( 'settings' , 'get' , 'settings/github-email' )
const token = await plugin . call ( 'settings' , 'get' , 'settings/gist-access-token' )
if ( ! name || ! email || ! token ) {
if ( ! name || ! email ) {
await plugin . call ( 'notification' , 'toast' , 'Please provide GitHub details in the settings section to start committing and branching.' )
} else {
// commit the template as first commit
@ -518,12 +519,20 @@ export const getGitRepoCurrentBranch = async (workspaceName: string) => {
export const showAllBranches = async ( ) = > {
const isActive = await plugin . call ( 'manager' , 'isActive' , 'dgit' )
if ( ! isActive ) await plugin . call ( 'manager' , 'activatePlugin' , 'dgit' )
plugin . call ( 'menuicons' , 'select' , 'dgit' )
plugin . call ( 'dgit' , 'open' , 'branches' )
}
export const getGitConfig = async ( ) = > {
const username = await plugin . call ( 'settings' , 'get' , 'settings/github-user-name' )
const email = await plugin . call ( 'settings' , 'get' , 'settings/github-email' )
const token = await plugin . call ( 'settings' , 'get' , 'settings/gist-access-token' )
const config = { username , email , token }
dispatch ( setGitConfig ( config ) )
return config
}
const refreshBranches = async ( ) = > {
const workspacesPath = plugin . fileProviders . workspace . workspacesPath
const workspaceName = plugin . fileProviders . workspace . workspace