| 
									
										
										
										
											2020-03-20 06:59:35 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							| 
									
										
										
										
											2020-05-19 12:08:49 -07:00
										 |  |  |  * Copyright Google LLC All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2020-03-20 06:59:35 -07:00
										 |  |  |  * | 
					
						
							|  |  |  |  * 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
 | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-04-16 20:12:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-20 14:41:44 -07:00
										 |  |  | import {info} from '../utils/console'; | 
					
						
							| 
									
										
										
										
											2020-03-20 06:59:35 -07:00
										 |  |  | import {PullApproveGroupResult} from './group'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-23 15:53:46 -07:00
										 |  |  | type ConditionGrouping = keyof Pick< | 
					
						
							|  |  |  |     PullApproveGroupResult, 'matchedConditions'|'unmatchedConditions'|'unverifiableConditions'>; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-20 06:59:35 -07:00
										 |  |  | /** Create logs for each pullapprove group result. */ | 
					
						
							| 
									
										
										
										
											2020-07-23 15:53:46 -07:00
										 |  |  | export function logGroup( | 
					
						
							|  |  |  |     group: PullApproveGroupResult, conditionsToPrint: ConditionGrouping, printMessageFn = info) { | 
					
						
							|  |  |  |   const conditions = group[conditionsToPrint]; | 
					
						
							| 
									
										
										
										
											2020-05-28 14:57:47 -07:00
										 |  |  |   printMessageFn.group(`[${group.groupName}]`); | 
					
						
							| 
									
										
										
										
											2020-04-16 20:12:25 +02:00
										 |  |  |   if (conditions.length) { | 
					
						
							| 
									
										
										
										
											2020-07-23 15:53:46 -07:00
										 |  |  |     conditions.forEach(groupCondition => { | 
					
						
							|  |  |  |       const count = groupCondition.matchedFiles.size; | 
					
						
							|  |  |  |       if (conditionsToPrint === 'unverifiableConditions') { | 
					
						
							|  |  |  |         printMessageFn(`${groupCondition.expression}`); | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         printMessageFn( | 
					
						
							|  |  |  |             `${count} ${count === 1 ? 'match' : 'matches'} - ${groupCondition.expression}`); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-04-16 20:12:25 +02:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-05-28 14:57:47 -07:00
										 |  |  |     printMessageFn.groupEnd(); | 
					
						
							| 
									
										
										
										
											2020-03-20 06:59:35 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** Logs a header within a text drawn box. */ | 
					
						
							|  |  |  | export function logHeader(...params: string[]) { | 
					
						
							|  |  |  |   const totalWidth = 80; | 
					
						
							|  |  |  |   const fillWidth = totalWidth - 2; | 
					
						
							|  |  |  |   const headerText = params.join(' ').substr(0, fillWidth); | 
					
						
							|  |  |  |   const leftSpace = Math.ceil((fillWidth - headerText.length) / 2); | 
					
						
							|  |  |  |   const rightSpace = fillWidth - leftSpace - headerText.length; | 
					
						
							|  |  |  |   const fill = (count: number, content: string) => content.repeat(count); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-20 14:41:44 -07:00
										 |  |  |   info(`┌${fill(fillWidth, '─')}┐`); | 
					
						
							|  |  |  |   info(`│${fill(leftSpace, ' ')}${headerText}${fill(rightSpace, ' ')}│`); | 
					
						
							|  |  |  |   info(`└${fill(fillWidth, '─')}┘`); | 
					
						
							| 
									
										
										
										
											2020-04-16 20:12:25 +02:00
										 |  |  | } |