| 
									
										
										
										
											2020-08-14 16:49:07 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							|  |  |  |  * Copyright Google LLC All Rights Reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Use of this source code is governed by an MIT-style license that can be | 
					
						
							|  |  |  |  * found in the LICENSE file at https://angular.io/license
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import {Arguments, Argv, CommandModule} from 'yargs'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-01 10:39:35 +02:00
										 |  |  | import {addGithubTokenOption} from '../../utils/git/github-yargs'; | 
					
						
							| 
									
										
										
										
											2020-08-14 16:49:07 -07:00
										 |  |  | import {checkOutPullRequestLocally} from '../common/checkout-pr'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export interface CheckoutOptions { | 
					
						
							|  |  |  |   prNumber: number; | 
					
						
							| 
									
										
										
										
											2020-08-28 11:45:01 -07:00
										 |  |  |   githubToken: string; | 
					
						
							| 
									
										
										
										
											2020-08-14 16:49:07 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** Builds the checkout pull request command. */ | 
					
						
							|  |  |  | function builder(yargs: Argv) { | 
					
						
							| 
									
										
										
										
											2020-09-01 10:39:35 +02:00
										 |  |  |   return addGithubTokenOption(yargs).positional('prNumber', {type: 'number', demandOption: true}); | 
					
						
							| 
									
										
										
										
											2020-08-14 16:49:07 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** Handles the checkout pull request command. */ | 
					
						
							| 
									
										
										
										
											2020-08-28 11:45:01 -07:00
										 |  |  | async function handler({prNumber, githubToken}: Arguments<CheckoutOptions>) { | 
					
						
							| 
									
										
										
										
											2020-08-14 16:49:07 -07:00
										 |  |  |   const prCheckoutOptions = {allowIfMaintainerCannotModify: true, branchName: `pr-${prNumber}`}; | 
					
						
							|  |  |  |   await checkOutPullRequestLocally(prNumber, githubToken, prCheckoutOptions); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** yargs command module for checking out a PR  */ | 
					
						
							|  |  |  | export const CheckoutCommandModule: CommandModule<{}, CheckoutOptions> = { | 
					
						
							|  |  |  |   handler, | 
					
						
							|  |  |  |   builder, | 
					
						
							|  |  |  |   command: 'checkout <pr-number>', | 
					
						
							|  |  |  |   describe: 'Checkout a PR from the upstream repo', | 
					
						
							|  |  |  | }; |