Skip to content

Commit

Permalink
moved git functions to separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
PhotoNomad0 committed Nov 4, 2024
1 parent 9f063bd commit eaeaa1d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
18 changes: 15 additions & 3 deletions src/test/dcs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
import {
bibleCheckingTopic,
downloadPublicRepoFromBranch,
downloadRepoFromDCS,
getCheckingReposForOwner,
getCheckingOwners,
getOwnersFromRepoList,
Expand All @@ -30,9 +31,14 @@ import {
} from "../utilities/network";
import {
addTopicToRepo,
createCheckingRepository, createRepoBranch,
createCheckingRepository,
createRepoBranch,
getChangedFiles,
getCheckingRepos, getOwners, getReposForOwner, getRepoTree, searchCatalogByTopic,
getCheckingRepos,
getOwners,
getReposForOwner,
getRepoTree,
searchCatalogByTopic,
uploadRepoFileFromPath,
} from "../utilities/gitUtils";
// import * as myExtension from '../extension';
Expand Down Expand Up @@ -129,13 +135,19 @@ suite.skip('Repo Tests', async ()=> {
// assert.ok(results.repos?.length)
})

test('Test downloadRepo', async () => {
test('Test downloadPublicRepoFromBranch', async () => {
const branch = 'master'
const repo = env.REPO || ''
const results = await downloadPublicRepoFromBranch(testRepoPath, server, owner, repo, branch)
assert.ok(!results.error)
})

test('Test downloadRepoFromDCS', async () => {
const repo = 'pigeon_ult_en_tit_checking'
const results = await downloadRepoFromDCS(server, owner, repo, true)
assert.ok(!results.error)
})

test('Test addTopicToRepo', async () => {
const topic = bibleCheckingTopic
const repo = env.REPO || ''
Expand Down
38 changes: 35 additions & 3 deletions src/utilities/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@ import {
getBibleBookFolders,
getMetaData,
getRepoFileName,
projectsBasePath,
} from "./resourceUtils";
// @ts-ignore
import * as fs from "fs-extra";
import * as path from "path";
import { getAllFiles, getChecksum, getFilesOfType, getPatch, readJsonFile } from "./fileUtils";
import {
getAllFiles,
getChecksum,
getFilesOfType,
getPatch,
readJsonFile,
} from "./fileUtils";
import { GeneralObject, NestedObject, ResourcesObject } from "../../types";
import {
addTopicToRepo,
Expand Down Expand Up @@ -54,7 +61,6 @@ function sortAndRemoveDuplicates(strings: string[]): string[] {

// Convert the Set back to an array and sort it
const sortedStrings = Array.from(uniqueStrings).sort();

return sortedStrings;
}

Expand Down Expand Up @@ -255,9 +261,35 @@ async function updateFilesInBranch(localFiles: string[], localRepoPath: string,
return { changedFiles }
}

export async function downloadRepoFromDCS(server: string, owner: string, repo: string, backup = false): Promise<GeneralObject> {
const localRepoPath = path.join(projectsBasePath, repo)
if (fs.existsSync(localRepoPath)) {
if (!backup) {
return {
error: `local project already exists ${localRepoPath}`,
errorLocalProjectExists: true,
}
}

try {
const newFolder = localRepoPath + '.OLD_' + getTimeStamp()
fs.moveSync(localRepoPath, newFolder)
// TODO: move original project
} catch (e:any) {
return {
error: `Could not backup local project ${localRepoPath}`,
errorMessage: e.toString(),
errorRenameFailure: true,
}
}
}

return await downloadPublicRepoFromBranch(localRepoPath, server, owner, repo, 'master')
}

export async function downloadPublicRepoFromBranch(localRepoPath: string, server: string, owner: string, repo: string, branch: string): Promise<GeneralObject> {
fs.ensureDirSync(localRepoPath)
const treeResults = await getRepoTree(server, owner, repo, 'master');
const treeResults = await getRepoTree(server, owner, repo, branch);
if (treeResults.error) {
return treeResults
}
Expand Down

0 comments on commit eaeaa1d

Please sign in to comment.