(pullRequest: GitHubPull, metadata: Metadata)
| 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); |
no test coverage detected