Currently, when verifying our pullapprove configuration, we don't respect modifications to the set of files in a condition. e.g. It's not possible to do the following: ``` contains_any_globs(files.exclude(...), [ ``` This prevents us from having codeowner groups which match a directory, but want to filter out specific sub directories. For example, `fw-core` matches all files in the core package. We want to exclude the schematics from that glob. Usually we do this by another exclude condition. This has a *significant* downside though. It means that fw-core will not be requested if a PR changes schematic code, _and_ actual fw-core code. To support these conditions, the pullapprove verification tool is refactored, so that it no longer uses Regular expressions for parsing, but rather evaluates the code through a dynamic function. This is possible since the conditions are written in simple Python that can be run in NodeJS too (with small modifications/transformations). PR Close #36661
		
			
				
	
	
		
			37 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			37 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
/**
 | 
						|
 * @license
 | 
						|
 * Copyright Google Inc. 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 {PullApproveGroupResult} from './group';
 | 
						|
 | 
						|
/** Create logs for each pullapprove group result. */
 | 
						|
export function logGroup(group: PullApproveGroupResult, matched = true) {
 | 
						|
  const conditions = matched ? group.matchedConditions : group.unmatchedConditions;
 | 
						|
  console.groupCollapsed(`[${group.groupName}]`);
 | 
						|
  if (conditions.length) {
 | 
						|
    conditions.forEach(matcher => {
 | 
						|
      const count = matcher.matchedFiles.size;
 | 
						|
      console.info(`${count} ${count === 1 ? 'match' : 'matches'} - ${matcher.expression}`)
 | 
						|
    });
 | 
						|
    console.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);
 | 
						|
 | 
						|
  console.info(`┌${fill(fillWidth, '─')}┐`);
 | 
						|
  console.info(`│${fill(leftSpace, ' ')}${headerText}${fill(rightSpace, ' ')}│`);
 | 
						|
  console.info(`└${fill(fillWidth, '─')}┘`);
 | 
						|
}
 |