Skip to content

Commit ec6020e

Browse files
fix(server): match webhook existence filters on wildcard objects (#23414)
Co-authored-by: maria-rcks <[email protected]>
1 parent 6daebdb commit ec6020e

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

‎apps/server/src/scheduledTasks/webhookFilter.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,28 @@ const issueComment: WebhookRequest = {
1616
};
1717

1818
describe("findFailedWebhookFilter", () => {
19+
it("matches exists on wildcard object values", () => {
20+
assert.isNull(
21+
findFailedWebhookFilter([{ path: "body.issue.labels[]", op: "exists" }], issueComment),
22+
);
23+
assert.isNull(
24+
findFailedWebhookFilter([{ path: "body.issues[].labels", op: "exists" }], {
25+
...issueComment,
26+
bodyText: JSON.stringify({ issues: [{ labels: [] }] }),
27+
}),
28+
);
29+
});
30+
31+
it("rejects exists when wildcard values are all null or missing", () => {
32+
assert.deepEqual(
33+
findFailedWebhookFilter([{ path: "body.issues[].labels", op: "exists" }], {
34+
...issueComment,
35+
bodyText: JSON.stringify({ issues: [{ labels: null }, {}] }),
36+
}),
37+
{ index: 0, path: "body.issues[].labels" },
38+
);
39+
});
40+
1941
it("matches a wildcard path when any element matches", () => {
2042
assert.isNull(
2143
findFailedWebhookFilter(

‎apps/server/src/scheduledTasks/webhookFilter.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ function matchesScalar(filter: ScheduledTaskWebhookFilter, text: string): boolea
3636
*/
3737
function matchesWebhookFilter(filter: ScheduledTaskWebhookFilter, value: unknown): boolean {
3838
if (Array.isArray(value) && /\[\]/.test(filter.path)) {
39+
if (filter.op === "exists")
40+
return value.some((element) => element !== null && element !== undefined);
3941
const texts = value.map(scalarText).filter((text): text is string => text !== undefined);
4042
if (filter.op === "notEquals") return texts.every((text) => text !== filter.value);
4143
return texts.some((text) => matchesScalar(filter, text));

0 commit comments

Comments
 (0)