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

Method editorialWorkflowGit

packages/decap-cms-backend-github/src/API.ts:1043–1100  ·  view source on GitHub ↗
(
    files: TreeFile[],
    slug: string,
    mediaFilesList: MediaFile[],
    options: PersistOptions,
  )

Source from the content-addressed store, hash-verified

1041 }
1042
1043 async editorialWorkflowGit(
1044 files: TreeFile[],
1045 slug: string,
1046 mediaFilesList: MediaFile[],
1047 options: PersistOptions,
1048 ) {
1049 const contentKey = this.generateContentKey(options.collectionName as string, slug);
1050 const branch = branchFromContentKey(contentKey);
1051 const unpublished = options.unpublished || false;
1052 const hasSubfolders = options.hasSubfolders !== false; // default to true
1053 if (!unpublished) {
1054 const branchData = await this.getDefaultBranch();
1055 const changeTree = await this.updateTree(
1056 branchData.commit.sha,
1057 files,
1058 this.branch,
1059 hasSubfolders,
1060 );
1061 const commitResponse = await this.commit(options.commitMessage, changeTree);
1062
1063 if (this.useOpenAuthoring) {
1064 await this.createBranch(branch, commitResponse.sha);
1065 } else {
1066 const pr = await this.createBranchAndPullRequest(
1067 branch,
1068 commitResponse.sha,
1069 options.commitMessage,
1070 );
1071 await this.setPullRequestStatus(
1072 pr as GitHubPull,
1073 options.status || this.initialWorkflowStatus,
1074 );
1075 }
1076 } else {
1077 // Entry is already on editorial review workflow - commit to existing branch
1078 const { files: diffFiles } = await this.getDifferences(
1079 this.branch,
1080 await this.getHeadReference(branch),
1081 );
1082
1083 const diffs = await Promise.all((diffFiles || []).map(file => this.diffFromFile(file)));
1084 // mark media files to remove
1085 const mediaFilesToRemove: { path: string; sha: string | null }[] = [];
1086 for (const diff of diffs.filter(d => d.binary)) {
1087 if (!mediaFilesList.some(file => file.path === diff.path)) {
1088 mediaFilesToRemove.push({ path: diff.path, sha: null });
1089 }
1090 }
1091
1092 // rebase the branch before applying new changes
1093 const rebasedHead = await this.rebaseBranch(branch);
1094 const treeFiles = mediaFilesToRemove.concat(files);
1095 const changeTree = await this.updateTree(rebasedHead.sha, treeFiles, branch, hasSubfolders);
1096 const commit = await this.commit(options.commitMessage, changeTree);
1097
1098 return this.patchBranch(branch, commit.sha, { force: true });
1099 }
1100 }

Callers 2

persistFilesMethod · 0.95
API.spec.jsFile · 0.45

Calls 15

generateContentKeyMethod · 0.95
getDefaultBranchMethod · 0.95
updateTreeMethod · 0.95
commitMethod · 0.95
createBranchMethod · 0.95
setPullRequestStatusMethod · 0.95
getDifferencesMethod · 0.95
getHeadReferenceMethod · 0.95
diffFromFileMethod · 0.95
rebaseBranchMethod · 0.95
patchBranchMethod · 0.95

Tested by

no test coverage detected