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

Method migrateToVersion1

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

Source from the content-addressed store, hash-verified

759 };
760
761 async migrateToVersion1(pullRequest: GitHubPull, metadata: Metadata) {
762 // hard code key/branch generation logic to ignore future changes
763 const oldContentKey = pullRequest.head.ref.slice(`cms/`.length);
764 const newContentKey = `${metadata.collection}/${oldContentKey}`;
765 const newBranchName = `cms/${newContentKey}`;
766
767 // retrieve or create new branch and pull request in new format
768 const branch = await this.getBranch(newBranchName).catch(() => undefined);
769 if (!branch) {
770 await this.createBranch(newBranchName, pullRequest.head.sha as string);
771 }
772
773 const pr =
774 (await this.getPullRequests(newBranchName, PullRequestState.All, () => true))[0] ||
775 (await this.createPR(pullRequest.title, newBranchName));
776
777 // store new metadata
778 const newMetadata = {
779 ...metadata,
780 pr: {
781 number: pr.number,
782 head: pr.head.sha,
783 },
784 branch: newBranchName,
785 version: '1',
786 };
787 await this.storeMetadata(newContentKey, newMetadata);
788
789 // remove old data
790 await this.closePR(pullRequest.number);
791 await this.deleteBranch(pullRequest.head.ref);
792 await this.deleteMetadata(oldContentKey);
793
794 return { metadata: newMetadata, pullRequest: pr };
795 }
796
797 async migrateToPullRequestLabels(pullRequest: GitHubPull, metadata: Metadata) {
798 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