Revert "feat(core): Align GitHub metadata handling with other backends (#3292)"

This reverts commit 8193b5ace89d6f14a6c756235a50b186a763b6b1.
This commit is contained in:
Shawn Erquhart
2020-02-22 14:20:28 -05:00
parent 60edf10530
commit 5bdd3df9cc
87 changed files with 34210 additions and 24545 deletions

View File

@ -23,7 +23,6 @@ import {
PreviewState,
FetchError,
parseContentKey,
branchFromContentKey,
} from 'netlify-cms-lib-util';
import { oneLine } from 'common-tags';
import { parse } from 'what-the-diff';
@ -450,8 +449,8 @@ export default class API {
}
async editorialWorkflowGit(files: (Entry | AssetProxy)[], entry: Entry, options: PersistOptions) {
const contentKey = generateContentKey(options.collectionName as string, entry.slug);
const branch = branchFromContentKey(contentKey);
const contentKey = this.generateContentKey(options.collectionName as string, entry.slug);
const branch = this.branchFromContentKey(contentKey);
const unpublished = options.unpublished || false;
if (!unpublished) {
const defaultBranchSha = await this.branchCommitSha(this.branch);
@ -498,6 +497,18 @@ export default class API {
);
};
generateContentKey(collectionName: string, slug: string) {
return generateContentKey(collectionName, slug);
}
contentKeyFromBranch(branch: string) {
return branch.substring(`${CMS_BRANCH_PREFIX}/`.length);
}
branchFromContentKey(contentKey: string) {
return `${CMS_BRANCH_PREFIX}/${contentKey}`;
}
async isFileExists(path: string, branch: string) {
const fileExists = await this.readFile(path, null, { branch })
.then(() => true)
@ -548,7 +559,7 @@ export default class API {
async retrieveMetadata(contentKey: string) {
const { collection, slug } = parseContentKey(contentKey);
const branch = branchFromContentKey(contentKey);
const branch = this.branchFromContentKey(contentKey);
const pullRequest = await this.getBranchPullRequest(branch);
const diff = await this.getDifferences(branch);
const { newPath: path, newFile } = diff.find(d => !d.binary) as {
@ -598,8 +609,8 @@ export default class API {
}
async updateUnpublishedEntryStatus(collection: string, slug: string, newStatus: string) {
const contentKey = generateContentKey(collection, slug);
const branch = branchFromContentKey(contentKey);
const contentKey = this.generateContentKey(collection, slug);
const branch = this.branchFromContentKey(contentKey);
const pullRequest = await this.getBranchPullRequest(branch);
await this.addPullRequestComment(pullRequest, statusToLabel(newStatus));
@ -621,8 +632,8 @@ export default class API {
}
async publishUnpublishedEntry(collectionName: string, slug: string) {
const contentKey = generateContentKey(collectionName, slug);
const branch = branchFromContentKey(contentKey);
const contentKey = this.generateContentKey(collectionName, slug);
const branch = this.branchFromContentKey(contentKey);
const pullRequest = await this.getBranchPullRequest(branch);
await this.mergePullRequest(pullRequest);
@ -643,8 +654,8 @@ export default class API {
}
async deleteUnpublishedEntry(collectionName: string, slug: string) {
const contentKey = generateContentKey(collectionName, slug);
const branch = branchFromContentKey(contentKey);
const contentKey = this.generateContentKey(collectionName, slug);
const branch = this.branchFromContentKey(contentKey);
const pullRequest = await this.getBranchPullRequest(branch);
await this.declinePullRequest(pullRequest);
@ -663,8 +674,8 @@ export default class API {
}
async getStatuses(collectionName: string, slug: string) {
const contentKey = generateContentKey(collectionName, slug);
const branch = branchFromContentKey(contentKey);
const contentKey = this.generateContentKey(collectionName, slug);
const branch = this.branchFromContentKey(contentKey);
const pullRequest = await this.getBranchPullRequest(branch);
const statuses = await this.getPullRequestStatuses(pullRequest);

View File

@ -34,8 +34,6 @@ import {
getLargeMediaFilteredMediaFiles,
FetchError,
blobToFileObj,
contentKeyFromBranch,
generateContentKey,
} from 'netlify-cms-lib-util';
import NetlifyAuthenticator from 'netlify-cms-lib-auth';
import AuthenticationPage from './AuthenticationPage';
@ -447,7 +445,7 @@ export default class BitbucketBackend implements Implementation {
async unpublishedEntries() {
const listEntriesKeys = () =>
this.api!.listUnpublishedBranches().then(branches =>
branches.map(branch => contentKeyFromBranch(branch)),
branches.map(branch => this.api!.contentKeyFromBranch(branch)),
);
const readUnpublishedBranchFile = (contentKey: string) =>
@ -464,7 +462,7 @@ export default class BitbucketBackend implements Implementation {
this.loadEntryMediaFiles(branch, files),
} = {},
) {
const contentKey = generateContentKey(collection, slug);
const contentKey = this.api!.generateContentKey(collection, slug);
const data = await this.api!.readUnpublishedBranchFile(contentKey);
const mediaFiles = await loadEntryMediaFiles(
data.metaData.branch,