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

Method getCommitItems

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

Source from the content-addressed store, hash-verified

633 }
634
635 async getCommitItems(
636 files: { path: string; newPath?: string }[],
637 branch: string,
638 hasSubfolders = true,
639 ) {
640 const items: CommitItem[] = await Promise.all(
641 files.map(async file => {
642 const [base64Content, fileExists] = await Promise.all([
643 result(file, 'toBase64', partial(this.toBase64, (file as DataFile).raw)),
644 this.isFileExists(file.path, branch),
645 ]);
646
647 let action = CommitAction.CREATE;
648 let path = trimStart(file.path, '/');
649 let oldPath = undefined;
650 if (fileExists) {
651 oldPath = file.newPath && path;
652 action =
653 file.newPath && file.newPath !== oldPath ? CommitAction.MOVE : CommitAction.UPDATE;
654 path = file.newPath ? trimStart(file.newPath, '/') : path;
655 }
656
657 return {
658 action,
659 base64Content,
660 path,
661 oldPath,
662 };
663 }),
664 );
665
666 // Move children if subfolders is true (legacy/default behavior)
667 if (hasSubfolders) {
668 for (const item of items.filter(i => i.oldPath && i.action === CommitAction.MOVE)) {
669 const sourceDir = dirname(item.oldPath as string);
670 const destDir = dirname(item.path);
671 const children = await this.listAllFiles(sourceDir, true, branch);
672 children
673 .filter(f => f.path !== item.oldPath)
674 .forEach(file => {
675 items.push({
676 action: CommitAction.MOVE,
677 path: file.path.replace(sourceDir, destDir),
678 oldPath: file.path,
679 });
680 });
681 }
682 }
683
684 return items;
685 }
686
687 async persistFiles(dataFiles: DataFile[], mediaFiles: AssetProxy[], options: PersistOptions) {
688 const files = [...dataFiles, ...mediaFiles];

Callers 2

persistFilesMethod · 0.95
editorialWorkflowGitMethod · 0.95

Calls 6

isFileExistsMethod · 0.95
partialFunction · 0.85
mapMethod · 0.80
filterMethod · 0.80
replaceMethod · 0.80
listAllFilesMethod · 0.45

Tested by

no test coverage detected