@ -1,11 +1,11 @@
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 , setRemoteBranches , setRemotes , setRepos , setUpstream , setLocalBranchCommits , setBranchDifferences , setRemoteAsDefault , setScopes , setLog , clearLog , setUserEmails , setCurrenHead , setStoragePayload , resetBranchDifferences } from "../state/gitpayload" ;
import { fileStatus , fileStatusMerge , setRemoteBranchCommits , resetRemoteBranchCommits , setBranches , setCanCommit , setCommitChanges , setCommits , setCurrentBranch , setGitHubUser , setLoading , setRemoteBranches , setRemotes , setRepos , setUpstream , setLocalBranchCommits , setBranchDifferences , setRemoteAsDefault , setScopes , setLog , clearLog , setUserEmails , setCurrenHead , setStoragePayload , resetBranchDifferences } from "../state/gitpayload" ;
import { GitHubUser , branch , commitChange , gitActionDispatch , statusMatrixType , gitState , branchDifference , remote , gitLog , fileStatusResult , customGitApi , IGitApi , cloneInputType , fetchInputType , pullInputType , pushInputType , checkoutInput , rmInput , addInput , repository , userEmails , storage } from '../types' ;
import { GitHubUser , branch , commitChange , gitActionDispatch , statusMatrixType , gitState , branchDifference , remote , gitLog , fileStatusResult , customGitApi , IGitApi , cloneInputType , fetchInputType , pullInputType , pushInputType , checkoutInput , rmInput , addInput , repository , userEmails , storage , gitMatomoEventTypes } from '../types' ;
import { removeSlash } from "../utils" ;
import { removeSlash } from "../utils" ;
import { disableCallBacks , enableCallBacks } from "./listeners" ;
import { disableCallBacks , enableCallBacks } from "./listeners" ;
import { ModalTypes } from "@remix-ui/app" ;
import { ModalTypes } from "@remix-ui/app" ;
import { setFileDecorators } from "./pluginActions" ;
import { sendToMatomo , se tFileDecorators } from "./pluginActions" ;
import { Plugin } from "@remixproject/engine" ;
import { Plugin } from "@remixproject/engine" ;
import { CustomRemixApi } from "@remix-api" ;
import { CustomRemixApi } from "@remix-api" ;
@ -24,27 +24,6 @@ export const fileStatuses = [
[ "unstaged,modified" , 1 , 2 , 0 ]
[ "unstaged,modified" , 1 , 2 , 0 ]
] ;
] ;
enum gitEventTypes {
INIT = 'INIT' ,
COMMIT = 'COMMIT' ,
PUSH = 'PUSH' ,
PULL = 'PULL' ,
ADDREMOTE = 'ADDREMOTE' ,
RMREMOTE = 'RMREMOTE' ,
CLONE = 'CLONE' ,
FETCH = 'FETCH' ,
ADD = 'ADD' ,
ADD_ALL = 'ADD_ALL' ,
RM = 'RM' ,
CHECKOUT = 'CHECKOUT' ,
DIFF = 'DIFF' ,
BRANCH = 'BRANCH' ,
CREATEBRANCH = 'CREATEBRANCH' ,
}
const statusmatrix : statusMatrixType [ ] = fileStatuses . map ( ( x : any ) = > {
const statusmatrix : statusMatrixType [ ] = fileStatuses . map ( ( x : any ) = > {
return {
return {
matrix : x.shift ( ) . split ( "," ) ,
matrix : x.shift ( ) . split ( "," ) ,
@ -59,12 +38,8 @@ export const setPlugin = (p: Plugin, dispatcher: React.Dispatch<gitActionDispatc
dispatch = dispatcher
dispatch = dispatcher
}
}
const sendToMatomo = async ( event : gitEventTypes ) = > {
plugin . call ( 'matomo' , 'track' , [ 'trackEvent' , 'git' , event ] )
}
export const init = async ( ) = > {
export const init = async ( ) = > {
sendToMatomo ( gitEventTypes . INIT )
await sendToMatomo ( gitMatomoEventTypes . INIT )
await plugin . call ( 'dgitApi' , "init" ) ;
await plugin . call ( 'dgitApi' , "init" ) ;
await gitlog ( ) ;
await gitlog ( ) ;
await getBranches ( ) ;
await getBranches ( ) ;
@ -169,7 +144,7 @@ export const currentBranch = async () => {
}
}
export const createBranch = async ( name : string = "" ) = > {
export const createBranch = async ( name : string = "" ) = > {
sendToMatomo ( gitEventTypes . CREATEBRANCH )
await sendToMatomo ( gitMatomo EventTypes . CREATEBRANCH )
dispatch ( setLoading ( true ) )
dispatch ( setLoading ( true ) )
if ( name ) {
if ( name ) {
await plugin . call ( 'dgitApi' , 'branch' , { ref : name , force : true , checkout : true } ) ;
await plugin . call ( 'dgitApi' , 'branch' , { ref : name , force : true , checkout : true } ) ;
@ -200,7 +175,7 @@ const settingsWarning = async () => {
export const commit = async ( message : string = "" ) = > {
export const commit = async ( message : string = "" ) = > {
sendToMatomo ( gitEventTypes . COMMIT )
await sendToMatomo ( gitMatomo EventTypes . COMMIT )
try {
try {
const credentials = await settingsWarning ( )
const credentials = await settingsWarning ( )
if ( ! credentials ) {
if ( ! credentials ) {
@ -228,7 +203,7 @@ export const commit = async (message: string = "") => {
}
}
export const addall = async ( files : fileStatusResult [ ] ) = > {
export const addall = async ( files : fileStatusResult [ ] ) = > {
sendToMatomo ( gitEventTypes . ADD_ALL )
await sendToMatomo ( gitMatomo EventTypes . ADD_ALL )
try {
try {
const filesToAdd = files
const filesToAdd = files
. filter ( f = > ! f . statusNames . includes ( 'deleted' ) )
. filter ( f = > ! f . statusNames . includes ( 'deleted' ) )
@ -254,7 +229,7 @@ export const addall = async (files: fileStatusResult[]) => {
}
}
export const add = async ( filepath : addInput ) = > {
export const add = async ( filepath : addInput ) = > {
sendToMatomo ( gitEventTypes . ADD )
await sendToMatomo ( gitMatomo EventTypes . ADD )
try {
try {
if ( typeof filepath . filepath === "string" ) {
if ( typeof filepath . filepath === "string" ) {
filepath . filepath = removeSlash ( filepath . filepath )
filepath . filepath = removeSlash ( filepath . filepath )
@ -281,7 +256,7 @@ const getLastCommmit = async () => {
}
}
export const rm = async ( args : rmInput ) = > {
export const rm = async ( args : rmInput ) = > {
sendToMatomo ( gitEventTypes . RM )
await sendToMatomo ( gitMatomo EventTypes . RM )
await plugin . call ( 'dgitApi' , 'rm' , {
await plugin . call ( 'dgitApi' , 'rm' , {
filepath : removeSlash ( args . filepath ) ,
filepath : removeSlash ( args . filepath ) ,
} ) ;
} ) ;
@ -318,7 +293,7 @@ export const checkoutfile = async (filename: string) => {
}
}
export const checkout = async ( cmd : checkoutInput ) = > {
export const checkout = async ( cmd : checkoutInput ) = > {
sendToMatomo ( gitMatomoEventTypes . CHECKOUT )
await disableCallBacks ( ) ;
await disableCallBacks ( ) ;
await plugin . call ( 'fileManager' , 'closeAllFiles' )
await plugin . call ( 'fileManager' , 'closeAllFiles' )
try {
try {
@ -332,7 +307,7 @@ export const checkout = async (cmd: checkoutInput) => {
export const clone = async ( input : cloneInputType ) = > {
export const clone = async ( input : cloneInputType ) = > {
sendToMatomo ( gitEventTypes . CLONE )
await sendToMatomo ( gitMatomo EventTypes . CLONE )
dispatch ( setLoading ( true ) )
dispatch ( setLoading ( true ) )
const urlParts = input . url . split ( "/" ) ;
const urlParts = input . url . split ( "/" ) ;
const lastPart = urlParts [ urlParts . length - 1 ] ;
const lastPart = urlParts [ urlParts . length - 1 ] ;
@ -361,7 +336,7 @@ export const clone = async (input: cloneInputType) => {
}
}
export const fetch = async ( input : fetchInputType ) = > {
export const fetch = async ( input : fetchInputType ) = > {
sendToMatomo ( gitEventTypes . FETCH )
await sendToMatomo ( gitMatomo EventTypes . FETCH )
dispatch ( setLoading ( true ) )
dispatch ( setLoading ( true ) )
await disableCallBacks ( )
await disableCallBacks ( )
try {
try {
@ -379,7 +354,7 @@ export const fetch = async (input: fetchInputType) => {
}
}
export const pull = async ( input : pullInputType ) = > {
export const pull = async ( input : pullInputType ) = > {
sendToMatomo ( gitEventTypes . PULL )
await sendToMatomo ( gitMatomo EventTypes . PULL )
dispatch ( setLoading ( true ) )
dispatch ( setLoading ( true ) )
await disableCallBacks ( )
await disableCallBacks ( )
try {
try {
@ -394,7 +369,7 @@ export const pull = async (input: pullInputType) => {
}
}
export const push = async ( input : pushInputType ) = > {
export const push = async ( input : pushInputType ) = > {
sendToMatomo ( gitEventTypes . PUSH )
await sendToMatomo ( gitMatomo EventTypes . PUSH )
dispatch ( setLoading ( true ) )
dispatch ( setLoading ( true ) )
await disableCallBacks ( )
await disableCallBacks ( )
try {
try {
@ -420,6 +395,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' ) ) {
await sendToMatomo ( gitMatomoEventTypes . ERROR , [ '401' ] )
const result = await plugin . call ( 'notification' , 'modal' as any , {
const result = await plugin . call ( 'notification' , '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' ,
@ -430,6 +406,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 sendToMatomo ( gitMatomoEventTypes . ERROR , [ '404' ] )
await plugin . call ( 'notification' , 'modal' as any , {
await plugin . call ( 'notification' , '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.' ,
@ -440,6 +417,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 sendToMatomo ( gitMatomoEventTypes . ERROR , [ '403' ] )
await plugin . call ( 'notification' , 'modal' as any , {
await plugin . call ( 'notification' , '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' ,
@ -448,6 +426,7 @@ 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 sendToMatomo ( gitMatomoEventTypes . ERROR , [ 'BRANCH NOT FOUND ON REMOTE' ] )
await plugin . call ( 'notification' , 'modal' , {
await plugin . call ( 'notification' , '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.' ,
@ -455,6 +434,7 @@ const parseError = async (e: any) => {
type : ModalTypes . alert
type : ModalTypes . alert
} )
} )
} else {
} else {
await sendToMatomo ( gitMatomoEventTypes . ERROR , [ 'UKNOWN' ] )
await plugin . call ( 'notification' , 'alert' as any , {
await plugin . call ( 'notification' , 'alert' as any , {
title : 'Error' ,
title : 'Error' ,
message : e.message
message : e.message
@ -482,6 +462,7 @@ export const repositories = async () => {
}
}
} else {
} else {
await sendToMatomo ( gitMatomoEventTypes . ERROR , [ 'TOKEN ERROR' ] )
plugin . call ( 'notification' , 'alert' , {
plugin . call ( 'notification' , 'alert' , {
id : 'github-token-error' ,
id : 'github-token-error' ,
title : 'Error getting repositories' ,
title : 'Error getting repositories' ,
@ -491,6 +472,7 @@ export const repositories = async () => {
}
}
} catch ( e ) {
} catch ( e ) {
console . log ( e )
console . log ( e )
await sendToMatomo ( gitMatomoEventTypes . ERROR , [ 'TOKEN ERROR' ] )
plugin . call ( 'notification' , 'alert' , {
plugin . call ( 'notification' , 'alert' , {
id : 'github-token-error' ,
id : 'github-token-error' ,
title : 'Error getting repositories' ,
title : 'Error getting repositories' ,
@ -519,6 +501,7 @@ export const remoteBranches = async (owner: string, repo: string) => {
page ++
page ++
}
}
} else {
} else {
await sendToMatomo ( gitMatomoEventTypes . ERROR , [ 'TOKEN ERROR' ] )
plugin . call ( 'notification' , 'alert' , {
plugin . call ( 'notification' , 'alert' , {
title : 'Error getting branches' ,
title : 'Error getting branches' ,
id : 'github-token-error' ,
id : 'github-token-error' ,
@ -528,6 +511,7 @@ export const remoteBranches = async (owner: string, repo: string) => {
}
}
} catch ( e ) {
} catch ( e ) {
console . log ( e )
console . log ( e )
await sendToMatomo ( gitMatomoEventTypes . ERROR , [ 'TOKEN ERROR' ] )
plugin . call ( 'notification' , 'alert' , {
plugin . call ( 'notification' , 'alert' , {
title : 'Error' ,
title : 'Error' ,
id : 'github-error' ,
id : 'github-error' ,
@ -697,7 +681,7 @@ export const resolveRef = async (ref: string) => {
}
}
export const diff = async ( commitChange : commitChange ) = > {
export const diff = async ( commitChange : commitChange ) = > {
sendToMatomo ( gitEventTypes . DIFF )
await sendToMatomo ( gitMatomo EventTypes . DIFF )
if ( ! commitChange . hashModified ) {
if ( ! commitChange . hashModified ) {
const newcontent = await plugin . call (
const newcontent = await plugin . call (
"fileManager" ,
"fileManager" ,
@ -864,11 +848,12 @@ export const getBranchCommits = async (branch: branch, page: number) => {
}
}
export const setDefaultRemote = async ( remote : remote ) = > {
export const setDefaultRemote = async ( remote : remote ) = > {
await sendToMatomo ( gitMatomoEventTypes . SETDEFAULTREMOTE )
dispatch ( setRemoteAsDefault ( remote ) )
dispatch ( setRemoteAsDefault ( remote ) )
}
}
export const addRemote = async ( remote : remote ) = > {
export const addRemote = async ( remote : remote ) = > {
sendToMatomo ( gitEventTypes . ADDREMOTE )
await sendToMatomo ( gitMatomo EventTypes . ADDREMOTE )
try {
try {
await plugin . call ( 'dgitApi' , 'addremote' , remote )
await plugin . call ( 'dgitApi' , 'addremote' , remote )
await getRemotes ( )
await getRemotes ( )
@ -883,7 +868,7 @@ export const addRemote = async (remote: remote) => {
}
}
export const removeRemote = async ( remote : remote ) = > {
export const removeRemote = async ( remote : remote ) = > {
sendToMatomo ( gitEventTypes . RMREMOTE )
await sendToMatomo ( gitMatomo EventTypes . RMREMOTE )
try {
try {
await plugin . call ( 'dgitApi' , 'delremote' , remote )
await plugin . call ( 'dgitApi' , 'delremote' , remote )
await getRemotes ( )
await getRemotes ( )