refactoring

pull/4791/head
bunsenstraat 7 months ago
parent 12c587ff57
commit c0357ae03e
  1. 2
      apps/remix-ide-e2e/src/tests/plugin_api.ts
  2. 96
      apps/remix-ide/src/app/files/dgitProvider.ts
  3. 2
      apps/remix-ide/src/app/plugins/git.tsx
  4. 2
      apps/remix-ide/src/remixAppManager.js
  5. 2
      apps/remix-ide/src/remixEngine.js
  6. 14
      apps/remixdesktop/src/plugins/isoGitPlugin.ts
  7. 9
      apps/remixdesktop/src/types/index.ts
  8. 7
      apps/vyper/src/app/utils/remix-client.tsx
  9. 22
      libs/remix-ui/git/src/components/buttons/sourcecontrolbuttons.tsx
  10. 41
      libs/remix-ui/git/src/components/panels/commands/pushpull.tsx
  11. 9
      libs/remix-ui/git/src/components/panels/commits.tsx
  12. 8
      libs/remix-ui/git/src/components/panels/sourcecontrol/sourcontrolitembuttons.tsx
  13. 212
      libs/remix-ui/git/src/lib/gitactions.ts
  14. 42
      libs/remix-ui/git/src/lib/listeners.ts
  15. 16
      libs/remix-ui/git/src/state/context.tsx
  16. 4
      libs/remix-ui/git/src/state/gitpayload.ts
  17. 160
      libs/remix-ui/git/src/types/index.ts
  18. 2
      libs/remix-ui/home-tab/src/lib/components/homeTabGetStarted.tsx
  19. 3
      libs/remix-ui/workspace/src/lib/actions/payload.ts
  20. 77
      libs/remix-ui/workspace/src/lib/actions/workspace.ts
  21. 7
      libs/remix-ui/workspace/src/lib/contexts/index.ts
  22. 7
      libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx
  23. 8
      libs/remix-ui/workspace/src/lib/reducers/workspace.ts
  24. 12
      libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx
  25. 19
      libs/remix-ui/workspace/src/lib/types/index.ts

