Skip to content

Commit 481512e

Browse files
committed
fix(ng-dev): update pullapprove to handle array inclusion checks (#2321)
Allow the inclusion checks with arrays to be included and still pass verification checks PR Close #2321
1 parent 8d3cb7b commit 481512e

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

ng-dev/pullapprove/condition_evaluator.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ const conditionEvaluationContext: object = (() => {
3333
// We cannot process references to `author` in conditions.
3434
Object.defineProperty(context, 'author', {
3535
get: () => {
36-
throw new PullApproveAuthorStateDependencyError();
36+
const x: any = new String();
37+
x.matchesAny = true;
38+
return x;
3739
},
3840
});
3941

@@ -79,6 +81,8 @@ export function convertConditionToFunction(
7981
*/
8082
function transformExpressionToJs(expression: string): string {
8183
return expression
84+
.replace(/^(.+)\s+not in\s+(\[.+\])$/, '!$2.some(x => $1.matchesAny || $1 == x)')
85+
.replace(/^(.+)\s+in\s+(.+)$/, '$2.some(x => $1.matchesAny || $1 == x)')
8286
.replace(/^(.+)\s+not in\s+(.+)$/, '!$2.includes($1)')
8387
.replace(/^(.+)\s+in\s+(.+)$/, '$2.includes($1)')
8488
.replace(/not\s+/g, '!');

ng-dev/pullapprove/verify.spec.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ describe('group parsing', () => {
7979
expect(() => fwCore.testFile('any')).not.toThrow();
8080
});
8181

82-
it('should never match groups with conditions that rely on author state', () => {
82+
describe('automaticall matches for author and', () => {
8383
const groups = getGroupsFromYaml(`
8484
groups:
8585
renovate-notify-group:
@@ -89,8 +89,13 @@ describe('group parsing', () => {
8989
`);
9090
const renovateGroup = getGroupByName(groups, 'renovate-notify-group')!;
9191

92-
expect(renovateGroup.testFile('packages/core/index.ts')).toBe(false);
93-
expect(renovateGroup.conditions[0].unverifiable).toBe(true);
92+
it('can pass with a file match', () => {
93+
expect(renovateGroup.testFile('packages/core/index.ts')).toBe(true);
94+
});
95+
96+
it('can fail without a file match', () => {
97+
expect(renovateGroup.testFile('packages/not-core/index.ts')).toBe(false);
98+
});
9499
});
95100

96101
describe('in operator', () => {

0 commit comments

Comments
 (0)