feat(dev-infra): migrate pullapprove tool to use new logging system (#37232)
Migrate the pullapprove tool in ng-dev to use new logging system rather than directly calling console.* to create a better experience for users. PR Close #37232
This commit is contained in:
parent
9b3ca19675
commit
367f6fe12d
|
@ -5,6 +5,8 @@
|
||||||
* Use of this source code is governed by an MIT-style license that can be
|
* 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
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import {error} from '../utils/console';
|
||||||
import {convertConditionToFunction} from './condition_evaluator';
|
import {convertConditionToFunction} from './condition_evaluator';
|
||||||
import {PullApproveGroupConfig} from './parse-yaml';
|
import {PullApproveGroupConfig} from './parse-yaml';
|
||||||
|
|
||||||
|
@ -58,9 +60,11 @@ export class PullApproveGroup {
|
||||||
matchedFiles: new Set(),
|
matchedFiles: new Set(),
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`Could not parse condition in group: ${this.groupName}`);
|
error(`Could not parse condition in group: ${this.groupName}`);
|
||||||
console.error(` - ${expression}`);
|
error(` - ${expression}`);
|
||||||
console.error(`Error:`, e.message, e.stack);
|
error(`Error:`);
|
||||||
|
error(e.message);
|
||||||
|
error(e.stack);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -84,7 +88,7 @@ export class PullApproveGroup {
|
||||||
`From the [${this.groupName}] group:\n` +
|
`From the [${this.groupName}] group:\n` +
|
||||||
` - ${expression}` +
|
` - ${expression}` +
|
||||||
`\n\n${e.message} ${e.stack}\n\n`;
|
`\n\n${e.message} ${e.stack}\n\n`;
|
||||||
console.error(errMessage);
|
error(errMessage);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,18 +6,19 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import {info} from '../utils/console';
|
||||||
import {PullApproveGroupResult} from './group';
|
import {PullApproveGroupResult} from './group';
|
||||||
|
|
||||||
/** Create logs for each pullapprove group result. */
|
/** Create logs for each pullapprove group result. */
|
||||||
export function logGroup(group: PullApproveGroupResult, matched = true) {
|
export function logGroup(group: PullApproveGroupResult, matched = true) {
|
||||||
const conditions = matched ? group.matchedConditions : group.unmatchedConditions;
|
const conditions = matched ? group.matchedConditions : group.unmatchedConditions;
|
||||||
console.groupCollapsed(`[${group.groupName}]`);
|
info.group(`[${group.groupName}]`);
|
||||||
if (conditions.length) {
|
if (conditions.length) {
|
||||||
conditions.forEach(matcher => {
|
conditions.forEach(matcher => {
|
||||||
const count = matcher.matchedFiles.size;
|
const count = matcher.matchedFiles.size;
|
||||||
console.info(`${count} ${count === 1 ? 'match' : 'matches'} - ${matcher.expression}`)
|
info(`${count} ${count === 1 ? 'match' : 'matches'} - ${matcher.expression}`);
|
||||||
});
|
});
|
||||||
console.groupEnd();
|
info.groupEnd();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +31,7 @@ export function logHeader(...params: string[]) {
|
||||||
const rightSpace = fillWidth - leftSpace - headerText.length;
|
const rightSpace = fillWidth - leftSpace - headerText.length;
|
||||||
const fill = (count: number, content: string) => content.repeat(count);
|
const fill = (count: number, content: string) => content.repeat(count);
|
||||||
|
|
||||||
console.info(`┌${fill(fillWidth, '─')}┐`);
|
info(`┌${fill(fillWidth, '─')}┐`);
|
||||||
console.info(`│${fill(leftSpace, ' ')}${headerText}${fill(rightSpace, ' ')}│`);
|
info(`│${fill(leftSpace, ' ')}${headerText}${fill(rightSpace, ' ')}│`);
|
||||||
console.info(`└${fill(fillWidth, '─')}┘`);
|
info(`└${fill(fillWidth, '─')}┘`);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import * as path from 'path';
|
||||||
import {cd, exec, set} from 'shelljs';
|
import {cd, exec, set} from 'shelljs';
|
||||||
|
|
||||||
import {getRepoBaseDir} from '../utils/config';
|
import {getRepoBaseDir} from '../utils/config';
|
||||||
|
import {info} from '../utils/console';
|
||||||
|
|
||||||
import {PullApproveGroup} from './group';
|
import {PullApproveGroup} from './group';
|
||||||
import {logGroup, logHeader} from './logging';
|
import {logGroup, logHeader} from './logging';
|
||||||
|
@ -67,38 +68,39 @@ export function verify(verbose = false) {
|
||||||
*/
|
*/
|
||||||
logHeader('Overall Result');
|
logHeader('Overall Result');
|
||||||
if (verificationSucceeded) {
|
if (verificationSucceeded) {
|
||||||
console.info('PullApprove verification succeeded!');
|
info('PullApprove verification succeeded!');
|
||||||
} else {
|
} else {
|
||||||
console.info(`PullApprove verification failed.\n`);
|
info(`PullApprove verification failed.`);
|
||||||
console.info(`Please update '.pullapprove.yml' to ensure that all necessary`);
|
info();
|
||||||
console.info(`files/directories have owners and all patterns that appear in`);
|
info(`Please update '.pullapprove.yml' to ensure that all necessary`);
|
||||||
console.info(`the file correspond to actual files/directories in the repo.`);
|
info(`files/directories have owners and all patterns that appear in`);
|
||||||
|
info(`the file correspond to actual files/directories in the repo.`);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* File by file Summary
|
* File by file Summary
|
||||||
*/
|
*/
|
||||||
logHeader('PullApprove results by file');
|
logHeader('PullApprove results by file');
|
||||||
console.groupCollapsed(`Matched Files (${matchedFiles.length} files)`);
|
info.group(`Matched Files (${matchedFiles.length} files)`);
|
||||||
verbose && matchedFiles.forEach(file => console.info(file));
|
verbose && matchedFiles.forEach(file => info(file));
|
||||||
console.groupEnd();
|
info.groupEnd();
|
||||||
console.groupCollapsed(`Unmatched Files (${unmatchedFiles.length} files)`);
|
info.group(`Unmatched Files (${unmatchedFiles.length} files)`);
|
||||||
unmatchedFiles.forEach(file => console.info(file));
|
unmatchedFiles.forEach(file => info(file));
|
||||||
console.groupEnd();
|
info.groupEnd();
|
||||||
/**
|
/**
|
||||||
* Group by group Summary
|
* Group by group Summary
|
||||||
*/
|
*/
|
||||||
logHeader('PullApprove results by group');
|
logHeader('PullApprove results by group');
|
||||||
console.groupCollapsed(`Groups skipped (${groupsSkipped.length} groups)`);
|
info.group(`Groups skipped (${groupsSkipped.length} groups)`);
|
||||||
verbose && groupsSkipped.forEach(group => console.info(`${group.groupName}`));
|
verbose && groupsSkipped.forEach(group => info(`${group.groupName}`));
|
||||||
console.groupEnd();
|
info.groupEnd();
|
||||||
const matchedGroups = resultsByGroup.filter(group => !group.unmatchedCount);
|
const matchedGroups = resultsByGroup.filter(group => !group.unmatchedCount);
|
||||||
console.groupCollapsed(`Matched conditions by Group (${matchedGroups.length} groups)`);
|
info.group(`Matched conditions by Group (${matchedGroups.length} groups)`);
|
||||||
verbose && matchedGroups.forEach(group => logGroup(group));
|
verbose && matchedGroups.forEach(group => logGroup(group));
|
||||||
console.groupEnd();
|
info.groupEnd();
|
||||||
const unmatchedGroups = resultsByGroup.filter(group => group.unmatchedCount);
|
const unmatchedGroups = resultsByGroup.filter(group => group.unmatchedCount);
|
||||||
console.groupCollapsed(`Unmatched conditions by Group (${unmatchedGroups.length} groups)`);
|
info.group(`Unmatched conditions by Group (${unmatchedGroups.length} groups)`);
|
||||||
unmatchedGroups.forEach(group => logGroup(group, false));
|
unmatchedGroups.forEach(group => logGroup(group, false));
|
||||||
console.groupEnd();
|
info.groupEnd();
|
||||||
|
|
||||||
// Provide correct exit code based on verification success.
|
// Provide correct exit code based on verification success.
|
||||||
process.exit(verificationSucceeded ? 0 : 1);
|
process.exit(verificationSucceeded ? 0 : 1);
|
||||||
|
|
Loading…
Reference in New Issue