github integration

pull/1585/head
filip mertens 3 years ago
parent 7c297a31ac
commit 1387251797
  1. 147
      apps/remix-ide/src/app/files/dgitProvider.js
  2. 6
      apps/remix-ide/src/remixAppManager.js

@ -8,6 +8,7 @@ import IpfsHttpClient from 'ipfs-http-client'
import { import {
saveAs saveAs
} from 'file-saver' } from 'file-saver'
import http from 'isomorphic-git/http/web'
const JSZip = require('jszip') const JSZip = require('jszip')
const path = require('path') const path = require('path')
@ -20,7 +21,7 @@ const profile = {
description: '', description: '',
icon: 'assets/img/fileManager.webp', icon: 'assets/img/fileManager.webp',
version: '0.0.1', version: '0.0.1',
methods: ['init', 'status', 'log', 'commit', 'add', 'remove', 'rm', 'lsfiles', 'readblob', 'resolveref', 'branches', 'branch', 'checkout', 'currentbranch', 'push', 'pin', 'pull', 'pinList', 'unPin', 'setIpfsConfig', 'zip', 'setItem', 'getItem'], methods: ['init', 'localStorageUsed', 'addremote', 'delremote', 'remotes', 'fetch', 'clone', 'export', 'import', 'status', 'log', 'commit', 'add', 'remove', 'rm', 'lsfiles', 'readblob', 'resolveref', 'branches', 'branch', 'checkout', 'currentbranch', 'push', 'pin', 'pull', 'pinList', 'unPin', 'setIpfsConfig', 'zip', 'setItem', 'getItem'],
kind: 'file-system' kind: 'file-system'
} }
class DGitProvider extends Plugin { class DGitProvider extends Plugin {
@ -55,10 +56,24 @@ class DGitProvider extends Plugin {
} }
} }
async init () { async parseInput (input) {
return {
corsProxy: 'http://static.220.14.12.49.clients.your-server.de:3001',
http,
onAuth: url => {
const auth = {
username: input.token,
password: ''
}
return auth
}
}
}
async init (input) {
await git.init({ await git.init({
...await this.getGitConfig(), ...await this.getGitConfig(),
defaultBranch: 'main' defaultBranch: (input && input.branch) || 'main'
}) })
} }
@ -91,7 +106,7 @@ class DGitProvider extends Plugin {
...await this.getGitConfig(), ...await this.getGitConfig(),
...cmd ...cmd
}) })
this.call('fileManager', 'refresh') await this.call('fileManager', 'refresh')
} }
async log (cmd) { async log (cmd) {
@ -102,6 +117,15 @@ class DGitProvider extends Plugin {
return status return status
} }
async remotes () {
let remotes = []
try {
remotes = await git.listRemotes({ ...await this.getGitConfig() })
} catch (e) {
}
return remotes
}
async branch (cmd) { async branch (cmd) {
const status = await git.branch({ const status = await git.branch({
...await this.getGitConfig(), ...await this.getGitConfig(),
@ -118,10 +142,18 @@ class DGitProvider extends Plugin {
return name return name
} }
async branches () { async branches (input) {
const branches = await git.listBranches({ const cmd = {
...await this.getGitConfig() ...await this.getGitConfig()
}) }
const remotes = await this.remotes()
let branches = []
branches = (await git.listBranches(cmd)).map((branch) => { return { remote: undefined, name: branch } })
for (const remote of remotes) {
cmd.remote = remote.remote
const remotebranches = (await git.listBranches(cmd)).map((branch) => { return { remote: remote.remote, name: branch } })
branches = [...branches, ...remotebranches]
}
return branches return branches
} }
@ -133,7 +165,7 @@ class DGitProvider extends Plugin {
...cmd ...cmd
}) })
return sha return sha
} catch (e) {} } catch (e) { }
} }
async lsfiles (cmd) { async lsfiles (cmd) {
@ -177,7 +209,94 @@ class DGitProvider extends Plugin {
} }
} }
async push () { async addremote (input) {
await git.addRemote({ ...await this.getGitConfig(), url: input.url, remote: input.remote })
}
async delremote (input) {
await git.deleteRemote({ ...await this.getGitConfig(), remote: input.remote })
}
async localStorageUsed () {
return this.calculateLocalStorage()
}
async clone (input) {
const permission = await this.askUserPermission('clone', 'Import multiple files into your workspaces.')
if (!permission) return false
if (this.calculateLocalStorage() > 10000) throw new Error('Local browser storage is full.')
await this.call('filePanel', 'createWorkspace', `workspace_${Date.now()}`, false)
const cmd = {
url: input.url,
singleBranch: input.singleBranch,
ref: input.branch,
depth: input.depth || 10,
...await this.parseInput(input),
...await this.getGitConfig()
}
console.log(cmd)
const result = await git.clone(cmd)
await this.call('fileManager', 'refresh')
return result
}
async push (input) {
console.log('push')
const cmd = {
force: input.force,
ref: input.ref,
remoteRef: input.remoteRef,
remote: input.remote,
author: {
name: input.name,
email: input.email
},
...await this.parseInput(input),
...await this.getGitConfig()
}
console.log(cmd)
return await git.push(cmd)
}
async pull (input) {
const cmd = {
ref: input.ref,
remoteRef: input.remoteRef,
author: {
name: input.name,
email: input.email
},
remote: input.remote,
...await this.parseInput(input),
...await this.getGitConfig()
}
console.log(cmd)
const result = await git.pull(cmd)
await this.call('fileManager', 'refresh')
return result
}
async fetch (input) {
const cmd = {
ref: input.ref,
remoteRef: input.remoteRef,
author: {
name: input.name,
email: input.email
},
remote: input.remote,
...await this.parseInput(input),
...await this.getGitConfig()
}
console.log(cmd)
const result = await git.fetch(cmd)
await this.call('fileManager', 'refresh')
return result
}
async export () {
if (!this.checkIpfsConfig()) return false if (!this.checkIpfsConfig()) return false
const workspace = await this.call('filePanel', 'getCurrentWorkspace') const workspace = await this.call('filePanel', 'getCurrentWorkspace')
const files = await this.getDirectory('/') const files = await this.getDirectory('/')
@ -312,10 +431,10 @@ class DGitProvider extends Plugin {
const dir = path.dirname(file.path) const dir = path.dirname(file.path)
try { try {
this.createDirectories(`${workspace.absolutePath}/${dir}`) this.createDirectories(`${workspace.absolutePath}/${dir}`)
} catch (e) {} } catch (e) { }
try { try {
window.remixFileSystem.writeFileSync(`${workspace.absolutePath}/${file.path}`, Buffer.concat(content) || new Uint8Array()) window.remixFileSystem.writeFileSync(`${workspace.absolutePath}/${file.path}`, Buffer.concat(content) || new Uint8Array())
} catch (e) {} } catch (e) { }
} }
} catch (e) { } catch (e) {
} }
@ -336,8 +455,8 @@ class DGitProvider extends Plugin {
return (_lsTotal / 1024).toFixed(2) return (_lsTotal / 1024).toFixed(2)
} }
async pull (cmd) { async import (cmd) {
const permission = await this.askUserPermission('pull', 'Import multiple files into your workspaces.') const permission = await this.askUserPermission('import', 'Import multiple files into your workspaces.')
if (!permission) return false if (!permission) return false
if (this.calculateLocalStorage() > 10000) throw new Error('Local browser storage is full.') if (this.calculateLocalStorage() > 10000) throw new Error('Local browser storage is full.')
const cid = cmd.cid const cid = cmd.cid
@ -392,7 +511,7 @@ class DGitProvider extends Plugin {
const finalPath = previouspath + '/' + directories[i] const finalPath = previouspath + '/' + directories[i]
try { try {
window.remixFileSystem.mkdirSync(finalPath) window.remixFileSystem.mkdirSync(finalPath)
} catch (e) {} } catch (e) { }
} }
} }

@ -117,6 +117,12 @@ export class RemixAppManager extends PluginManager {
} }
return true return true
}) })
// temp dgit hack
for (const profile of plugins) {
if (profile.name === 'dgit') {
profile.url = 'https://dgit3remix.web.app/'
}
}
localStorage.setItem('plugins-directory', JSON.stringify(plugins)) localStorage.setItem('plugins-directory', JSON.stringify(plugins))
} catch (e) { } catch (e) {
console.log('getting plugins list from localstorage...') console.log('getting plugins list from localstorage...')

Loading…
Cancel
Save