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

Method migrateToVersion1

packages/decap-cms-backend-github/src/API.ts:786–820  ·  view source on GitHub ↗
(pullRequest: GitHubPull, metadata: Metadata)

Source from the content-addressed store, hash-verified

784 };
785
786 async migrateToVersion1(pullRequest: GitHubPull, metadata: Metadata) {
787 // hard code key/branch generation logic to ignore future changes
788 const oldContentKey = pullRequest.head.ref.slice(`cms/`.length);
789 const newContentKey = `${metadata.collection}/${oldContentKey}`;
790 const newBranchName = `cms/${newContentKey}`;
791
792 // retrieve or create new branch and pull request in new format
793 const branch = await this.getBranch(newBranchName).catch(() => undefined);
794 if (!branch) {
795 await this.createBranch(newBranchName, pullRequest.head.sha as string);
796 }
797
798 const pr =
799 (await this.getPullRequests(newBranchName, PullRequestState.All, () => true))[0] ||
800 (await this.createPR(pullRequest.title, newBranchName));
801
802 // store new metadata
803 const newMetadata = {
804 ...metadata,
805 pr: {
806 number: pr.number,
807 head: pr.head.sha,
808 },
809 branch: newBranchName,
810 version: '1',
811 };
812 await this.storeMetadata(newContentKey, newMetadata);
813
814 // remove old data
815 await this.closePR(pullRequest.number);
816 await this.deleteBranch(pullRequest.head.ref);
817 await this.deleteMetadata(oldContentKey);
818
819 return { metadata: newMetadata, pullRequest: pr };
820 }
821
822 async migrateToPullRequestLabels(pullRequest: GitHubPull, metadata: Metadata) {
823 await this.setPullRequestStatus(pullRequest, metadata.status);

Callers 2

migratePullRequestMethod · 0.95
API.spec.jsFile · 0.80

Calls 8

getBranchMethod · 0.95
createBranchMethod · 0.95
getPullRequestsMethod · 0.95
createPRMethod · 0.95
storeMetadataMethod · 0.95
closePRMethod · 0.95
deleteBranchMethod · 0.95
deleteMetadataMethod · 0.95

Tested by

no test coverage detected