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

Function checkoutAsPrTakeover

ng-dev/pr/checkout/takeover.ts:22–70  ·  view source on GitHub ↗
(
  prNumber: number,
  {resetGitState, pullRequest}: Awaited<ReturnType<typeof checkOutPullRequestLocally>>,
)

Source from the content-addressed store, hash-verified

20 * Checkout the provided pull request in preperation for a new takeover pull request to be made
21 */
22export async function checkoutAsPrTakeover(
23 prNumber: number,
24 {resetGitState, pullRequest}: Awaited<ReturnType<typeof checkOutPullRequestLocally>>,
25) {
26 /** An authenticated git client. */
27 const git = await AuthenticatedGitClient.get();
28 /** The branch name to be used for the takeover attempt. */
29 const branchName = `pr-takeover-${prNumber}`;
30
31 if (git.runGraceful(['rev-parse', '-q', '--verify', branchName]).status === 0) {
32 Log.error(` ✘ Expected branch name \`${branchName}\` already exists locally`);
33 return;
34 }
35
36 // Validate that the takeover attempt is being made against a pull request created by an
37 // expected account.
38 if (!pullRequest.author || !takeoverAccounts.includes(pullRequest.author.login)) {
39 Log.warn(
40 ` ⚠ ${bold(pullRequest.author?.login ?? 'unknown')} is not an account fully supported for takeover.`,
41 );
42 Log.warn(` Supported accounts: ${bold(takeoverAccounts.join(', '))}`);
43 if (
44 await Prompt.confirm({
45 message: `Continue with pull request takeover anyway?`,
46 default: true,
47 })
48 ) {
49 Log.debug('Continuing per user confirmation in prompt');
50 } else {
51 Log.info('Aborting takeover..');
52 resetGitState();
53 return;
54 }
55 }
56
57 Log.info(`Setting local branch name based on the pull request`);
58 git.run(['checkout', '-q', '-b', branchName]);
59
60 Log.info('Updating commit messages to close previous pull request');
61 git.run([
62 'filter-branch',
63 '-f',
64 '--msg-filter',
65 `${getCommitMessageFilterScriptPath()} ${prNumber}`,
66 `${pullRequest.baseRefOid}..HEAD`,
67 ]);
68
69 Log.info(` ${green('✔')} Checked out pull request #${prNumber} into branch: ${branchName}`);
70}
71
72/** Gets the absolute file path to the commit-message filter script. */
73function getCommitMessageFilterScriptPath(): string {

Callers 1

checkoutPullRequestFunction · 0.85

Calls 5

getMethod · 0.45
runGracefulMethod · 0.45
errorMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected