MCPcopy Create free account
hub / github.com/angular/dev-infra / checkoutToTargetBranch

Function checkoutToTargetBranch

ng-dev/pr/checkout/target.ts:16–80  ·  view source on GitHub ↗
(
  prNumber: number,
  target: string,
  {pullRequest}: Awaited<ReturnType<typeof checkOutPullRequestLocally>>,
)

Source from the content-addressed store, hash-verified

14import {checkOutPullRequestLocally} from '../common/checkout-pr.js';
15import {
16 assertNoNodeModulesInCommitRange,
17 ensureBaseCommitExistsLocally,
18} from '../common/validation/assert-safe-pr-files.js';
19
20export async function checkoutToTargetBranch(
21 prNumber: number,
22 target: string,
23 {pullRequest, resetGitState}: Awaited<ReturnType<typeof checkOutPullRequestLocally>>,
24) {
25 /** An authenticated git client. */
26 const git = await AuthenticatedGitClient.get();
27 const config = git.config;
28
29 const branchName = `pr-${target.toLowerCase().replaceAll(/[\W_]/gm, '-')}-${prNumber}`;
30 const {owner, name: repo} = config.github;
31 const activeReleaseTrains = await ActiveReleaseTrains.fetch({
32 name: repo,
33 owner: owner,
34 nextBranchName: getNextBranchName(config.github),
35 api: git.github,
36 });
37
38 let targetBranch = target;
39 let targetName = target;
40
41 if (
42 target === 'patch' ||
43 target === 'latest' ||
44 activeReleaseTrains.latest.branchName === target
45 ) {
46 targetName = 'patch';
47 targetBranch = activeReleaseTrains.latest.branchName;
48 } else if (
49 target === 'main' ||
50 target === 'next' ||
51 target === 'minor' ||
52 activeReleaseTrains.next.branchName === target
53 ) {
54 targetName = 'main';
55 targetBranch = activeReleaseTrains.next.branchName;
56 } else if (
57 activeReleaseTrains.releaseCandidate &&
58 (target === 'rc' || activeReleaseTrains.releaseCandidate.branchName === target)
59 ) {
60 targetName = 'rc';
61 targetBranch = activeReleaseTrains.releaseCandidate.branchName;
62 }
63 Log.info(`Targeting '${targetBranch}' branch\n`);
64
65 const baseRefUrl = addTokenToGitHttpsUrl(pullRequest.baseRef.repository.url, git.githubToken);
66 const revisionRange = `${pullRequest.baseRefOid}..${pullRequest.headRefOid}`;
67
68 git.run(['checkout', '-q', targetBranch]);
69 git.run(['fetch', '-q', baseRefUrl, '--deepen=500', '--', targetBranch]);
70 try {
71 ensureBaseCommitExistsLocally(
72 git,
73 pullRequest.baseRefOid,

Callers 1

checkoutPullRequestFunction · 0.85

Calls 5

getNextBranchNameFunction · 0.85
addTokenToGitHttpsUrlFunction · 0.85
fetchMethod · 0.80
getMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected