()
| 14 | import {getGroupsFromYaml} from './parse-yaml.js'; |
| 15 | |
| 16 | export 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 | } |
no test coverage detected