@ -1,7 +1,7 @@
import { ViewPlugin } from "@remixproject/engine-web" ;
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 , 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 } from '../types' ;
import { GitHubUser , RateLimit , branch , commitChange , gitActionDispatch , statusMatrixType , gitState , branchDifference , remote , gitLog } from '../types' ;
import { removeSlash } from "../utils" ;
import { removeSlash } from "../utils" ;
import { disableCallBacks , enableCallBacks } from "./listeners" ;
import { disableCallBacks , enableCallBacks } from "./listeners" ;
@ -428,6 +428,7 @@ const tokenWarning = async () => {
const parseError = async ( e : any ) = > {
const parseError = async ( e : any ) = > {
console . log ( 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' , 'modal' , {
@ -458,6 +459,13 @@ const parseError = async (e: any) => {
cancelLabel : 'Close' ,
cancelLabel : 'Close' ,
type : ModalTypes . confirm
type : ModalTypes . confirm
} )
} )
} else if ( e . toString ( ) . includes ( 'NotFoundError' ) && ! e . toString ( ) . includes ( 'fetch' ) ) {
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.' ,
okLabel : 'OK' ,
type : ModalTypes . alert
} )
} else {
} else {
await plugin . call ( 'notification' , 'alert' , {
await plugin . call ( 'notification' , 'alert' , {
title : 'Error' ,
title : 'Error' ,
@ -736,7 +744,18 @@ export const diff = async (commitChange: commitChange) => {
export const getCommitChanges = async ( oid1 : string , oid2 : string , branch? : branch , remote? : remote ) = > {
export const getCommitChanges = async ( oid1 : string , oid2 : string , branch? : branch , remote? : remote ) = > {
console . log ( oid1 , oid2 , branch , remote )
console . log ( oid1 , oid2 , branch , remote )
try {
try {
// check if oid2 exists
const log = await plugin . call ( 'dGitProvider' , 'log' , {
ref : branch? branch . name : 'HEAD' ,
} )
if ( log ) {
const foundCommit = log . find ( ( commit : ReadCommitResult ) = > commit . oid === oid2 )
if ( ! foundCommit ) {
await fetch ( remote ? remote.remote : null , branch ? branch.name : null , null , 5 , true , true )
}
}
const result : commitChange [ ] = await plugin . call ( 'dGitProvider' , 'getCommitChanges' , oid1 , oid2 )
const result : commitChange [ ] = await plugin . call ( 'dGitProvider' , 'getCommitChanges' , oid1 , oid2 )
dispatch ( setCommitChanges ( result ) )
dispatch ( setCommitChanges ( result ) )
return result
return result
@ -762,6 +781,9 @@ export const fetchBranch = async (branch: branch, page: number) => {
if ( ! branch . remote || ! branch . remote . url ) return
if ( ! branch . remote || ! branch . remote . url ) return
const token = await tokenWarning ( ) ;
const token = await tokenWarning ( ) ;
console . log ( 'fetch' , branch )
console . log ( 'fetch' , branch )
if ( page == 1 ) {
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 ( 'dGitProvider' as any , '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' )
@ -825,7 +847,7 @@ export const getBranchCommits = async (branch: branch, page: number) => {
const commits : ReadCommitResult [ ] = await plugin . call ( 'dGitProvider' , 'log' , {
const commits : ReadCommitResult [ ] = await plugin . call ( 'dGitProvider' , 'log' , {
ref : branch.name ,
ref : branch.name ,
} )
} )
try {
const branchDifference : branchDifference = await plugin . call ( 'dGitProvider' , 'compareBranches' , {
const branchDifference : branchDifference = await plugin . call ( 'dGitProvider' , 'compareBranches' , {
branch ,
branch ,
remote : {
remote : {
@ -841,12 +863,15 @@ export const getBranchCommits = async (branch: branch, page: number) => {
{ remote : 'origin' , url : '' } ,
{ remote : 'origin' , url : '' } ,
branchDifference : branchDifference
branchDifference : branchDifference
} ) )
} ) )
} catch ( e ) {
}
dispatch ( setLocalBranchCommits ( { branch , commits } ) )
dispatch ( setLocalBranchCommits ( { branch , commits } ) )
} else {
} else {
await fetchBranch ( branch , page )
await fetchBranch ( branch , page )
}
}
} catch ( e ) {
} catch ( e ) {
console . log ( e )
console . trace ( e )
await fetchBranch ( branch , page )
await fetchBranch ( branch , page )
}
}
dispatch ( setLoading ( false ) )
dispatch ( setLoading ( false ) )