@ -10,7 +10,7 @@ declare global {
const localPluginData: Profile & LocationProfile & ExternalProfile = {
name: 'localPlugin',
displayName: 'Local Plugin',
canActivate: ['dGitProvider', 'flattener', 'solidityUnitTesting', 'udapp', 'hardhat-provider'],
canActivate: ['dgitApi', 'flattener', 'solidityUnitTesting', 'udapp', 'hardhat-provider'],
url: 'http://localhost:9999',
location: 'sidePanel'
}

@ -3,7 +3,7 @@
import {
Plugin
} from '@remixproject/engine'
import git, { ReadCommitResult } from 'isomorphic-git'
import git, { ReadBlobResult, ReadCommitResult, StatusRow } from 'isomorphic-git'
import IpfsHttpClient from 'ipfs-http-client'
import {
saveAs
@ -19,7 +19,7 @@ import { Octokit, App } from "octokit"
import { OctokitResponse } from '@octokit/types'
import { Endpoints } from "@octokit/types"
import { IndexedDBStorage } from './filesystems/indexedDB'
import { GitHubUser, RateLimit, branch, commitChange, remote, pagedCommits } from '@remix-ui/git'
import { GitHubUser, RateLimit, branch, commitChange, remote, pagedCommits, remoteCommitsInputType, cloneInputType, fetchInputType, pullInputType, pushInputType, currentBranchInput, branchInputType, addInput, rmInput, resolveRefInput, readBlobInput, repositoriesInput, commitInput, branchDifference, compareBranchesInput, initInput } from '@remix-ui/git'
import { LibraryProfile, StatusEvents } from '@remixproject/plugin-utils'
import { ITerminal } from '@remixproject/plugin-api/src/lib/terminal'
@ -28,7 +28,7 @@ declare global {
}
const profile: LibraryProfile = {
name: 'dGitProvider',
name: 'dgitApi',
displayName: 'Decentralized git',
description: 'Decentralized git provider',
icon: 'assets/img/fileManager.webp',
@ -128,10 +128,10 @@ class DGitProvider extends Plugin {
return author
}
async init(input?) {
async init(input?: initInput): Promise<void> {
if ((Registry.getInstance().get('platform').api.isDesktop())) {
await this.call('isogit', 'init', {
defaultBranch: (input && input.branch) || 'main'
defaultBranch: (input && input.defaultBranch) || 'main'
})
this.emit('init')
return
@ -139,7 +139,7 @@ class DGitProvider extends Plugin {
await git.init({
...await this.addIsomorphicGitConfigFS(),
defaultBranch: (input && input.branch) || 'main'
defaultBranch: (input && input.defaultBranch) || 'main'
})
this.emit('init')
}
@ -153,7 +153,7 @@ class DGitProvider extends Plugin {
return version
}
async status(cmd) {
async status(cmd): Promise<Array<StatusRow>> {
if ((Registry.getInstance().get('platform').api.isDesktop())) {
const status = await this.call('isogit', 'status', cmd)
@ -169,7 +169,7 @@ class DGitProvider extends Plugin {
return status
}
async add(cmd) {
async add(cmd: addInput): Promise<void> {
if ((Registry.getInstance().get('platform').api.isDesktop())) {
await this.call('isogit', 'add', cmd)
@ -183,7 +183,7 @@ class DGitProvider extends Plugin {
this.emit('add')
}
async rm(cmd) {
async rm(cmd: rmInput) {
if ((Registry.getInstance().get('platform').api.isDesktop())) {
await this.call('isogit', 'rm', cmd)
@ -252,7 +252,7 @@ class DGitProvider extends Plugin {
this.emit('checkout')
}
async log(cmd) {
async log(cmd:{ref:string}):Promise<ReadCommitResult[]> {
if ((Registry.getInstance().get('platform').api.isDesktop())) {
const status = await this.call('isogit', 'log', {
@ -270,7 +270,7 @@ class DGitProvider extends Plugin {
return status
}
async compareBranches({ branch, remote }: { branch: branch, remote: remote }) {
async compareBranches({ branch, remote }: compareBranchesInput): Promise<branchDifference> {
// Get current branch commits
const headCommits = await git.log({
...await this.addIsomorphicGitConfigFS(),
@ -280,7 +280,7 @@ class DGitProvider extends Plugin {
// Get remote branch commits
const remoteCommits = await git.log({
...await this.addIsomorphicGitConfigFS(),
ref: `${remote.remote}/${branch.name}`,
ref: `${remote.name}/${branch.name}`,
});
// Convert arrays of commit objects to sets of commit SHAs
@ -299,7 +299,7 @@ class DGitProvider extends Plugin {
};
}
async getCommitChanges(commitHash1, commitHash2): Promise<commitChange[]> {
async getCommitChanges(commitHash1: string, commitHash2: string): Promise<commitChange[]> {
//console.log(commitHash1, commitHash2, [git.TREE({ ref: commitHash1 }), git.TREE({ ref: commitHash2 })])
const result: commitChange[] = await git.walk({
...await this.addIsomorphicGitConfigFS(),
@ -355,21 +355,23 @@ class DGitProvider extends Plugin {
return result
}
async remotes(config) {
async remotes(config): Promise<remote[]> {
if ((Registry.getInstance().get('platform').api.isDesktop())) {
return await this.call('isogit', 'remotes', config)
}
let remotes: remote[] = []
try {
remotes = await git.listRemotes({ ...config ? config : await this.addIsomorphicGitConfigFS() })
remotes = (await git.listRemotes({ ...config ? config : await this.addIsomorphicGitConfigFS() })).map((remote) =>
{ return { name: remote.remote, url: remote.url } }
)
} catch (e) {
// do nothing
}
return remotes
}
async branch(cmd, refresh = true) {
async branch(cmd: branchInputType): Promise<void> {
let status
if ((Registry.getInstance().get('platform').api.isDesktop())) {
@ -380,7 +382,7 @@ class DGitProvider extends Plugin {
...cmd
})
}
if (refresh) {
if (cmd.refresh) {
setTimeout(async () => {
await this.call('fileManager', 'refresh')
}, 1000)
@ -389,7 +391,7 @@ class DGitProvider extends Plugin {
return status
}
async currentbranch(config) {
async currentbranch(config: currentBranchInput): Promise<branch> {
if ((Registry.getInstance().get('platform').api.isDesktop())) {
return await this.call('isogit', 'currentbranch')
@ -411,7 +413,7 @@ class DGitProvider extends Plugin {
...defaultConfig,
path: `remote.${remoteName}.url`
})
remote = { remote: remoteName, url: remoteUrl }
remote = { name: remoteName, url: remoteUrl }
}
} catch (e) {
@ -427,7 +429,7 @@ class DGitProvider extends Plugin {
}
}
async branches(config) {
async branches(config): Promise<branch[]> {
if ((Registry.getInstance().get('platform').api.isDesktop())) {
return await this.call('isogit', 'branches')
@ -440,7 +442,7 @@ class DGitProvider extends Plugin {
let branches: branch[] = []
branches = (await git.listBranches(cmd)).map((branch) => { return { remote: undefined, name: branch } })
for (const remote of remotes) {
cmd.remote = remote.remote
cmd.remote = remote.name
const remotebranches = (await git.listBranches(cmd)).map((branch) => { return { remote: remote, name: branch } })
branches = [...branches, ...remotebranches]
}
@ -450,7 +452,7 @@ class DGitProvider extends Plugin {
}
}
async commit(cmd) {
async commit(cmd: commitInput): Promise<string> {
if ((Registry.getInstance().get('platform').api.isDesktop())) {
try {
@ -490,7 +492,7 @@ class DGitProvider extends Plugin {
return filesInStaging
}
async resolveref(cmd) {
async resolveref(cmd: resolveRefInput): Promise<string> {
if ((Registry.getInstance().get('platform').api.isDesktop())) {
return await this.call('isogit', 'resolveref', cmd)
@ -503,7 +505,7 @@ class DGitProvider extends Plugin {
return oid
}
async readblob(cmd) {
async readblob(cmd: readBlobInput): Promise<ReadBlobResult> {
if ((Registry.getInstance().get('platform').api.isDesktop())) {
const readBlobResult = await this.call('isogit', 'readblob', cmd)
return readBlobResult
@ -533,27 +535,27 @@ class DGitProvider extends Plugin {
}
}
async addremote(input) {
async addremote(input: remote): Promise<void> {
if ((Registry.getInstance().get('platform').api.isDesktop())) {
await this.call('isogit', 'addremote', { url: input.url, remote: input.remote })
await this.call('isogit', 'addremote', { url: input.url, remote: input.name })
return
}
await git.addRemote({ ...await this.addIsomorphicGitConfigFS(), url: input.url, remote: input.remote })
await git.addRemote({ ...await this.addIsomorphicGitConfigFS(), url: input.url, remote: input.name })
}
async delremote(input) {
async delremote(input: remote) {
if ((Registry.getInstance().get('platform').api.isDesktop())) {
await this.call('isogit', 'delremote', { remote: input.remote })
await this.call('isogit', 'delremote', { remote: input.name })
return
}
await git.deleteRemote({ ...await this.addIsomorphicGitConfigFS(), remote: input.remote })
await git.deleteRemote({ ...await this.addIsomorphicGitConfigFS(), remote: input.name })
}
async localStorageUsed() {
return this.calculateLocalStorage()
}
async clone(input, workspaceName, workspaceExists = false) {
async clone(input: cloneInputType) {
if ((Registry.getInstance().get('platform').api.isDesktop())) {
const folder = await this.call('fs', 'selectFolder', null, 'Select or create a folder to clone the repository in', 'Select as Repository Destination')
@ -581,7 +583,7 @@ class DGitProvider extends Plugin {
const permission = await this.askUserPermission('clone', 'Import multiple files into your workspaces.')
if (!permission) return false
if (parseFloat(this.calculateLocalStorage()) > 10000) throw new Error('The local storage of the browser is full.')
if (!workspaceExists) await this.call('filePanel', 'createWorkspace', workspaceName || `workspace_${Date.now()}`, true)
if (!input.workspaceExists) await this.call('filePanel', 'createWorkspace', input.workspaceName || `workspace_${Date.now()}`, true)
const cmd = {
url: input.url,
singleBranch: input.singleBranch,
@ -592,7 +594,7 @@ class DGitProvider extends Plugin {
}
this.call('terminal', 'logHtml', `Cloning ${input.url}...`)
const result = await git.clone(cmd)
if (!workspaceExists) {
if (!input.workspaceExists) {
setTimeout(async () => {
await this.call('fileManager', 'refresh')
}, 1000)
@ -733,13 +735,13 @@ class DGitProvider extends Plugin {
}
}
async push(input) {
async push(input: pushInputType) {
console.log('push input', input)
const cmd = {
force: input.force,
ref: input.ref,
remoteRef: input.remoteRef,
remote: input.remote,
ref: input.ref.name,
remoteRef: input.remoteRef.name,
remote: input.remote.name,
author: await this.getCommandUser(input),
input,
}
@ -762,12 +764,12 @@ class DGitProvider extends Plugin {
}
}
async pull(input) {
async pull(input: pullInputType) {
const cmd = {
ref: input.ref,
remoteRef: input.remoteRef,
ref: input.ref.name,
remoteRef: input.remoteRef.name,
author: await this.getCommandUser(input),
remote: input.remote,
remote: input.remote.name,
input,
}
let result
@ -791,12 +793,12 @@ class DGitProvider extends Plugin {
return result
}
async fetch(input) {
async fetch(input: fetchInputType) {
const cmd = {
ref: input.ref,
remoteRef: input.remoteRef,
ref: input.ref.name,
remoteRef: input.remoteRef.name,
author: await this.getCommandUser(input),
remote: input.remote,
remote: input.remote.name,
depth: input.depth || 5,
singleBranch: input.singleBranch,
relative: input.relative,
@ -1033,7 +1035,7 @@ class DGitProvider extends Plugin {
}
}
async remotecommits(input: { owner: string, repo: string, token: string, branch: string, length: number, page: number }): Promise<pagedCommits[]> {
async remotecommits(input: remoteCommitsInputType): Promise<pagedCommits[]> {
const octokit = new Octokit({
auth: input.token
})
@ -1095,7 +1097,7 @@ class DGitProvider extends Plugin {
return pages
}
async repositories(input: { token: string, page?: number, per_page?: number }) {
async repositories(input: repositoriesInput) {
const accessToken = input.token;

@ -22,7 +22,7 @@ export class GitPlugin extends ViewPlugin {
onDeactivation(): void {
this.call('fileDecorator', 'clearFileDecorators')
this.call('manager', 'activatePlugin', 'dGitProvider')
this.call('manager', 'activatePlugin', 'dgitApi')
}
render() {

@ -35,7 +35,7 @@ let requiredModules = [ // services + layout views + system views
'pluginManager',
'tabs',
'udapp',
'dGitProvider',
'dgitApi',
'solidity',
'solidity-logic',
'gistHandler',

@ -10,7 +10,7 @@ export class RemixEngine extends Engine {
setPluginOption ({ name, kind }) {
if (kind === 'provider') return { queueTimeout: 60000 * 2 }
if (name === 'LearnEth') return { queueTimeout: 60000 }
if (name === 'dGitProvider') return { queueTimeout: 60000 * 4 }
if (name === 'dgitApi') return { queueTimeout: 60000 * 4 }
if (name === 'slither') return { queueTimeout: 60000 * 4 } // Requires when a solc version is installed
if (name === 'hardhat') return { queueTimeout: 60000 * 4 }
if (name === 'truffle') return { queueTimeout: 60000 * 4 }

@ -6,6 +6,7 @@ import git from 'isomorphic-git'
import { dialog } from "electron";
import http from 'isomorphic-git/http/web'
import { gitProxy } from "../tools/git";
import { remote } from "../types";
const profile: Profile = {
name: 'isogit',
@ -328,9 +329,9 @@ class IsoGitPluginClient extends ElectronBasePluginClient {
async clone(cmd: any) {
if (this.gitIsInstalled) {
try{
try {
await gitProxy.clone(cmd.url, cmd.dir)
}catch(e){
} catch (e) {
throw e
}
} else {
@ -376,8 +377,9 @@ class IsoGitPluginClient extends ElectronBasePluginClient {
if (!this.workingDir || this.workingDir === '') {
return []
}
let remotes = []
remotes = await git.listRemotes({ ...await this.getGitConfig() })
let remotes: remote[] = []
remotes = (await git.listRemotes({ ...await this.getGitConfig() })).map((remote) => { return { name: remote.remote, url: remote.url } }
)
return remotes
}
@ -408,10 +410,10 @@ class IsoGitPluginClient extends ElectronBasePluginClient {
for (const remote of remotes) {
cmd = {
...cmd,
remote: remote.remote
remote: remote.name
}
const remotebranches = (await git.listBranches(cmd)).map((branch) => { return { remote: remote.remote, name: branch } })
const remotebranches = (await git.listBranches(cmd)).map((branch) => { return { remote: remote.name, name: branch } })
branches = [...branches, ...remotebranches]
}

@ -0,0 +1,9 @@
export type branch = {
name: string
remote: remote
}
export type remote = {
name: string
url: string
}

@ -81,14 +81,17 @@ export class RemixClient extends PluginClient {
try {
// @ts-ignore
this.call('notification', 'toast', 'cloning Snekmate Vyper repository...')
await this.call('manager', 'activatePlugin', 'dGitProvider')
await this.call('manager', 'activatePlugin', 'dgitApi')
/*
await this.call(
'dGitProvider',
'dgitApi',
'clone',
{url: 'https://github.com/pcaversaccio/snekmate', token: null, branch: 'v0.0.5'},
// @ts-ignore
'snekmate'
)
*/
this.call(
// @ts-ignore
'notification',

@ -29,17 +29,29 @@ export const SourceControlButtons = () => {
}
const pull = async () => {
await actions.pull(getRemoteName(), branch ? branch.name : context.currentBranch.name)
await actions.pull({
remote: getRemote(),
ref: branch ? branch : context.currentBranch
})
}
const push = async () => {
await actions.push(getRemoteName(), branch ? branch.name : context.currentBranch.name)
await actions.fetch(getRemoteName(), branch ? branch.name : context.currentBranch.name, null, null, true)
await actions.push({
remote: getRemote(),
ref: branch ? branch : context.currentBranch
})
await actions.fetch({
remote: getRemote(),
ref: branch ? branch : context.currentBranch,
relative: false,
depth: 1,
singleBranch: true
})
}
const sync = async () => {
await actions.pull(getRemoteName(), branch ? branch.name : context.currentBranch.name)
await actions.push(getRemoteName(), branch ? branch.name : context.currentBranch.name)
await pull()
await push()
}
const refresh = async() => {

@ -5,6 +5,7 @@ import { selectStyles, selectTheme } from "../../../types/styles";
import Select, { Options, OptionsOrGroups } from 'react-select'
import GitUIButton from "../../buttons/gituibutton";
import { remote } from "../../../types";
import { relative } from "path";
export const PushPull = () => {
const context = React.useContext(gitPluginContext)
@ -47,12 +48,46 @@ export const PushPull = () => {
const push = async () => {
console.log('PUSH', context.upstream, localBranch, remoteBranch, force)
await actions.push(context.upstream.name, localBranch, remoteBranch, force)
await actions.fetch(context.upstream.name, localBranch, remoteBranch, 1, true)
await actions.push({
remote: context.upstream,
ref: {
name: localBranch,
remote: null
},
remoteRef: {
name: remoteBranch,
remote: null
},
force: force
})
await actions.fetch({
remote: context.upstream,
ref: {
name: localBranch,
remote: null
},
remoteRef: {
name: remoteBranch,
remote: null
},
depth: 1,
relative: true,
singleBranch: true
})
}
const pull = async () => {
actions.pull(context.upstream.name, localBranch, remoteBranch)
await actions.pull({
remote: context.upstream,
ref: {
name: localBranch,
remote: null
},
remoteRef: {
name: remoteBranch,
remote: null
},
})
}
useEffect(() => {

@ -25,7 +25,14 @@ export const Commits = () => {
const loadNextPage = () => {
console.log('LOAD NEXT PAGE', context.commits.length)
actions.fetch(null, context.currentBranch.name, null, 5, true, true)
//actions.fetch(null, context.currentBranch.name, null, 5, true, true)
actions.fetch({
remote: null,
ref: context.currentBranch,
relative: true,
depth: 5,
singleBranch: true
})
//actions.getBranchCommits(branch, lastPageNumber+1)
}

@ -23,17 +23,17 @@ export const SourceControlItemButtons = (props: SourceControlItemButtonsProps) =
{status && status.indexOf("modified") === -1 ? <></> : <button onClick={async () => await actions.checkoutfile(file.filename)} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faUndo} className="" /></button>}
{status && status.indexOf("deleted") === -1 ? <></> : <button onClick={async () => await actions.checkoutfile(file.filename)} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faUndo} className="" /></button>}
{status && status.indexOf("deleted") !== -1 ? <></> : <button data-id={`unStage${group.name}${path.basename(file.filename)}`} onClick={async () => await actions.rm(file.filename)} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faMinus} className="" /></button>}
{status && status.indexOf("deleted") !== -1 ? <></> : <button data-id={`unStage${group.name}${path.basename(file.filename)}`} onClick={async () => await actions.rm({filepath:file.filename})} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faMinus} className="" /></button>}
</>
}
if (group.name === 'Changes') {
return <>
{status && status.indexOf("deleted") === -1 ? <></> : <><button onClick={async () => await actions.checkoutfile(file.filename)} data-id={`undo${group.name}${path.basename(file.filename)}`} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faUndo} className="" /></button><button data-id={`addToGit${group.name}${path.basename(file.filename)}`} onClick={async () => await actions.rm(file.filename)} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faPlus} className="" /></button></>}
{status && status.indexOf("deleted") === -1 ? <></> : <><button onClick={async () => await actions.checkoutfile(file.filename)} data-id={`undo${group.name}${path.basename(file.filename)}`} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faUndo} className="" /></button><button data-id={`addToGit${group.name}${path.basename(file.filename)}`} onClick={async () => await actions.rm({filepath:file.filename})} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faPlus} className="" /></button></>}
{status && status.indexOf("modified") === -1 ? <></> : <button onClick={async () => await actions.checkoutfile(file.filename)} data-id={`undo${group.name}${path.basename(file.filename)}`} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faUndo} className="" /></button>}
{(status && status.indexOf("unstaged") !== -1 || status && status.indexOf("deleted") !== -1) ? <></> : <button data-id={`addToGit${group.name}${path.basename(file.filename)}`} onClick={async () => await actions.add(file.filename)} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faPlus} className="" /></button>}
{(status && status.indexOf("unstaged") !== -1 && status && status.indexOf("modified") !== -1) ? <button data-id={`addToGit${group.name}${path.basename(file.filename)}`} onClick={async () => await actions.add(file.filename)} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faPlus} className="" /></button> : <></>}
{(status && status.indexOf("unstaged") !== -1 || status && status.indexOf("deleted") !== -1) ? <></> : <button data-id={`addToGit${group.name}${path.basename(file.filename)}`} onClick={async () => await actions.add({filepath:file.filename})} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faPlus} className="" /></button>}
{(status && status.indexOf("unstaged") !== -1 && status && status.indexOf("modified") !== -1) ? <button data-id={`addToGit${group.name}${path.basename(file.filename)}`} onClick={async () => await actions.add({filepath:file.filename})} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faPlus} className="" /></button> : <></>}
</>
}
return <></>

@ -2,7 +2,7 @@ import { ViewPlugin } from "@remixproject/engine-web";
import { ReadBlobResult, ReadCommitResult } from "isomorphic-git";
import React from "react";
import { fileStatus, fileStatusMerge, setRemoteBranchCommits, resetRemoteBranchCommits, setBranches, setCanCommit, setCommitChanges, setCommits, setCurrentBranch, setGitHubUser, setLoading, setRateLimit, setRemoteBranches, setRemotes, setRepos, setUpstream, setLocalBranchCommits, setBranchDifferences, setRemoteAsDefault, setScopes, setLog, clearLog } from "../state/gitpayload";
import { GitHubUser, RateLimit, branch, commitChange, gitActionDispatch, statusMatrixType, gitState, branchDifference, remote, gitLog, fileStatusResult } from '../types';
import { GitHubUser, RateLimit, branch, commitChange, gitActionDispatch, statusMatrixType, gitState, branchDifference, remote, gitLog, fileStatusResult, customGitApi, customDGitSystem, cloneInputType, fetchInputType, pullInputType, pushInputType, CustomRemixApi, checkoutInput, rmInput, addInput, repository } from '../types';
import { removeSlash } from "../utils";
import { disableCallBacks, enableCallBacks } from "./listeners";
import { AlertModal, ModalTypes } from "@remix-ui/app";
@ -37,8 +37,7 @@ const statusmatrix: statusMatrixType[] = fileStatuses.map((x: any) => {
};
});
let plugin: Plugin, dispatch: React.Dispatch<gitActionDispatch>
let plugin: Plugin<any, CustomRemixApi>, dispatch: React.Dispatch<gitActionDispatch>
export const setPlugin = (p: Plugin, dispatcher: React.Dispatch<gitActionDispatch>) => {
plugin = p
@ -48,13 +47,13 @@ export const setPlugin = (p: Plugin, dispatcher: React.Dispatch<gitActionDispatc
export const getBranches = async () => {
console.log('getBranches')
const branches = await plugin.call("dGitProvider", "branches");
const branches = await plugin.call('dgitApi', "branches")
console.log('branches :>>', branches)
dispatch(setBranches(branches));
}
export const getRemotes = async () => {
console.log('getRemotes')
const remotes: remote[] = await plugin.call("dGitProvider", "remotes" as any);
const remotes: remote[] = await plugin.call('dgitApi', "remotes");
console.log('remotes :>>', remotes)
dispatch(setRemotes(remotes));
}
@ -69,7 +68,7 @@ export const getFileStatusMatrix = async (filepaths: string[]) => {
statusmatrix.map((sm) => {
if (JSON.stringify(sm.status) === JSON.stringify(m.status)) {
//Utils.log(m, sm);
m.statusNames = sm.matrix;
//m.statusNames = sm.matrix;
}
});
});
@ -87,7 +86,7 @@ export const getCommits = async () => {
console.log('getCommits')
try {
const commits: ReadCommitResult[] = await plugin.call(
"dGitProvider",
'dgitApi',
"log",
{ ref: "HEAD" }
);
@ -114,11 +113,7 @@ export const showCurrentBranch = async () => {
const currentcommitoid = await getCommitFromRef("HEAD");
if (typeof branch === "undefined" || branch.name === "") {
//toast.warn(`You are in a detached state`);
plugin.call('notification', 'alert', {
type: 'warning',
title: 'You are in a detached state',
})
branch.name = `HEAD detached at ${currentcommitoid}`;
//canCommit = false;
dispatch(setCanCommit(false));
@ -136,7 +131,7 @@ export const currentBranch = async () => {
// eslint-disable-next-line no-useless-catch
try {
const branch: branch =
(await plugin.call("dGitProvider", "currentbranch")) || {
(await plugin.call('dgitApi', "currentbranch")) || {
name: "",
remote: {
name: "",
@ -152,14 +147,14 @@ export const currentBranch = async () => {
export const createBranch = async (name: string = "") => {
dispatch(setLoading(true))
if (name) {
await plugin.call("dGitProvider", "branch", { ref: name });
await plugin.call("dGitProvider", "checkout", { ref: name });
await plugin.call('dgitApi', 'branch', { ref: name });
await plugin.call('dgitApi', 'checkout', { ref: name });
}
dispatch(setLoading(false))
}
export const getCommitFromRef = async (ref: string) => {
const commitOid = await plugin.call("dGitProvider", "resolveref", {
const commitOid = await plugin.call('dgitApi', "resolveref", {
ref: ref,
});
return commitOid;
@ -169,7 +164,7 @@ const settingsWarning = async () => {
const username = await plugin.call('config' as any, 'getAppParameter', 'settings/github-user-name')
const email = await plugin.call('config' as any, 'getAppParameter', 'settings/github-email')
if (!username || !email) {
plugin.call('notification', 'toast', 'Please set your github username and email in the settings')
plugin.call('notification' as any, 'toast', 'Please set your github username and email in the settings')
return false;
} else {
return {
@ -188,7 +183,7 @@ export const commit = async (message: string = "") => {
return
}
const sha = await plugin.call("dGitProvider", "commit", {
const sha = await plugin.call('dgitApi', 'commit', {
author: {
name: credentials.username,
email: credentials.email,
@ -197,12 +192,12 @@ export const commit = async (message: string = "") => {
});
sendToGitLog({
type:'success',
type: 'success',
message: `Commited: ${sha}`
})
} catch (err) {
plugin.call('notification', 'toast', `${err}`)
plugin.call('notification' as any, 'toast', `${err}`)
}
}
@ -212,47 +207,29 @@ export const addall = async (files: fileStatusResult[]) => {
console.log('addall', files.map(f => removeSlash(f.filename)))
const filesToAdd = files.map(f => removeSlash(f.filename))
try {
await plugin.call("dGitProvider", "add", {
filepath: filesToAdd,
});
add({ filepath: filesToAdd })
} catch (e) { }
sendToGitLog({
type:'success',
type: 'success',
message: `Added all files to git`
})
} catch (e) {
plugin.call('notification', 'toast', `${e}`)
plugin.call('notification' as any, 'toast', `${e}`)
}
}
export const add = async (args: string | undefined) => {
if (args !== undefined) {
let filename = args; // $(args[0].currentTarget).data('file')
let stagingfiles;
if (filename !== "/") {
filename = removeSlash(filename);
stagingfiles = [filename];
} else {
//await addall();
return;
}
try {
for (const filepath of stagingfiles) {
export const add = async (filepath: addInput) => {
try {
await plugin.call("dGitProvider", "add", {
filepath: removeSlash(filepath),
});
} catch (e) { }
}
await plugin.call('dgitApi', 'add', filepath);
sendToGitLog({
type:'success',
message: `Added ${filename} to git`
type: 'success',
message: `Added to git`
})
} catch (e) {
plugin.call('notification', 'toast', `${e}`)
}
plugin.call('notification' as any, 'toast', `${e}`)
}
}
const getLastCommmit = async () => {
@ -265,14 +242,13 @@ const getLastCommmit = async () => {
}
}
export const rm = async (args: any) => {
const filename = args;
await plugin.call("dGitProvider", "rm", {
filepath: removeSlash(filename),
export const rm = async (args: rmInput) => {
await plugin.call('dgitApi', 'rm', {
filepath: removeSlash(args.filepath),
});
sendToGitLog({
type:'success',
message: `Removed ${filename} from git`
type: 'success',
message: `Removed from git`
})
}
@ -280,10 +256,10 @@ export const checkoutfile = async (filename: string) => {
const oid = await getLastCommmit();
if (oid)
try {
const commitOid = await plugin.call("dGitProvider", "resolveref", {
const commitOid = await plugin.call('dgitApi', 'resolveref', {
ref: oid,
});
const { blob } = await plugin.call("dGitProvider", "readblob", {
const { blob } = await plugin.call('dgitApi', 'readblob', {
oid: commitOid,
filepath: removeSlash(filename),
});
@ -298,47 +274,44 @@ export const checkoutfile = async (filename: string) => {
);
await enableCallBacks();
} catch (e) {
plugin.call('notification', 'toast', `No such file`)
plugin.call('notification' as any, 'toast', `No such file`)
}
}
export const checkout = async (cmd: any) => {
export const checkout = async (cmd: checkoutInput) => {
console.log(cmd)
await disableCallBacks();
await plugin.call('fileManager', 'closeAllFiles')
try {
await plugin.call("dGitProvider", "checkout", cmd);
await plugin.call('dgitApi', 'checkout', cmd)
gitlog();
} catch (e) {
plugin.call('notification', 'toast', `${e}`)
plugin.call('notification' as any, 'toast', `${e}`)
}
await enableCallBacks();
}
export const clone = async (url: string, branch: string, depth: number, singleBranch: boolean) => {
console.log(url, branch, depth, singleBranch)
export const clone = async (input: cloneInputType) => {
dispatch(setLoading(true))
try {
await disableCallBacks()
// get last part of url
const urlParts = url.split("/");
const urlParts = input.url.split("/");
const lastPart = urlParts[urlParts.length - 1];
const repoName = lastPart.split(".")[0];
// add timestamp to repo name
const timestamp = new Date().getTime();
const repoNameWithTimestamp = `${repoName}-${timestamp}`;
//const token = await tokenWarning();
const token = await plugin.call('config' as any, 'getAppParameter', 'settings/gist-access-token')
//if (!token) {
// dispatch(setLoading(false))
// return
//} else {
await plugin.call('dGitProvider' as any, 'clone', { url, branch, token, depth, singleBranch }, repoNameWithTimestamp);
const token = await plugin.call('config' as any, 'getAppParameter' as any, 'settings/gist-access-token')
await plugin.call('dgitApi', 'clone', { ...input, workspaceName: repoNameWithTimestamp });
await enableCallBacks()
sendToGitLog({
type:'success',
message: `Cloned ${url} to ${repoNameWithTimestamp}`
type: 'success',
message: `Cloned ${input.url} to ${repoNameWithTimestamp}`
})
//}
} catch (e: any) {
@ -347,12 +320,12 @@ export const clone = async (url: string, branch: string, depth: number, singleBr
dispatch(setLoading(false))
}
export const fetch = async (remote?: string, ref?: string, remoteRef?: string, depth?: number, singleBranch?: boolean, relative?: boolean, quiet?: boolean) => {
export const fetch = async (input: fetchInputType) => {
dispatch(setLoading(true))
await disableCallBacks()
try {
await plugin.call('dGitProvider' as any, 'fetch', { remote, ref, remoteRef, depth, singleBranch, relative });
if (!quiet) {
await plugin.call('dgitApi', 'fetch', input);
if (!input.quiet) {
await gitlog()
await getBranches()
}
@ -364,11 +337,11 @@ export const fetch = async (remote?: string, ref?: string, remoteRef?: string, d
await enableCallBacks()
}
export const pull = async (remote?: string, ref?: string, remoteRef?: string) => {
export const pull = async (input: pullInputType) => {
dispatch(setLoading(true))
await disableCallBacks()
try {
await plugin.call('dGitProvider' as any, 'pull', { remote, ref, remoteRef })
await plugin.call('dgitApi', 'pull', input)
await gitlog()
} catch (e: any) {
await parseError(e)
@ -377,11 +350,11 @@ export const pull = async (remote?: string, ref?: string, remoteRef?: string) =>
await enableCallBacks()
}
export const push = async (remote?: string, ref?: string, remoteRef?: string, force?: boolean) => {
export const push = async (input: pushInputType) => {
dispatch(setLoading(true))
await disableCallBacks()
try {
await plugin.call('dGitProvider' as any, 'push', { remote, ref, remoteRef, force })
await plugin.call('dgitApi', 'push', input)
} catch (e: any) {
await parseError(e)
}
@ -390,7 +363,7 @@ export const push = async (remote?: string, ref?: string, remoteRef?: string, fo
}
const tokenWarning = async () => {
const token = await plugin.call('config' as any, 'getAppParameter', 'settings/gist-access-token')
const token = await plugin.call('config' as any, 'getAppParameter' as any, 'settings/gist-access-token')
if (!token) {
return false;
} else {
@ -402,7 +375,7 @@ const parseError = async (e: any) => {
console.trace(e)
// if message conttains 401 Unauthorized, show token warning
if (e.message.includes('401')) {
const result = await plugin.call('notification', 'modal', {
const result = await plugin.call('notification' as any, 'modal' as any, {
title: 'The GitHub token may be missing or invalid',
message: 'Please check the GitHub token and try again. Error: 401 Unauthorized',
okLabel: 'Go to settings',
@ -413,7 +386,7 @@ const parseError = async (e: any) => {
}
// if message contains 404 Not Found, show repo not found
else if (e.message.includes('404')) {
await plugin.call('notification', 'modal', {
await plugin.call('notification' as any, 'modal' as any, {
title: 'Repository not found',
message: 'Please check the URL and try again.',
okLabel: 'Go to settings',
@ -423,7 +396,7 @@ const parseError = async (e: any) => {
}
// if message contains 403 Forbidden
else if (e.message.includes('403')) {
await plugin.call('notification', 'modal', {
await plugin.call('notification' as any, 'modal' as any, {
title: 'The GitHub token may be missing or invalid',
message: 'Please check the GitHub token and try again. Error: 403 Forbidden',
okLabel: 'Go to settings',
@ -431,14 +404,14 @@ const parseError = async (e: any) => {
type: ModalTypes.confirm
})
} else if (e.toString().includes('NotFoundError') && !e.toString().includes('fetch')) {
await plugin.call('notification', 'modal', {
await plugin.call('notification' as any, 'modal', {
title: 'Remote branch not found',
message: 'The branch you are trying to fetch does not exist on the remote. If you have forked this branch from another branch, you may need to fetch the original branch first or publish this branch on the remote.',
okLabel: 'OK',
type: ModalTypes.alert
})
} else {
await plugin.call('notification', 'alert', {
await plugin.call('notification' as any, 'alert' as any, {
title: 'Error',
message: e.message
})
@ -449,13 +422,13 @@ export const repositories = async () => {
try {
const token = await tokenWarning();
if (token) {
let repos = await plugin.call('dGitProvider' as any, 'repositories', { token, per_page: 100 })
let repos = await plugin.call('dgitApi', 'repositories', { token, per_page: 100 })
dispatch(setRepos(repos))
let page = 2
let hasMoreData = true
const per_page = 100
while (hasMoreData) {
const pagedResponse = await plugin.call('dGitProvider' as any, 'repositories', { token, page: page, per_page: per_page })
const pagedResponse = await plugin.call('dgitApi', 'repositories', { token, page: page, per_page: per_page })
if (pagedResponse.length < per_page) {
hasMoreData = false
}
@ -465,7 +438,7 @@ export const repositories = async () => {
}
} else {
plugin.call('notification', 'alert', {
plugin.call('notification' as any, 'alert', {
title: 'Error getting repositories',
message: `Please check your GitHub token in the GitHub settings... cannot connect to GitHub`
})
@ -473,7 +446,7 @@ export const repositories = async () => {
}
} catch (e) {
console.log(e)
plugin.call('notification', 'alert', {
plugin.call('notification' as any, 'alert', {
title: 'Error getting repositories',
message: `${e.message}: Please check your GitHub token in the GitHub settings.`
})
@ -485,13 +458,13 @@ export const remoteBranches = async (owner: string, repo: string) => {
try {
const token = await tokenWarning();
if (token) {
let branches = await plugin.call('dGitProvider' as any, 'remotebranches', { token, owner, repo, per_page: 100 });
let branches = await plugin.call('dgitApi' as any, 'remotebranches', { token, owner, repo, per_page: 100 });
dispatch(setRemoteBranches(branches))
let page = 2
let hasMoreData = true
const per_page = 100
while (hasMoreData) {
const pagedResponse = await plugin.call('dGitProvider' as any, 'remotebranches', { token, owner, repo, page: page, per_page: per_page })
const pagedResponse = await plugin.call('dgitApi' as any, 'remotebranches', { token, owner, repo, page: page, per_page: per_page })
if (pagedResponse.length < per_page) {
hasMoreData = false
}
@ -500,7 +473,7 @@ export const remoteBranches = async (owner: string, repo: string) => {
page++
}
} else {
plugin.call('notification', 'alert', {
plugin.call('notification' as any, 'alert', {
title: 'Error getting branches',
message: `Please check your GitHub token in the GitHub settings. It needs to have access to the branches.`
})
@ -508,7 +481,7 @@ export const remoteBranches = async (owner: string, repo: string) => {
}
} catch (e) {
console.log(e)
plugin.call('notification', 'alert', {
plugin.call('notification' as any, 'alert', {
title: 'Error',
message: e.message
})
@ -532,7 +505,7 @@ export const remoteCommits = async (url: string, branch: string, length: number)
const token = await tokenWarning();
if (token) {
console.log(token, owner, repo, branch, length)
const commits = await plugin.call('dGitProvider' as any, 'remotecommits', { token, owner, repo, branch, length });
const commits = await plugin.call('dgitApi' as any, 'remotecommits', { token, owner, repo, branch, length });
console.log(commits, 'remote commits')
} else {
sendToGitLog({
@ -542,7 +515,7 @@ export const remoteCommits = async (url: string, branch: string, length: number)
}
} catch (e) {
console.log(e)
plugin.call('notification', 'alert', {
plugin.call('notification' as any, 'alert', {
title: 'Error',
message: e.message
})
@ -551,9 +524,9 @@ export const remoteCommits = async (url: string, branch: string, length: number)
export const saveGitHubCredentials = async (credentials: { username: string, email: string, token: string }) => {
try {
await plugin.call('config' as any, 'setAppParameter', 'settings/github-user-name', credentials.username)
await plugin.call('config' as any, 'setAppParameter', 'settings/github-email', credentials.email)
await plugin.call('config' as any, 'setAppParameter', 'settings/gist-access-token', credentials.token)
await plugin.call('config' as any, 'setAppParameter' as any, 'settings/github-user-name', credentials.username)
await plugin.call('config' as any, 'setAppParameter' as any, 'settings/github-email', credentials.email)
await plugin.call('config' as any, 'setAppParameter' as any, 'settings/gist-access-token', credentials.token)
} catch (e) {
console.log(e)
}
@ -562,9 +535,9 @@ export const saveGitHubCredentials = async (credentials: { username: string, ema
export const getGitHubCredentials = async () => {
if (!plugin) return
try {
const username = await plugin.call('config' as any, 'getAppParameter', 'settings/github-user-name')
const email = await plugin.call('config' as any, 'getAppParameter', 'settings/github-email')
const token = await plugin.call('config' as any, 'getAppParameter', 'settings/gist-access-token')
const username = await plugin.call('config' as any, 'getAppParameter' as any, 'settings/github-user-name')
const email = await plugin.call('config' as any, 'getAppParameter' as any, 'settings/github-email')
const token = await plugin.call('config' as any, 'getAppParameter' as any, 'settings/gist-access-token')
return {
username,
email,
@ -584,7 +557,7 @@ export const getGitHubUser = async () => {
user: GitHubUser,
ratelimit: RateLimit
scopes: string[]
} = await plugin.call('dGitProvider' as any, 'getGitHubUser', { token });
} = await plugin.call('dgitApi' as any, 'getGitHubUser', { token });
console.log('GET USER"', data)
@ -600,7 +573,7 @@ export const getGitHubUser = async () => {
}
export const statusMatrix = async (filepaths: string[]) => {
const matrix = await plugin.call("dGitProvider", "status", { ref: "HEAD", filepaths: filepaths || ['.']});
const matrix = await plugin.call('dgitApi', 'status', { ref: "HEAD", filepaths: filepaths || ['.'] });
const result = (matrix || []).map((x) => {
return {
filename: `/${x.shift()}`,
@ -616,7 +589,7 @@ export const diffFiles = async (filename: string | undefined) => {
}
export const resolveRef = async (ref: string) => {
const oid = await plugin.call("dGitProvider", "resolveref", {
const oid = await plugin.call('dgitApi', "resolveref", {
ref,
});
return oid;
@ -636,7 +609,7 @@ export const diff = async (commitChange: commitChange) => {
} else {
try {
const modifiedContentReadBlobResult: ReadBlobResult = await plugin.call("dGitProvider", "readblob", {
const modifiedContentReadBlobResult: ReadBlobResult = await plugin.call('dgitApi', "readblob", {
oid: commitChange.hashModified,
filepath: removeSlash(commitChange.path),
});
@ -651,7 +624,7 @@ export const diff = async (commitChange: commitChange) => {
}
try {
const originalContentReadBlobResult: ReadBlobResult = await plugin.call("dGitProvider", "readblob", {
const originalContentReadBlobResult: ReadBlobResult = await plugin.call('dgitApi', "readblob", {
oid: commitChange.hashOriginal,
filepath: removeSlash(commitChange.path),
});
@ -672,7 +645,7 @@ export const getCommitChanges = async (oid1: string, oid2: string, branch?: bran
let log
try {
// check if oid2 exists
log = await plugin.call('dGitProvider', 'log', {
log = await plugin.call('dgitApi', 'log', {
ref: branch ? branch.name : 'HEAD',
})
console.log(log, 'log')
@ -683,10 +656,19 @@ export const getCommitChanges = async (oid1: string, oid2: string, branch?: bran
const foundCommit = log.find((commit: ReadCommitResult) => commit.oid === oid2)
if (!foundCommit && remote) {
console.log('getCommitChanges fetching remote')
await fetch(remote ? remote.name : null, branch ? branch.name : null, null, 5, true, true)
//await fetch(remote ? remote.name : null, branch ? branch.name : null, null, 5, true, true)
await fetch({
remote: remote,
singleBranch: true,
quiet: true,
relative: true,
depth: 5,
ref: branch,
remoteRef: null
})
}
}
const result: commitChange[] = await plugin.call('dGitProvider', 'getCommitChanges', oid1, oid2)
const result: commitChange[] = await plugin.call('dgitApi', 'getCommitChanges', oid1, oid2)
dispatch(setCommitChanges(result))
return result
} catch (e) {
@ -714,27 +696,27 @@ export const fetchBranch = async (branch: branch, page: number) => {
dispatch(resetRemoteBranchCommits({ branch }))
}
const { owner, repo } = await getRepoDetails(branch.remote.url);
const rc = await plugin.call('dGitProvider' as any, 'remotecommits', { token, owner: owner, repo: repo, branch: branch.name, length, page });
const rc = await plugin.call('dgitApi', 'remotecommits', { token, owner: owner, repo: repo, branch: branch.name, length, page });
console.log(rc, 'remote commits from octokit')
dispatch(setRemoteBranchCommits({ branch, commits: rc }))
return
}
export const getBranchDifferences = async (branch: branch, remote: remote, state: gitState) => {
if (!remote && state){
if (state.defaultRemote){
if (!remote && state) {
if (state.defaultRemote) {
remote = state.defaultRemote
} else {
remote = state.remotes.find((remote: remote) => remote.name === 'origin')
}
if (!remote && state.remotes[0]){
if (!remote && state.remotes[0]) {
remote = state.remotes[0]
}
}
if (!remote) return
try {
console.log('compare', branch, remote)
const branchDifference: branchDifference = await plugin.call('dGitProvider', 'compareBranches', {
const branchDifference: branchDifference = await plugin.call('dgitApi', 'compareBranches', {
branch,
remote
})
@ -756,7 +738,7 @@ export const getBranchCommits = async (branch: branch, page: number) => {
try {
console.log(branch)
if (!branch.remote) {
const commits: ReadCommitResult[] = await plugin.call('dGitProvider', 'log', {
const commits: ReadCommitResult[] = await plugin.call('dgitApi', 'log', {
ref: branch.name,
})
console.log(commits)
@ -778,7 +760,7 @@ export const setDefaultRemote = async (remote: remote) => {
export const addRemote = async (remote: remote) => {
try {
await plugin.call('dGitProvider', 'addremote', remote)
await plugin.call('dgitApi', 'addremote', remote)
await getRemotes()
} catch (e) {
console.log(e)
@ -787,7 +769,7 @@ export const addRemote = async (remote: remote) => {
export const removeRemote = async (remote: remote) => {
try {
await plugin.call('dGitProvider', 'delremote', remote)
await plugin.call('dgitApi', 'delremote', remote)
await getRemotes()
} catch (e) {
console.log(e)

@ -2,10 +2,12 @@
import { ViewPlugin } from "@remixproject/engine-web";
import React from "react";
import { setCanUseApp, setLoading, setRepoName, setGItHubToken, setLog } from "../state/gitpayload";
import { gitActionDispatch } from "../types";
import { CustomRemixApi, customDGitSystem, gitActionDispatch } from "../types";
import { Plugin } from "@remixproject/engine";
import { diffFiles, getBranches, getFileStatusMatrix, getGitHubUser, getRemotes, gitlog, setPlugin } from "./gitactions";
import { Profile } from "@remixproject/plugin-utils";
let plugin: ViewPlugin, gitDispatch: React.Dispatch<gitActionDispatch>, loaderDispatch: React.Dispatch<any>, loadFileQueue: AsyncDebouncedQueue
let plugin: Plugin<any, CustomRemixApi>, gitDispatch: React.Dispatch<gitActionDispatch>, loaderDispatch: React.Dispatch<any>, loadFileQueue: AsyncDebouncedQueue
let callBackEnabled: boolean = false
let syncTimer: NodeJS.Timer = null
@ -34,7 +36,7 @@ class AsyncDebouncedQueue {
export const setCallBacks = (viewPlugin: ViewPlugin, gitDispatcher: React.Dispatch<gitActionDispatch>, loaderDispatcher: React.Dispatch<any>) => {
export const setCallBacks = (viewPlugin: Plugin, gitDispatcher: React.Dispatch<gitActionDispatch>, loaderDispatcher: React.Dispatch<any>) => {
plugin = viewPlugin
gitDispatch = gitDispatcher
loaderDispatch = loaderDispatcher
@ -49,10 +51,10 @@ export const setCallBacks = (viewPlugin: ViewPlugin, gitDispatcher: React.Dispat
})
});
plugin.on('dGitProvider', 'checkout' as any, async () => {
plugin.on('dgitApi', 'checkout', async () => {
//await synTimerStart();
})
plugin.on('dGitProvider', 'branch' as any, async () => {
plugin.on('dgitApi', 'branch', async () => {
//await synTimerStart();
})
@ -98,23 +100,23 @@ export const setCallBacks = (viewPlugin: ViewPlugin, gitDispatcher: React.Dispat
//await synTimerStart();
});
plugin.on('dGitProvider', 'checkout', async () => {
plugin.on('dgitApi', 'checkout', async () => {
})
plugin.on('dGitProvider', 'init', async () => {
plugin.on('dgitApi', 'init', async () => {
})
plugin.on('dGitProvider', 'add', async () => {
plugin.on('dgitApi', 'add', async () => {
loadFileQueue.enqueue(async () => {
loadFiles()
}, 10)
})
plugin.on('dGitProvider', 'rm', async () => {
plugin.on('dgitApi', 'rm', async () => {
loadFileQueue.enqueue(async () => {
loadFiles()
}, 10)
})
plugin.on('dGitProvider', 'commit', async () => {
plugin.on('dgitApi', 'commit', async () => {
loadFileQueue.enqueue(async () => {
gitlog()
}, 10)
@ -123,13 +125,13 @@ export const setCallBacks = (viewPlugin: ViewPlugin, gitDispatcher: React.Dispat
type: 'success'
}))
})
plugin.on('dGitProvider', 'branch', async () => {
plugin.on('dgitApi', 'branch', async () => {
gitDispatch(setLog({
message: "Created Branch",
type: "success"
}))
})
plugin.on('dGitProvider', 'clone', async () => {
plugin.on('dgitApi', 'clone', async () => {
gitDispatch(setLog({
message: "Cloned Repository",
type: "success"
@ -138,17 +140,17 @@ export const setCallBacks = (viewPlugin: ViewPlugin, gitDispatcher: React.Dispat
loadFiles()
})
})
plugin.on('manager', 'pluginActivated', async (p: Plugin) => {
if (p.name === 'dGitProvider') {
plugin.on('manager', 'pluginActivated', async (p: Profile<any>) => {
if (p.name === 'dgitApi') {
getGitHubUser();
plugin.off('manager', 'pluginActivated');
}
})
plugin.on('config', 'configChanged', async () => {
plugin.on('config' as any, 'configChanged', async () => {
await getGitConfig()
})
plugin.on('settings', 'configChanged', async () => {
plugin.on('settings' as any, 'configChanged', async () => {
await getGitConfig()
})
@ -156,9 +158,9 @@ export const setCallBacks = (viewPlugin: ViewPlugin, gitDispatcher: React.Dispat
}
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 username = await plugin.call('settings' as any, 'get', 'settings/github-user-name')
const email = await plugin.call('settings' as any, 'get', 'settings/github-email')
const token = await plugin.call('settings' as any, 'get', 'settings/gist-access-token')
const config = { username, email, token }
gitDispatch(setGItHubToken(config.token))
return config
@ -206,7 +208,7 @@ const getStorageUsed = async () => {
try {
const storageUsed = await plugin.call("storage" as any, "getStorage" as any);
} catch (e) {
const storage: string = await plugin.call("dGitProvider", "localStorageUsed" as any);
const storage: string = await plugin.call('dgitApi', "localStorageUsed" as any);
const storageUsed = {
usage: parseFloat(storage) * 1000,
quota: 10000000,

@ -1,20 +1,20 @@
import { ReadCommitResult } from "isomorphic-git"
import React from "react"
import { branch, commitChange, fileStatusResult, gitLog, gitState, remote } from "../types"
import { addInput, branch, checkoutInput, cloneInputType, commitChange, fetchInputType, fileStatusResult, gitLog, gitState, pullInputType, pushInputType, remote, rmInput } from "../types"
export interface gitActions {
removeRemote(remote: remote): void
clone(url: string, path: string, depth: number, singleBranch: boolean): Promise<void>
add(path: string): Promise<void>
rm(path: string): Promise<void>
clone(input: cloneInputType): Promise<void>
add(input: addInput): Promise<void>
rm(input: rmInput): Promise<void>
commit(message: string): Promise<any>
addall(files: fileStatusResult[]): Promise<void>
push(remote?: string, ref?: string, remoteRef?: string, force?: boolean): Promise<void>
pull(remote?: string, ref?: string, remoteRef?: string): Promise<void>
fetch(remote?: string, ref?: string, remoteRef?: string, depth?: number, singleBranch?: boolean, relative?: boolean, quiet?: boolean): Promise<void>
push(input: pushInputType): Promise<void>
pull(input: pullInputType): Promise<void>
fetch(input: fetchInputType): Promise<void>
repositories(): Promise<any>
checkoutfile(file: string): Promise<void>
checkout(cmd: any): Promise<void>
checkout(input: checkoutInput): Promise<void>
createBranch(branch: string): Promise<void>
remoteBranches(owner: string, repo: string): Promise<any>
getCommitChanges(oid1: string, oid2: string, branch?: branch, remote?: remote): Promise<commitChange[] | boolean>

@ -1,5 +1,5 @@
import { ReadCommitResult } from "isomorphic-git"
import { GitHubUser, branch, commitChange, fileStatusResult, remote, pagedCommits, branchDifference, gitLog } from "../types"
import { GitHubUser, branch, commitChange, fileStatusResult, remote, pagedCommits, branchDifference, gitLog, repository } from "../types"
import { Endpoints } from "@octokit/types"
export const fileStatus = (files: fileStatusResult[]) => {
@ -30,7 +30,7 @@ export const setBranches = (branches: any[]) => {
}
}
export const setRepos = (repos: any[]) => {
export const setRepos = (repos: repository[]) => {
return {
type: 'SET_REPOS',
payload: repos

@ -1,8 +1,164 @@
import { Endpoints } from "@octokit/types"
import { CommitObject, ReadCommitResult } from "isomorphic-git"
import { IRemixApi } from "@remixproject/plugin-api"
import { LibraryProfile, StatusEvents } from "@remixproject/plugin-utils"
import { CommitObject, ReadBlobResult, ReadCommitResult, StatusRow } from "isomorphic-git"
export type GitHubUser = Endpoints["GET /user"]["response"]['data']
export type RateLimit = Endpoints["GET /rate_limit"]["response"]["data"]
export interface customDGitSystem {
events: {
"checkout": () => void
"clone": () => void
"add": () => void
"rm": () => void
"commit": () => void
"branch": () => void
"init": () => void
} & StatusEvents,
methods: {
getCommitChanges(oid1: string, oid2: string): Promise<commitChange[]>
//getBranchCommits(branch: branch): Promise<ReadCommitResult[]>
//fetchBranch(branch: branch): Promise<any>
//remotebranches(owner: string, repo: string): Promise<branch[]>
//remoteCommits(url: string, branch: string, length: number): Promise<ReadCommitResult[]>
repositories(input: repositoriesInput): Promise<repository[]>
clone(input: cloneInputType): Promise<any>
branches(input?: branchesInput): Promise<branch[]>,
remotes(): Promise<remote[]>,
log(cmd: { ref: string }): Promise<ReadCommitResult[]>,
remotecommits(input: remoteCommitsInputType): Promise<pagedCommits[]>
fetch(input: fetchInputType): Promise<any>
pull(input: pullInputType): Promise<any>
push(input: pushInputType): Promise<any>
//getGitHubUser(token: string): Promise<{ user: GitHubUser, ratelimit: RateLimit }>
//saveGitHubCredentials(credentials: { username: string, email: string, token: string }): Promise<any>
//getGitHubCredentials(): Promise<{ username: string, email: string, token: string }>
currentbranch(input?: currentBranchInput): Promise<branch>
branch(input: branchInputType): Promise<void>
checkout(input: checkoutInput): Promise<void>
add(input: addInput): Promise<void>
rm(input: rmInput): Promise<void>
resolveref(input: resolveRefInput): Promise<string>
readblob(input: readBlobInput): Promise<ReadBlobResult>
commit(input: commitInput): Promise<string>
addremote(input: remote): Promise<void>
delremote(input: remote): Promise<void>
status(input?: statusInput): Promise<Array<StatusRow>>
compareBranches(input: compareBranchesInput): Promise<branchDifference>
init(input?: initInput): Promise<void>
updateSubmodules: (input: updateSubmodulesInput) => Promise<void>
}
}
export interface ICustomRemixApi extends IRemixApi {
dgitApi: customDGitSystem
}
export declare type CustomRemixApi = Readonly<ICustomRemixApi>;
export type initInput = {
defaultBranch: string
}
export type updateSubmodulesInput = {
dir?: string
token?: string
}
export type remoteCommitsInputType = {
owner: string, repo: string, token: string, branch: string, length: number, page: number
}
export type compareBranchesInput = {
branch: branch, remote: remote
}
export type fetchInputType = {
remote: remote, ref: branch, remoteRef?: branch, depth: number, singleBranch: boolean, relative: boolean, quiet?: boolean
}
export type pullInputType = {
remote: remote, ref: branch, remoteRef?: branch
}
export type pushInputType = {
remote: remote, ref: branch, remoteRef?: branch, force?: boolean
}
export type branchInputType = {
ref: string,
checkout?: boolean
refresh?: boolean
}
export type currentBranchInput = {
fs: any,
dir: string
}
export type checkoutInput = {
ref: string,
force?: boolean,
remote?: string
refresh?: boolean
}
export type addInput = {
filepath: string | string[]
}
export type rmInput = {
filepath: string
}
export type resolveRefInput = {
ref: string
}
export type readBlobInput = {
oid: string,
filepath: string
}
export type commitInput = {
author: {
name: string,
email: string,
},
message: string,
}
export type branchesInput = {
fs?: any
dir?: string
}
export interface cloneInputType {
url: string,
branch?: string,
depth?: number,
singleBranch?: boolean
workspaceName?: string
workspaceExists?: boolean
token?: string
}
export interface repositoriesInput { token: string, page?: number, per_page?: number }
export interface statusInput { ref: string, filepaths?: string[] }
export const dGitProfile: LibraryProfile<customDGitSystem> = {
name: 'dgitApi',
methods: ['clone', 'branches', 'remotes', 'getCommitChanges', 'log', 'remotecommits'],
}
export interface customGitApi extends IRemixApi {
dgit: customDGitSystem
}
export type gitState = {
currentBranch: branch
commits: ReadCommitResult[]
@ -38,7 +194,7 @@ export type gitState = {
log: gitLog[]
}
export type gitLog = {
type: 'error' | 'warning' | 'info' |'success',
type: 'error' | 'warning' | 'info' | 'success',
message: string
}

@ -71,7 +71,7 @@ function HomeTabGetStarted({ plugin }: HomeTabGetStartedProps) {
const metadata = TEMPLATE_METADATA[templateName]
if (metadata) {
if (metadata.type === 'git') {
await plugin.call('dGitProvider', 'clone', { url: metadata.url, branch: metadata.branch }, templateDisplayName)
await plugin.call('dgitApi', 'clone', { url: metadata.url, branch: metadata.branch }, templateDisplayName)
} else if (metadata && metadata.type === 'plugin') {
await plugin.appManager.activatePlugin('filePanel')
templateDisplayName = await plugin.call('filePanel', 'getAvailableWorkspaceName', templateDisplayName)

@ -1,4 +1,5 @@
import { fileDecoration } from '@remix-ui/file-decorators'
import { branch } from '@remix-ui/git';
import { Action, ActionPayloadTypes, FileTree, WorkspaceElement, action } from '../types'
export const setCurrentWorkspace = (workspace: { name: string; isGitRepo: boolean; }): Action<'SET_CURRENT_WORKSPACE'> => {
@ -280,7 +281,7 @@ export const setCurrentWorkspaceBranches = (branches?: { remote: any, name: stri
}
}
export const setCurrentWorkspaceCurrentBranch = (currentBranch?: string): Action<'SET_CURRENT_WORKSPACE_CURRENT_BRANCH'> => {
export const setCurrentWorkspaceCurrentBranch = (currentBranch?: branch): Action<'SET_CURRENT_WORKSPACE_CURRENT_BRANCH'> => {
return {
type: 'SET_CURRENT_WORKSPACE_CURRENT_BRANCH',
payload: currentBranch

@ -42,8 +42,9 @@ import { ROOT_PATH, slitherYml, solTestYml, tsSolTestYml } from '../utils/consta
import { IndexedDBStorage } from '../../../../../../apps/remix-ide/src/app/files/filesystems/indexedDB'
import { getUncommittedFiles } from '../utils/gitStatusFilter'
import { AppModal, ModalTypes } from '@remix-ui/app'
import { branch } from '@remix-ui/git'
import { CustomRemixApi, branch, cloneInputType, customDGitSystem } from '@remix-ui/git'
import * as templates from '@remix-project/remix-ws-templates'
import { Plugin } from "@remixproject/engine";
declare global {
interface Window {
@ -56,27 +57,28 @@ const NO_WORKSPACE = ' - none - '
const ELECTRON = 'electron'
const queryParams = new QueryParams()
const _paq = (window._paq = window._paq || []) //eslint-disable-line
let plugin, dispatch: React.Dispatch<any>
let plugin: any, dgitPlugin: Plugin<any, CustomRemixApi>,dispatch: React.Dispatch<any>
export const setPlugin = (filePanelPlugin, reducerDispatch) => {
plugin = filePanelPlugin
dgitPlugin = filePanelPlugin
dispatch = reducerDispatch
plugin.on('dGitProvider', 'checkout', async () => {
dgitPlugin.on('dgitApi', 'checkout', async () => {
await checkGit()
})
plugin.on('dGitProvider', 'init', async () => {
dgitPlugin.on('dgitApi', 'init', async () => {
await checkGit()
})
plugin.on('dGitProvider', 'add', async () => {
dgitPlugin.on('dgitApi', 'add', async () => {
await checkGit()
})
plugin.on('dGitProvider', 'commit', async () => {
dgitPlugin.on('dgitApi', 'commit', async () => {
await checkGit()
})
plugin.on('dGitProvider', 'branch', async () => {
dgitPlugin.on('dgitApi', 'branch', async () => {
await checkGit()
})
plugin.on('dGitProvider', 'clone', async () => {
dgitPlugin.on('dgitApi', 'clone', async () => {
await checkGit()
})
plugin.on('config', 'configChanged', async () => {
@ -153,7 +155,7 @@ export const createWorkspace = async (
if (isGitRepo && createCommit) {
const name = await plugin.call('settings', 'get', 'settings/github-user-name')
const email = await plugin.call('settings', 'get', 'settings/github-email')
const currentBranch: branch = await plugin.call('dGitProvider', 'currentbranch')
const currentBranch: branch = await dgitPlugin.call('dgitApi', 'currentbranch')
if (!currentBranch) {
if (!name || !email) {
@ -162,22 +164,22 @@ export const createWorkspace = async (
// commit the template as first commit
plugin.call('notification', 'toast', 'Creating initial git commit ...')
await plugin.call('dGitProvider', 'init')
await dgitPlugin.call('dgitApi', 'init')
if (!isEmpty) await loadWorkspacePreset(workspaceTemplateName, opts)
const status = await plugin.call('dGitProvider', 'status', { ref: 'HEAD' })
const status = await dgitPlugin.call('dgitApi', 'status', { ref: 'HEAD' })
Promise.all(
status.map(([filepath, , worktreeStatus]) =>
worktreeStatus
? plugin.call('dGitProvider', 'add', {
? dgitPlugin.call('dgitApi', 'add', {
filepath: removeSlash(filepath),
})
: plugin.call('dGitProvider', 'rm', {
: dgitPlugin.call('dgitApi', 'rm', {
filepath: removeSlash(filepath),
})
)
).then(async () => {
await plugin.call('dGitProvider', 'commit', {
await dgitPlugin.call('dgitApi', 'commit', {
author: {
name,
email,
@ -225,7 +227,7 @@ export const createWorkspaceTemplate = async (workspaceName: string, template: W
if ((await workspaceExists(workspaceName)) && template === 'remixDefault') throw new Error('workspace already exists')
else if (metadata && metadata.type === 'git') {
dispatch(cloneRepositoryRequest())
await plugin.call('dGitProvider', 'clone', { url: metadata.url, branch: metadata.branch }, workspaceName)
await dgitPlugin.call('dgitApi', 'clone', { url: metadata.url, branch: metadata.branch, workspaceName: workspaceName })
dispatch(cloneRepositorySuccess())
} else {
const workspaceProvider = plugin.fileProviders.workspace
@ -649,11 +651,11 @@ export const getWorkspaces = async (): Promise<{ name: string; isGitRepo: boolea
export const cloneRepository = async (url: string) => {
const config = plugin.registry.get('config').api
const token = config.get('settings/gist-access-token')
const repoConfig = { url, token }
const repoConfig: cloneInputType = { url, token }
if (plugin.registry.get('platform').api.isDesktop()) {
try {
await plugin.call('dGitProvider', 'clone', repoConfig)
await dgitPlugin.call('dgitApi', 'clone', repoConfig)
} catch (e) {
console.log(e)
plugin.call('notification', 'alert', {
@ -666,7 +668,7 @@ export const cloneRepository = async (url: string) => {
const repoName = await getRepositoryTitle(url)
await createWorkspace(repoName, 'blank', null, true, null, true, false)
const promise = plugin.call('dGitProvider', 'clone', repoConfig, repoName, true)
const promise = dgitPlugin.call('dgitApi', 'clone', {...repoConfig, workspaceExists: true, workspaceName: repoName})
dispatch(cloneRepositoryRequest())
promise
@ -715,8 +717,8 @@ export const checkGit = async () => {
dispatch(setCurrentWorkspaceIsGitRepo(isGitRepo))
dispatch(setCurrentWorkspaceHasGitSubmodules(hasGitSubmodule))
await refreshBranches()
const currentBranch: branch = await plugin.call('dGitProvider', 'currentbranch')
dispatch(setCurrentWorkspaceCurrentBranch(currentBranch.name))
const currentBranch: branch = await dgitPlugin.call('dgitApi', 'currentbranch')
dispatch(setCurrentWorkspaceCurrentBranch(currentBranch))
} catch (e) {}
}
@ -744,7 +746,7 @@ export const getGitRepoBranches = async (workspacePath: string) => {
fs: window.remixFileSystemCallback,
dir: addSlash(workspacePath),
}
const branches: { remote: any; name: string }[] = await plugin.call('dGitProvider', 'branches', { ...gitConfig })
const branches: { remote: any; name: string }[] = await dgitPlugin.call('dgitApi', 'branches', { ...gitConfig })
return branches
}
@ -753,8 +755,8 @@ export const getGitRepoCurrentBranch = async (workspaceName: string) => {
fs: window.remixFileSystemCallback,
dir: addSlash(workspaceName),
}
const currentBranch: branch = await plugin.call('dGitProvider', 'currentbranch', { ...gitConfig })
return currentBranch && currentBranch.name
const currentBranch: branch = await dgitPlugin.call('dgitApi', 'currentbranch', { ...gitConfig })
return currentBranch
}
export const showAllBranches = async () => {
@ -782,7 +784,7 @@ const refreshBranches = async () => {
dispatch(setCurrentWorkspaceBranches(branches))
}
export const switchBranch = async (branch: string) => {
export const switchBranch = async (branch: branch) => {
await plugin.call('fileManager', 'closeAllFiles')
const localChanges = await hasLocalChanges()
@ -798,7 +800,7 @@ export const switchBranch = async (branch: string) => {
okFn: async () => {
dispatch(cloneRepositoryRequest())
plugin
.call('dGitProvider', 'checkout', { ref: branch, force: true }, false)
.call('dgitApi', 'checkout', { ref: branch, force: true }, false)
.then(async () => {
await fetchWorkspaceDirectory(ROOT_PATH)
dispatch(setCurrentWorkspaceCurrentBranch(branch))
@ -816,7 +818,7 @@ export const switchBranch = async (branch: string) => {
} else {
dispatch(cloneRepositoryRequest())
plugin
.call('dGitProvider', 'checkout', { ref: branch, force: true }, false)
.call('dgitApi', 'checkout', { ref: branch, force: true }, false)
.then(async () => {
await fetchWorkspaceDirectory(ROOT_PATH)
dispatch(setCurrentWorkspaceCurrentBranch(branch))
@ -829,13 +831,16 @@ export const switchBranch = async (branch: string) => {
}
export const createNewBranch = async (branch: string) => {
const promise = plugin.call('dGitProvider', 'branch', { ref: branch, checkout: true }, false)
const promise = dgitPlugin.call('dgitApi', 'branch', { ref: branch, checkout: true, refresh: false })
dispatch(cloneRepositoryRequest())
promise
.then(async () => {
await fetchWorkspaceDirectory(ROOT_PATH)
dispatch(setCurrentWorkspaceCurrentBranch(branch))
dispatch(setCurrentWorkspaceCurrentBranch({
remote: null,
name: branch,
}))
const workspacesPath = plugin.fileProviders.workspace.workspacesPath
const workspaceName = plugin.fileProviders.workspace.workspace
const branches = await getGitRepoBranches(workspacesPath + '/' + workspaceName)
@ -881,11 +886,11 @@ export const updateGitSubmodules = async () => {
const config = plugin.registry.get('config').api
const token = config.get('settings/gist-access-token')
const repoConfig = { token }
await plugin.call('dGitProvider', 'updateSubmodules', repoConfig)
await dgitPlugin.call('dgitApi', 'updateSubmodules', repoConfig)
dispatch(cloneRepositorySuccess())
}
export const checkoutRemoteBranch = async (branch: string, remote: string) => {
export const checkoutRemoteBranch = async (branch: branch) => {
const localChanges = await hasLocalChanges()
if (Array.isArray(localChanges) && localChanges.length > 0) {
@ -900,7 +905,10 @@ export const checkoutRemoteBranch = async (branch: string, remote: string) => {
okFn: async () => {
dispatch(cloneRepositoryRequest())
plugin
.call('dGitProvider', 'checkout', { ref: branch, remote, force: true }, false)
.call('dgitApi', 'checkout', {
ref: branch,
force: true,
})
.then(async () => {
await fetchWorkspaceDirectory(ROOT_PATH)
dispatch(setCurrentWorkspaceCurrentBranch(branch))
@ -923,7 +931,10 @@ export const checkoutRemoteBranch = async (branch: string, remote: string) => {
} else {
dispatch(cloneRepositoryRequest())
plugin
.call('dGitProvider', 'checkout', { ref: branch, remote, force: true }, false)
.call('dgitApi', 'checkout',{
ref: branch,
force: true,
}, false)
.then(async () => {
await fetchWorkspaceDirectory(ROOT_PATH)
dispatch(setCurrentWorkspaceCurrentBranch(branch))
@ -956,7 +967,7 @@ export const removeRecentElectronFolder = async (path: string) => {
}
export const hasLocalChanges = async () => {
const filesStatus = await plugin.call('dGitProvider', 'status')
const filesStatus = await dgitPlugin.call('dgitApi', 'status')
const uncommittedFiles = getUncommittedFiles(filesStatus)
return uncommittedFiles

@ -1,3 +1,4 @@
import { branch } from '@remix-ui/git'
import { customAction } from '@remixproject/plugin-api'
import { createContext, SyntheticEvent } from 'react'
import { BrowserState } from '../reducers/workspace'
@ -40,9 +41,9 @@ export const FileSystemContext = createContext<{
dispatchMoveFile: (src: string, dest: string) => Promise<void>,
dispatchMoveFolder: (src: string, dest: string) => Promise<void>,
dispatchShowAllBranches: () => Promise<void>,
dispatchSwitchToBranch: (branch: string) => Promise<void>,
dispatchCreateNewBranch: (branch: string) => Promise<void>,
dispatchCheckoutRemoteBranch: (branch: string, remote: string) => Promise<void>,
dispatchSwitchToBranch: (branch: branch) => Promise<void>,
dispatchCreateNewBranch: (name: string) => Promise<void>,
dispatchCheckoutRemoteBranch: (branch: branch) => Promise<void>,
dispatchCreateSolidityGithubAction: () => Promise<void>,
dispatchCreateTsSolGithubAction: () => Promise<void>,
dispatchCreateSlitherGithubAction: () => Promise<void>

@ -5,6 +5,7 @@ import {Toaster} from '@remix-ui/toaster' // eslint-disable-line
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { FileSystemContext } from '../contexts'
import { browserReducer, browserInitialState } from '../reducers/workspace'
import { branch } from '@remix-ui/git'
import {
initWorkspace,
fetchDirectory,
@ -209,7 +210,7 @@ export const FileSystemProvider = (props: WorkspaceProps) => {
await showAllBranches()
}
const dispatchSwitchToBranch = async (branch: string) => {
const dispatchSwitchToBranch = async (branch: branch) => {
await switchBranch(branch)
}
@ -217,8 +218,8 @@ export const FileSystemProvider = (props: WorkspaceProps) => {
await createNewBranch(branch)
}
const dispatchCheckoutRemoteBranch = async (branch: string, remote: string) => {
await checkoutRemoteBranch(branch, remote)
const dispatchCheckoutRemoteBranch = async (branch: branch) => {
await checkoutRemoteBranch(branch)
}
const dispatchCreateSolidityGithubAction = async () => {

@ -5,6 +5,7 @@ import { fileDecoration } from '@remix-ui/file-decorators'
import { ROOT_PATH } from '../utils/constants'
import isElectron from 'is-electron'
import { fileKeySort } from '../utils'
import { branch } from '@remix-ui/git'
export interface BrowserState {
browser: {
currentWorkspace: string
@ -12,11 +13,8 @@ export interface BrowserState {
name: string
isGitRepo: boolean
hasGitSubmodules?: boolean
branches?: {
remote: any
name: string
}[]
currentBranch?: string
branches?: branch[]
currentBranch?: branch
isGist: string
}[]
files: {[x: string]: Record<string, FileType>}

@ -16,6 +16,7 @@ import { customAction } from '@remixproject/plugin-api'
import { appPlatformTypes, platformContext } from '@remix-ui/app'
import { ElectronMenu } from './components/electron-menu'
import { ElectronWorkspaceName } from './components/electron-workspace-name'
import { branch } from '@remix-ui/git'
const _paq = (window._paq = window._paq || [])
@ -693,13 +694,14 @@ export function Workspace() {
global.dispatchShowAllBranches()
}
const switchToBranch = async (branch: {remote: string; name: string}) => {
const switchToBranch = async (branch: branch) => {
console.log('switchToBranch', branch)
try {
if (branch.remote) {
await global.dispatchCheckoutRemoteBranch(branch.name, branch.remote)
await global.dispatchCheckoutRemoteBranch(branch)
_paq.push(['trackEvent', 'Workspace', 'GIT', 'checkout_remote_branch'])
} else {
await global.dispatchSwitchToBranch(branch.name)
await global.dispatchSwitchToBranch(branch)
_paq.push(['trackEvent', 'Workspace', 'GIT', 'switch_to_exisiting_branch'])
}
} catch (e) {
@ -1259,7 +1261,7 @@ export function Workspace() {
}}
title={intl.formatMessage({ id: `filePanel.switchToBranch${branch.remote ? 'Title1' : 'Title2'}` })}
>
<div data-id={`workspaceGit-${branch.remote ? `${branch.remote}/${branch.name}` : branch.name}`}>
<div data-id={`workspaceGit-${branch.remote ? `${branch.remote.name}/${branch.name}` : branch.name}`}>
{currentBranch === branch.name && !branch.remote ? (
<span>
&#10003; <i className="far fa-code-branch"></i>
@ -1268,7 +1270,7 @@ export function Workspace() {
) : (
<span className="pl-3">
<i className={`far ${branch.remote ? 'fa-cloud' : 'fa-code-branch'}`}></i>
<span className="pl-1">{branch.remote ? `${branch.remote}/${branch.name}` : branch.name}</span>
<span className="pl-1">{branch.remote ? `${branch.remote.name}/${branch.name}` : branch.name}</span>
</span>
)}
</div>

@ -6,6 +6,7 @@ import { RemixAppManager } from 'libs/remix-ui/plugin-manager/src/types'
import { ViewPlugin } from '@remixproject/engine-web'
import { appPlatformTypes } from '@remix-ui/app'
import { Placement } from 'react-bootstrap/esm/Overlay'
import { branch } from '@remix-ui/git'
export type action = { name: string, type?: Array<WorkspaceElement>, path?: string[], extension?: string[], pattern?: string[], id: string, multiselect: boolean, label: string, sticky?: boolean, group: number, platform?: appPlatformTypes }
export interface JSONStandardInput {
@ -51,7 +52,7 @@ export type WorkspaceMetadata = {
name: string
isGitRepo: boolean
hasGitSubmodules?: boolean
branches?: {remote: any; name: string}[]
branches?: branch[]
currentBranch?: string
isGist: string
}
@ -244,14 +245,14 @@ export interface ActionPayloadTypes {
SET_CURRENT_WORKSPACE: {
name: string
isGitRepo: boolean
branches?: {remote: string | undefined; name: string}[]
currentBranch?: string
branches?: branch[]
currentBranch?: branch
},
SET_WORKSPACES: {
name: string
isGitRepo: boolean
branches?: {remote: string | undefined; name: string}[]
currentBranch?: string
branches?: branch[]
currentBranch?: branch
}[],
SET_MODE: 'browser' | 'localhost',
FETCH_DIRECTORY_REQUEST: undefined | null,
@ -293,8 +294,8 @@ export interface ActionPayloadTypes {
CREATE_WORKSPACE_SUCCESS: {
name: string
isGitRepo: boolean
branches?: { remote: string | undefined; name: string }[]
currentBranch?: string
branches?: branch[]
currentBranch?: branch
},
CREATE_WORKSPACE_ERROR: string,
RENAME_WORKSPACE: { oldName: string; workspaceName: string },
@ -317,8 +318,8 @@ export interface ActionPayloadTypes {
CLONE_REPOSITORY_FAILED: undefined | null,
FS_INITIALIZATION_COMPLETED: undefined | null,
SET_FILE_DECORATION_SUCCESS: fileDecoration[],
SET_CURRENT_WORKSPACE_BRANCHES: { remote: string | undefined; name: string }[],
SET_CURRENT_WORKSPACE_CURRENT_BRANCH: string,
SET_CURRENT_WORKSPACE_BRANCHES: branch[],
SET_CURRENT_WORKSPACE_CURRENT_BRANCH: branch,
SET_CURRENT_WORKSPACE_IS_GITREPO: boolean,
SET_CURRENT_WORKSPACE_HAS_GIT_SUBMODULES: boolean,
SET_GIT_CONFIG: {

Loading…
Cancel
Save