| 27 | const ROOT_DIR = path.join(__dirname, '..'); |
| 28 | |
| 29 | async function checkoutPR() { |
| 30 | const prUrlOrNum = process.argv[2]; |
| 31 | if (!prUrlOrNum) { |
| 32 | console.error( |
| 33 | 'Usage: node %s <PR-number-or-url>', |
| 34 | path.relative(process.cwd(), process.argv[1]), |
| 35 | ); |
| 36 | process.exit(1); |
| 37 | } |
| 38 | |
| 39 | const parts = prUrlOrNum.split('/').filter(Boolean); |
| 40 | const prNum = parts[parts.length - 1] || parts[0]; |
| 41 | |
| 42 | console.log(`Checking out pull request #${prNum}...`); |
| 43 | |
| 44 | const url = `https://api.github.com/repos/loopbackio/loopback-next/pulls/${prNum}`; |
| 45 | |
| 46 | const result = await getPRInfo(url); |
| 47 | const headUrl = result.head.repo.ssh_url; |
| 48 | const headBranch = result.head.ref; |
| 49 | const baseBranch = result.base.ref; |
| 50 | |
| 51 | const prStream = `pr-${prNum}`; |
| 52 | await git('remote', 'add', prStream, headUrl); |
| 53 | await git('fetch', prStream, headBranch); |
| 54 | await git('fetch', 'origin', baseBranch); |
| 55 | await git('checkout', '--track', `${prStream}/${headBranch}`); |
| 56 | await git('rebase', `origin/${baseBranch}`); |
| 57 | |
| 58 | console.log(`PR ${prNum} is now checked out.`); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Fetch PR information |