-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
173 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ import fs from 'node:fs'; | |
import path from 'node:path'; | ||
import { randomUUID } from 'node:crypto'; | ||
|
||
import Sandbox from '@nyariv/sandboxjs'; | ||
|
||
import {Container, ContainerConfig, ContainerEngine} from '../../ContainerEngine.ts'; | ||
import {FileId} from '../../model/model.ts'; | ||
import {GoogleFolderContainer} from '../google_folder/GoogleFolderContainer.ts'; | ||
|
@@ -703,6 +705,70 @@ export class JobManagerContainer extends Container { | |
const gitScanner = new GitScanner(logger, transformedFileSystem.getRealPath(), '[email protected]'); | ||
await gitScanner.initialize(); | ||
|
||
const googleFileSystem = await this.filesService.getSubFileService(driveId, ''); | ||
const userConfigService = new UserConfigService(googleFileSystem); | ||
const userConfig = await userConfigService.load(); | ||
|
||
const contentFileService = await getContentFileService(transformedFileSystem, userConfigService); | ||
const markdownTreeProcessor = new MarkdownTreeProcessor(contentFileService); | ||
await markdownTreeProcessor.load(); | ||
|
||
if (userConfig.companion_files_rule) { | ||
gitScanner.setCompanionFileResolver(async (filePath: string) => { | ||
if (!filePath.endsWith('.md')) { | ||
return []; | ||
} | ||
|
||
let subdir = (userConfigService.config.transform_subdir || '') | ||
.replace(/^\//, '') | ||
.replace(/\/$/, ''); | ||
if (subdir.length > 0) { | ||
subdir += '/'; | ||
} | ||
|
||
filePath = filePath | ||
.replace(/^\//, '') | ||
.substring(subdir.length); | ||
|
||
const tuple = await markdownTreeProcessor.findByPath('/' + filePath); | ||
|
||
const treeItem = tuple[0]; | ||
if (!treeItem) { | ||
return []; | ||
} | ||
|
||
const retVal: Set<string> = new Set(); | ||
|
||
const sandbox = new Sandbox.default(); | ||
const exec = sandbox.compile('return ' + (userConfig.companion_files_rule || 'false')); | ||
|
||
await markdownTreeProcessor.walkTree((treeNode) => { | ||
const commit = { | ||
path: subdir + treeItem.path.replace(/^\//, ''), | ||
id: treeItem.id, | ||
fileName: treeItem.fileName, | ||
mimeType: treeItem.mimeType, | ||
redirectTo: treeItem.redirectTo | ||
}; | ||
const file = { | ||
path: subdir + treeNode.path.replace(/^\//, ''), | ||
id: treeNode.id, | ||
fileName: treeNode.fileName, | ||
mimeType: treeNode.mimeType, | ||
redirectTo: treeNode.redirectTo | ||
}; | ||
|
||
const result = exec({ commit, file }).run(); | ||
|
||
if (result) { | ||
retVal.add(file.path); | ||
} | ||
return false; | ||
}); | ||
return Array.from(retVal); | ||
}); | ||
} | ||
|
||
await gitScanner.commit(message, filePaths, user); | ||
|
||
await this.schedule(driveId, { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import {createTmpDir} from '../utils.ts'; | ||
import {GitScanner} from '../../src/git/GitScanner.ts'; | ||
import fs from 'node:fs'; | ||
import path from 'node:path'; | ||
|
||
import test from '../tester.ts'; | ||
import winston from 'winston'; | ||
import {instrumentLogger} from '../../src/utils/logger/logger.ts'; | ||
import Sandbox from '@nyariv/sandboxjs'; | ||
|
||
const COMMITER1 = { | ||
name: 'John', email: '[email protected]' | ||
}; | ||
|
||
const logger = winston.createLogger({ | ||
level: 'debug', | ||
defaultMeta: {}, | ||
transports: [ | ||
new winston.transports.Console() | ||
] | ||
}); | ||
instrumentLogger(logger); | ||
|
||
test('test single commit', async (t) => { | ||
t.timeout(5000); | ||
|
||
const localRepoDir: string = createTmpDir(); | ||
|
||
try { | ||
const scannerLocal = new GitScanner(logger, localRepoDir, COMMITER1.email); | ||
await scannerLocal.initialize(); | ||
|
||
fs.writeFileSync(path.join(scannerLocal.rootPath, 'test1.md'), 'test'); | ||
fs.writeFileSync(path.join(scannerLocal.rootPath, 'navigation.md'), 'nav'); | ||
fs.writeFileSync(path.join(scannerLocal.rootPath, 'toc.md'), 'toc'); | ||
|
||
{ | ||
const changes = await scannerLocal.changes(); | ||
t.is(changes.length, 4); | ||
} | ||
|
||
// console.log('Sandbox', Sandbox); | ||
const sandbox = new Sandbox.default(); | ||
const exec = sandbox.compileExpression('return (filePath.endsWith(".md") && filePath == "test1.md" && ["navigation.md", "toc.md"]) || []'); | ||
|
||
scannerLocal.setCompanionFileResolver((filePath: string) => { | ||
return exec({ filePath }).run(); | ||
}); | ||
|
||
await scannerLocal.commit('initial commit', ['.gitignore', 'test1.md'], COMMITER1); | ||
|
||
const changes = await scannerLocal.changes(); | ||
t.is(changes.length, 0); | ||
} finally { | ||
fs.rmSync(localRepoDir, { recursive: true, force: true }); | ||
} | ||
}); |