There are a few changes in this PR to ensure conditions that are based
on groups (i.e. `- groups.pending.length == 0`) do not fail the verify
task:
* Remove the warning when a condition is encountered that depends on the
`groups` state. The warning will otherwise be printed once for every
file that triggers the execution of the condition (400,000+ times)
* Add an `unverifiable` flag to `GroupCondition` interface and set it to
true when an error is encountered due to attempting to get the state of
`groups` in a condition
* Ignore any unverifiable conditions when gathering unmatched
conditions. These should not be considered `unmatched` for verification
purposes.
* Print the unverifiable conditions by group in the results
Sample output:
```
┌──────────────────────────────────────────────────────────────────────────────┐
│                         PullApprove results by group                         │
└──────────────────────────────────────────────────────────────────────────────┘
Groups skipped (4 groups)
Matched conditions by Group (37 groups)
Unmatched conditions by Group (0 groups)
Unverifiable conditions by Group (3 groups)
  [public-api]
    len(groups.pending.exclude("required-minimum-review")...
    len(groups.rejected.exclude("required-minimum-review")...
  [size-tracking]
    len(groups.pending.exclude("required-minimum-review")...
    len(groups.rejected.exclude("required-minimum-review")...
  [circular-dependencies]
    len(groups.pending.exclude("required-minimum-review")...
    len(groups.rejected.exclude("required-minimum-review")...
```
PR Close #37798
		
	
			
		
			
				
	
	
		
			47 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			47 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| /**
 | |
|  * @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 {info} from '../utils/console';
 | |
| import {PullApproveGroupResult} from './group';
 | |
| 
 | |
| type ConditionGrouping = keyof Pick<
 | |
|     PullApproveGroupResult, 'matchedConditions'|'unmatchedConditions'|'unverifiableConditions'>;
 | |
| 
 | |
| /** Create logs for each pullapprove group result. */
 | |
| export function logGroup(
 | |
|     group: PullApproveGroupResult, conditionsToPrint: ConditionGrouping, printMessageFn = info) {
 | |
|   const conditions = group[conditionsToPrint];
 | |
|   printMessageFn.group(`[${group.groupName}]`);
 | |
|   if (conditions.length) {
 | |
|     conditions.forEach(groupCondition => {
 | |
|       const count = groupCondition.matchedFiles.size;
 | |
|       if (conditionsToPrint === 'unverifiableConditions') {
 | |
|         printMessageFn(`${groupCondition.expression}`);
 | |
|       } else {
 | |
|         printMessageFn(
 | |
|             `${count} ${count === 1 ? 'match' : 'matches'} - ${groupCondition.expression}`);
 | |
|       }
 | |
|     });
 | |
|     printMessageFn.groupEnd();
 | |
|   }
 | |
| }
 | |
| 
 | |
| /** 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);
 | |
| 
 | |
|   info(`┌${fill(fillWidth, '─')}┐`);
 | |
|   info(`│${fill(leftSpace, ' ')}${headerText}${fill(rightSpace, ' ')}│`);
 | |
|   info(`└${fill(fillWidth, '─')}┘`);
 | |
| }
 |