(params: CheckoutPullRequestParams)
| 20 | } |
| 21 | |
| 22 | export async function checkoutPullRequest(params: CheckoutPullRequestParams): Promise<void> { |
| 23 | const {pr, takeover, target} = params; |
| 24 | /** An authenticated git client. */ |
| 25 | const git = await AuthenticatedGitClient.get(); |
| 26 | |
| 27 | if (takeover && target) { |
| 28 | Log.error(` ${red('✘')} The --takeover and --target flags cannot be provided simultaneously`); |
| 29 | return; |
| 30 | } |
| 31 | |
| 32 | // Make sure the local repository is clean. |
| 33 | if (git.hasUncommittedChanges()) { |
| 34 | Log.error( |
| 35 | ` ${red('✘')} Local working repository not clean. Please make sure there are no uncommitted changes`, |
| 36 | ); |
| 37 | return; |
| 38 | } |
| 39 | |
| 40 | const localCheckoutResult = await checkOutPullRequestLocally(pr, { |
| 41 | allowIfMaintainerCannotModify: true, |
| 42 | }); |
| 43 | |
| 44 | if (takeover) { |
| 45 | return await checkoutAsPrTakeover(pr, localCheckoutResult); |
| 46 | } |
| 47 | |
| 48 | if (target) { |
| 49 | return await checkoutToTargetBranch(pr, target, localCheckoutResult); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Whether the pull request is configured to allow for the maintainers to modify the pull request. |
| 54 | */ |
| 55 | const maintainerCanModify = localCheckoutResult.pullRequest.maintainerCanModify; |
| 56 | |
| 57 | if (!maintainerCanModify) { |
| 58 | Log.info('The author of this pull request does not allow maintainers to modify the pull'); |
| 59 | Log.info('request. Since you will not be able to push changes to the original pull request'); |
| 60 | Log.info('you will instead need to perform a "takeover." In a takeover, the original pull'); |
| 61 | Log.info('request will be checked out, the commits are modified to close the original on'); |
| 62 | Log.info('merge of the newly created branch.'); |
| 63 | |
| 64 | if ( |
| 65 | await Prompt.confirm({ |
| 66 | message: `Would you like to create a takeover pull request?`, |
| 67 | default: true, |
| 68 | }) |
| 69 | ) { |
| 70 | return await checkoutAsPrTakeover(pr, localCheckoutResult); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | Log.info(` ${green('✔')} Checked out the remote branch for pull request #${pr}`); |
| 75 | if (maintainerCanModify) { |
| 76 | Log.info('To push the checked out branch back to its PR, run the following command:'); |
| 77 | Log.info(` $ ${localCheckoutResult.pushToUpstreamCommand}`); |
| 78 | } |
| 79 | } |
no test coverage detected