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