MCPcopy Create free account
hub / github.com/decaporg/decap-cms / getChangeFileOperations

Method getChangeFileOperations

packages/decap-cms-backend-gitea/src/API.ts:394–426  ·  view source on GitHub ↗
(files: { path: string; newPath?: string }[], branch: string)

Source from the content-addressed store, hash-verified

392 }
393
394 async getChangeFileOperations(files: { path: string; newPath?: string }[], branch: string) {
395 const items: ChangeFileOperation[] = await Promise.all(
396 files.map(async file => {
397 const content = await result(
398 file,
399 'toBase64',
400 partial(this.toBase64, (file as DataFile).raw),
401 );
402 let sha;
403 let operation;
404 let from_path;
405 let path = trimStart(file.path, '/');
406 try {
407 sha = await this.getFileSha(file.path, { branch });
408 operation = FileOperation.UPDATE;
409 from_path = file.newPath && path;
410 path = file.newPath ? trimStart(file.newPath, '/') : path;
411 } catch {
412 sha = undefined;
413 operation = FileOperation.CREATE;
414 }
415
416 return {
417 operation,
418 content,
419 path,
420 from_path,
421 sha,
422 } as ChangeFileOperation;
423 }),
424 );
425 return items;
426 }
427
428 async getFileSha(path: string, { repoURL = this.repoURL, branch = this.branch } = {}) {
429 /**

Callers 1

persistFilesMethod · 0.95

Calls 3

getFileShaMethod · 0.95
partialFunction · 0.85
mapMethod · 0.80

Tested by

no test coverage detected