refactor: split git provider adapters
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { getGitBranch, readGitRemoteConfig } from './config'
|
||||
import { createGiteaProvider } from './providers/gitea'
|
||||
import { createGitHubProvider } from './providers/github'
|
||||
import type { GitProvider } from './types'
|
||||
import type { PushFile } from '@/lib/types'
|
||||
|
||||
function createGitProvider(): GitProvider {
|
||||
const remote = readGitRemoteConfig()
|
||||
const branch = getGitBranch()
|
||||
|
||||
if (remote.provider === 'github') {
|
||||
return createGitHubProvider(remote, branch)
|
||||
}
|
||||
|
||||
return createGiteaProvider(remote, branch)
|
||||
}
|
||||
|
||||
export async function getRemoteFolder(folderPath: string) {
|
||||
return createGitProvider().getRemoteFolder(folderPath)
|
||||
}
|
||||
|
||||
export async function pushAllToGit(files: PushFile[], deletePaths: string[], commitMessage: string) {
|
||||
return createGitProvider().pushFiles({ files, deletePaths, commitMessage })
|
||||
}
|
||||
Reference in New Issue
Block a user