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