@ -1,11 +1,11 @@
import { ReadBlobResult , ReadCommitResult } from "isomorphic-git" ;
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 { 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 { disableCallBacks , enableCallBacks } from "./listeners" ;
import { ModalTypes } from "@remix-ui/app" ;
import { setFileDecorators } from "./pluginActions" ;
import { sendToMatomo , se tFileDecorators } from "./pluginActions" ;
import { Plugin } from "@remixproject/engine" ;
import { CustomRemixApi } from "@remix-api" ;
@ -24,27 +24,6 @@ export const fileStatuses = [
[ "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 ) = > {
return {
matrix : x.shift ( ) . split ( "," ) ,
@ -59,12 +38,8 @@ export const setPlugin = (p: Plugin, dispatcher: React.Dispatch<gitActionDispatc
dispatch = dispatcher
}
const sendToMatomo = async ( event : gitEventTypes ) = > {
plugin . call ( 'matomo' , 'track' , [ 'trackEvent' , 'git' , event ] )
}
export const init = async ( ) = > {
sendToMatomo ( gitEventTypes . INIT )
await sendToMatomo ( gitMatomoEventTypes . INIT )
await plugin . call ( 'dgitApi' , "init" ) ;
await gitlog ( ) ;
await getBranches ( ) ;
@ -169,7 +144,7 @@ export const currentBranch = async () => {
}
export const createBranch = async ( name : string = "" ) = > {
sendToMatomo ( gitEventTypes . CREATEBRANCH )
await sendToMatomo ( gitMatomo EventTypes . CREATEBRANCH )
dispatch ( setLoading ( true ) )
if ( name ) {
await plugin . call ( 'dgitApi' , 'branch' , { ref : name , force : true , checkout : true } ) ;
@ -200,7 +175,7 @@ const settingsWarning = async () => {
export const commit = async ( message : string = "" ) = > {
sendToMatomo ( gitEventTypes . COMMIT )
await sendToMatomo ( gitMatomo EventTypes . COMMIT )
try {
const credentials = await settingsWarning ( )
if ( ! credentials ) {
@ -228,7 +203,7 @@ export const commit = async (message: string = "") => {
}
export const addall = async ( files : fileStatusResult [ ] ) = > {
sendToMatomo ( gitEventTypes . ADD_ALL )
await sendToMatomo ( gitMatomo EventTypes . ADD_ALL )
try {
const filesToAdd = files
. filter ( f = > ! f . statusNames . includes ( 'deleted' ) )
@ -254,7 +229,7 @@ export const addall = async (files: fileStatusResult[]) => {
}
export const add = async ( filepath : addInput ) = > {
sendToMatomo ( gitEventTypes . ADD )
await sendToMatomo ( gitMatomo EventTypes . ADD )
try {
if ( typeof filepath . filepath === "string" ) {
filepath . filepath = removeSlash ( filepath . filepath )
@ -281,7 +256,7 @@ const getLastCommmit = async () => {
}
export const rm = async ( args : rmInput ) = > {
sendToMatomo ( gitEventTypes . RM )
await sendToMatomo ( gitMatomo EventTypes . RM )
await plugin . call ( 'dgitApi' , 'rm' , {
filepath : removeSlash ( args . filepath ) ,
} ) ;
@ -318,7 +293,7 @@ export const checkoutfile = async (filename: string) => {
}
export const checkout = async ( cmd : checkoutInput ) = > {
sendToMatomo ( gitMatomoEventTypes . CHECKOUT )
await disableCallBacks ( ) ;
await plugin . call ( 'fileManager' , 'closeAllFiles' )
try {
@ -332,7 +307,7 @@ export const checkout = async (cmd: checkoutInput) => {
export const clone = async ( input : cloneInputType ) = > {
sendToMatomo ( gitEventTypes . CLONE )
await sendToMatomo ( gitMatomo EventTypes . CLONE )
dispatch ( setLoading ( true ) )
const urlParts = input . url . split ( "/" ) ;
const lastPart = urlParts [ urlParts . length - 1 ] ;
@ -361,7 +336,7 @@ export const clone = async (input: cloneInputType) => {
}
export const fetch = async ( input : fetchInputType ) = > {
sendToMatomo ( gitEventTypes . FETCH )
await sendToMatomo ( gitMatomo EventTypes . FETCH )
dispatch ( setLoading ( true ) )
await disableCallBacks ( )
try {
@ -379,7 +354,7 @@ export const fetch = async (input: fetchInputType) => {
}
export const pull = async ( input : pullInputType ) = > {
sendToMatomo ( gitEventTypes . PULL )
await sendToMatomo ( gitMatomo EventTypes . PULL )
dispatch ( setLoading ( true ) )
await disableCallBacks ( )
try {
@ -394,7 +369,7 @@ export const pull = async (input: pullInputType) => {
}
export const push = async ( input : pushInputType ) = > {
sendToMatomo ( gitEventTypes . PUSH )
await sendToMatomo ( gitMatomo EventTypes . PUSH )
dispatch ( setLoading ( true ) )
await disableCallBacks ( )
try {
@ -420,6 +395,7 @@ const parseError = async (e: any) => {
console . trace ( e )
// if message conttains 401 Unauthorized, show token warning
if ( e . message . includes ( '401' ) ) {
await sendToMatomo ( gitMatomoEventTypes . ERROR , [ '401' ] )
const result = await plugin . call ( 'notification' , 'modal' as any , {
title : 'The GitHub token may be missing or invalid' ,
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
else if ( e . message . includes ( '404' ) ) {
await sendToMatomo ( gitMatomoEventTypes . ERROR , [ '404' ] )
await plugin . call ( 'notification' , 'modal' as any , {
title : 'Repository not found' ,
message : 'Please check the URL and try again.' ,
@ -440,6 +417,7 @@ const parseError = async (e: any) => {
}
// if message contains 403 Forbidden
else if ( e . message . includes ( '403' ) ) {
await sendToMatomo ( gitMatomoEventTypes . ERROR , [ '403' ] )
await plugin . call ( 'notification' , 'modal' as any , {
title : 'The GitHub token may be missing or invalid' ,
message : 'Please check the GitHub token and try again. Error: 403 Forbidden' ,
@ -448,6 +426,7 @@ const parseError = async (e: any) => {
type : ModalTypes . confirm
} )
} else if ( e . toString ( ) . includes ( 'NotFoundError' ) && ! e . toString ( ) . includes ( 'fetch' ) ) {
await sendToMatomo ( gitMatomoEventTypes . ERROR , [ 'BRANCH NOT FOUND ON REMOTE' ] )
await plugin . call ( 'notification' , '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.' ,
@ -455,6 +434,7 @@ const parseError = async (e: any) => {
type : ModalTypes . alert
} )
} else {
await sendToMatomo ( gitMatomoEventTypes . ERROR , [ 'UKNOWN' ] )
await plugin . call ( 'notification' , 'alert' as any , {
title : 'Error' ,
message : e.message
@ -482,6 +462,7 @@ export const repositories = async () => {
}
} else {
await sendToMatomo ( gitMatomoEventTypes . ERROR , [ 'TOKEN ERROR' ] )
plugin . call ( 'notification' , 'alert' , {
id : 'github-token-error' ,
title : 'Error getting repositories' ,
@ -491,6 +472,7 @@ export const repositories = async () => {
}
} catch ( e ) {
console . log ( e )
await sendToMatomo ( gitMatomoEventTypes . ERROR , [ 'TOKEN ERROR' ] )
plugin . call ( 'notification' , 'alert' , {
id : 'github-token-error' ,
title : 'Error getting repositories' ,
@ -519,6 +501,7 @@ export const remoteBranches = async (owner: string, repo: string) => {
page ++
}
} else {
await sendToMatomo ( gitMatomoEventTypes . ERROR , [ 'TOKEN ERROR' ] )
plugin . call ( 'notification' , 'alert' , {
title : 'Error getting branches' ,
id : 'github-token-error' ,
@ -528,6 +511,7 @@ export const remoteBranches = async (owner: string, repo: string) => {
}
} catch ( e ) {
console . log ( e )
await sendToMatomo ( gitMatomoEventTypes . ERROR , [ 'TOKEN ERROR' ] )
plugin . call ( 'notification' , 'alert' , {
title : 'Error' ,
id : 'github-error' ,
@ -697,7 +681,7 @@ export const resolveRef = async (ref: string) => {
}
export const diff = async ( commitChange : commitChange ) = > {
sendToMatomo ( gitEventTypes . DIFF )
await sendToMatomo ( gitMatomo EventTypes . DIFF )
if ( ! commitChange . hashModified ) {
const newcontent = await plugin . call (
"fileManager" ,
@ -864,11 +848,12 @@ export const getBranchCommits = async (branch: branch, page: number) => {
}
export const setDefaultRemote = async ( remote : remote ) = > {
await sendToMatomo ( gitMatomoEventTypes . SETDEFAULTREMOTE )
dispatch ( setRemoteAsDefault ( remote ) )
}
export const addRemote = async ( remote : remote ) = > {
sendToMatomo ( gitEventTypes . ADDREMOTE )
await sendToMatomo ( gitMatomo EventTypes . ADDREMOTE )
try {
await plugin . call ( 'dgitApi' , 'addremote' , remote )
await getRemotes ( )
@ -883,7 +868,7 @@ export const addRemote = async (remote: remote) => {
}
export const removeRemote = async ( remote : remote ) = > {
sendToMatomo ( gitEventTypes . RMREMOTE )
await sendToMatomo ( gitMatomo EventTypes . RMREMOTE )
try {
await plugin . call ( 'dgitApi' , 'delremote' , remote )
await getRemotes ( )