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

Method getCommitItems

packages/decap-cms-backend-azure/src/API.ts:506–554  ·  view source on GitHub ↗
(
    files: { path: string; newPath?: string }[],
    branch: string,
    subfolders = true,
  )

Source from the content-addressed store, hash-verified

504 }
505
506 async getCommitItems(
507 files: { path: string; newPath?: string }[],
508 branch: string,
509 subfolders = true,
510 ) {
511 const items = await Promise.all(
512 files.map(async file => {
513 const [base64Content, fileExists] = await Promise.all([
514 result(file, 'toBase64', partial(this.toBase64, (file as DataFile).raw)),
515 this.isFileExists(file.path, branch),
516 ]);
517
518 const path = file.newPath || file.path;
519 const oldPath = file.path;
520 const renameOrEdit =
521 path !== oldPath ? AzureCommitChangeType.RENAME : AzureCommitChangeType.EDIT;
522
523 const action = fileExists ? renameOrEdit : AzureCommitChangeType.ADD;
524 return {
525 action,
526 base64Content,
527 path,
528 oldPath,
529 } as AzureCommitItem;
530 }),
531 );
532
533 // move children when subfolders is true (legacy/default behavior)
534 if (subfolders) {
535 for (const item of items.filter(
536 i => i.oldPath && i.action === AzureCommitChangeType.RENAME,
537 )) {
538 const sourceDir = dirname(item.oldPath as string);
539 const destDir = dirname(item.path);
540 const children = await this.listFiles(sourceDir, true, branch);
541 children
542 .filter(file => file.path !== item.oldPath)
543 .forEach(file => {
544 items.push({
545 action: AzureCommitChangeType.RENAME,
546 path: file.path.replace(sourceDir, destDir),
547 oldPath: file.path,
548 });
549 });
550 }
551 }
552
553 return items;
554 }
555
556 async persistFiles(dataFiles: DataFile[], mediaFiles: AssetProxy[], options: PersistOptions) {
557 const files = [...dataFiles, ...mediaFiles];

Callers 2

persistFilesMethod · 0.95
editorialWorkflowGitMethod · 0.95

Calls 6

isFileExistsMethod · 0.95
listFilesMethod · 0.95
partialFunction · 0.85
mapMethod · 0.80
filterMethod · 0.80
replaceMethod · 0.80

Tested by

no test coverage detected