MCPcopy Index your code
hub / github.com/angular/dev-infra / verify

Function verify

ng-dev/pullapprove/verify.ts:16–110  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

14import {getGroupsFromYaml} from './parse-yaml.js';
15
16export async function verify() {
17 const git = await GitClient.get();
18 /** Full path to PullApprove config file */
19 const PULL_APPROVE_YAML_PATH = resolve(git.baseDir, '.pullapprove.yml');
20 /** All tracked files in the repository. */
21 const REPO_FILES = git.allFiles();
22 /** The pull approve config file. */
23 const pullApproveYamlRaw = readFileSync(PULL_APPROVE_YAML_PATH, 'utf8');
24 /** All of the groups defined in the pullapprove yaml. */
25 const groups = getGroupsFromYaml(pullApproveYamlRaw);
26 /**
27 * PullApprove groups without conditions. These are skipped in the verification
28 * as those would always be active and cause zero unmatched files.
29 */
30 const groupsSkipped = groups.filter((group) => !group.conditions.length);
31 /** PullApprove groups with conditions. */
32 const groupsWithConditions = groups.filter((group) => !!group.conditions.length);
33 /** Files which are matched by at least one group. */
34 const matchedFiles: string[] = [];
35 /** Files which are not matched by at least one group. */
36 const unmatchedFiles: string[] = [];
37
38 // Test each file in the repo against each group for being matched.
39 REPO_FILES.forEach((file: string) => {
40 if (groupsWithConditions.filter((group) => group.testFile(file)).length) {
41 matchedFiles.push(file);
42 } else {
43 unmatchedFiles.push(file);
44 }
45 });
46 /** Results for each group */
47 const resultsByGroup = groupsWithConditions.map((group) => group.getResults());
48 /**
49 * Whether all group condition lines match at least one file and all files
50 * are matched by at least one group.
51 */
52 const allGroupConditionsValid =
53 resultsByGroup.every((r) => !r.unmatchedCount) && !unmatchedFiles.length;
54 /** Whether all groups have at least one reviewer user or team defined. */
55 const groupsWithoutReviewers = groups.filter(
56 (group) => Object.keys(group.reviewers).length === 0,
57 );
58 /** The overall result of the verifcation. */
59 const overallResult = allGroupConditionsValid && groupsWithoutReviewers.length === 0;
60
61 /**
62 * Overall result
63 */
64 logHeader('Overall Result');
65 if (overallResult) {
66 Log.info('PullApprove verification succeeded!');
67 } else {
68 Log.info(`PullApprove verification failed.`);
69 Log.info();
70 Log.info(`Please update '.pullapprove.yml' to ensure that all necessary`);
71 Log.info(`files/directories have owners and all patterns that appear in`);
72 Log.info(`the file correspond to actual files/directories in the repo.`);
73 }

Callers 1

buildPullapproveParserFunction · 0.70

Calls 10

resolveFunction · 0.85
getGroupsFromYamlFunction · 0.85
logHeaderFunction · 0.85
logGroupFunction · 0.85
allFilesMethod · 0.80
testFileMethod · 0.80
getResultsMethod · 0.80
getMethod · 0.45
pushMethod · 0.45
keysMethod · 0.45

Tested by

no test coverage detected