MCPcopy Index your code
hub / github.com/loopbackio/loopback-next / checkoutPR

Function checkoutPR

bin/checkout-pr.js:29–59  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

27const ROOT_DIR = path.join(__dirname, '..');
28
29async 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

Callers

nothing calls this directly

Calls 5

getPRInfoFunction · 0.85
errorMethod · 0.80
exitMethod · 0.80
gitFunction · 0.70
logMethod · 0.65

Tested by

no test coverage detected