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

Method migrateToVersion1

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

Source from the content-addressed store, hash-verified

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