* Tests a provided file path to determine if it would be considered matched by * the pull approve group's conditions.
(filePath: string)
| 81 | * the pull approve group's conditions. |
| 82 | */ |
| 83 | testFile(filePath: string): boolean { |
| 84 | let allConditionsMet: boolean | null = null; |
| 85 | |
| 86 | for (const condition of this.conditions) { |
| 87 | const {matchedFiles, checkFn, expression} = condition; |
| 88 | try { |
| 89 | const matchesFile = checkFn([filePath], this.precedingGroups); |
| 90 | |
| 91 | if (matchesFile) { |
| 92 | matchedFiles.add(filePath); |
| 93 | } |
| 94 | |
| 95 | allConditionsMet = (allConditionsMet ?? true) && matchesFile; |
| 96 | } catch (e) { |
| 97 | // If a group relies on the author state, we assume this group to never match |
| 98 | // or own a file. This is a strict assumption but prevents false-positives. |
| 99 | if (e instanceof PullApproveAuthorStateDependencyError) { |
| 100 | condition.unverifiable = true; |
| 101 | allConditionsMet = false; |
| 102 | } |
| 103 | // In the case of a condition that depends on the state of groups, we want to ignore |
| 104 | // that the verification can't accurately evaluate the condition and continue processing. |
| 105 | // Other types of errors fail the verification, as conditions should otherwise be able to |
| 106 | // execute without throwing. |
| 107 | else if (e instanceof PullApproveGroupStateDependencyError) { |
| 108 | condition.unverifiable = true; |
| 109 | } else { |
| 110 | const errMessage = |
| 111 | `Condition could not be evaluated: \n\n` + |
| 112 | `From the [${this.groupName}] group:\n` + |
| 113 | ` - ${expression}`; |
| 114 | Log.error(errMessage, '\n\n', e, '\n\n'); |
| 115 | process.exit(1); |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | // A file matches the group when all conditions are met. A group is not considered |
| 121 | // as matching when all conditions have been skipped. |
| 122 | return allConditionsMet === true; |
| 123 | } |
| 124 | |
| 125 | /** Retrieve the results for the Group, all matched and unmatched conditions. */ |
| 126 | getResults(): PullApproveGroupResult { |
no test coverage detected