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