| 
									
										
										
										
											2020-05-15 17:21:01 +02: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
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-22 14:05:28 -08:00
										 |  |  | import {Arguments, Argv, CommandModule} from 'yargs'; | 
					
						
							| 
									
										
										
										
											2020-05-20 14:48:50 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-01 10:39:35 +02:00
										 |  |  | import {addGithubTokenOption} from '../../utils/git/github-yargs'; | 
					
						
							| 
									
										
										
										
											2020-05-20 14:48:50 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-28 11:45:01 -07:00
										 |  |  | import {mergePullRequest} from './index'; | 
					
						
							| 
									
										
										
										
											2020-05-15 17:21:01 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-14 12:20:55 -07:00
										 |  |  | /** The options available to the merge command via CLI. */ | 
					
						
							|  |  |  | export interface MergeCommandOptions { | 
					
						
							| 
									
										
										
										
											2020-08-28 11:45:01 -07:00
										 |  |  |   githubToken: string; | 
					
						
							| 
									
										
										
										
											2021-01-22 14:05:28 -08:00
										 |  |  |   pr: number; | 
					
						
							|  |  |  |   branchPrompt: boolean; | 
					
						
							| 
									
										
										
										
											2020-08-14 12:20:55 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-22 14:05:28 -08:00
										 |  |  | /** Builds the command. */ | 
					
						
							|  |  |  | function builder(yargs: Argv) { | 
					
						
							|  |  |  |   return addGithubTokenOption(yargs) | 
					
						
							|  |  |  |       .help() | 
					
						
							|  |  |  |       .strict() | 
					
						
							|  |  |  |       .positional('pr', { | 
					
						
							|  |  |  |         demandOption: true, | 
					
						
							|  |  |  |         type: 'number', | 
					
						
							|  |  |  |         description: 'The PR to be merged.', | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |       .option('branch-prompt' as 'branchPrompt', { | 
					
						
							|  |  |  |         type: 'boolean', | 
					
						
							|  |  |  |         default: true, | 
					
						
							|  |  |  |         description: 'Whether to prompt to confirm the branches a PR will merge into.', | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2020-05-15 17:21:01 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-22 14:05:28 -08:00
										 |  |  | /** Handles the command. */ | 
					
						
							| 
									
										
										
										
											2021-04-08 12:34:55 -07:00
										 |  |  | async function handler({pr, branchPrompt}: Arguments<MergeCommandOptions>) { | 
					
						
							|  |  |  |   await mergePullRequest(pr, {branchPrompt}); | 
					
						
							| 
									
										
										
										
											2020-05-15 17:21:01 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2021-01-22 14:05:28 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-24 16:17:15 -07:00
										 |  |  | /** yargs command module describing the command. */ | 
					
						
							| 
									
										
										
										
											2021-01-22 14:05:28 -08:00
										 |  |  | export const MergeCommandModule: CommandModule<{}, MergeCommandOptions> = { | 
					
						
							|  |  |  |   handler, | 
					
						
							|  |  |  |   builder, | 
					
						
							|  |  |  |   command: 'merge <pr>', | 
					
						
							|  |  |  |   describe: 'Merge a PR into its targeted branches.', | 
					
						
							|  |  |  | }; |