Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions apps/server/src/scheduledTasks/webhookFilter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ describe("findFailedWebhookFilter", () => {
issueComment,
),
);
assert.isNull(
findFailedWebhookFilter(
[{ path: "body.issue.assignees[].login", op: "notEquals", value: "anyone" }],
{ ...issueComment, bodyText: JSON.stringify({ issue: { assignees: null } }) },
),
);
assert.deepEqual(
findFailedWebhookFilter([{ path: "body.issue.number[].x", op: "exists" }], issueComment),
{ index: 0, path: "body.issue.number[].x" },
Expand Down
9 changes: 5 additions & 4 deletions apps/server/src/scheduledTasks/webhookTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ function parseBody(request: WebhookRequest): unknown {
const WILDCARD = /^(.*)\[\]$/;

/**
* Walks `segments` from `root`. A segment ending in `[]` names an array and
* the rest of the path applies to each element, so `labels[].name` resolves
* to the list of every label's name. Elements without the rest of the path
* are dropped; a wildcard on a non-array resolves to undefined.
* Walks `segments` from `root`; a `[]` segment applies the rest of the path to
* each array element, dropping elements that lack it. A wildcard on null is an
* empty list, as Go senders such as Forgejo encode one, and on any other
* non-array it is undefined.
*/
function lookup(root: unknown, segments: ReadonlyArray<string>): unknown {
let current = root;
Expand All @@ -81,6 +81,7 @@ function lookup(root: unknown, segments: ReadonlyArray<string>): unknown {
if (!Object.hasOwn(current, key)) return undefined;
current = (current as Record<string, unknown>)[key];
if (!wildcard) continue;
if (current === null) return [];
if (!Array.isArray(current)) return undefined;
const rest = segments.slice(index + 1);
return current.flatMap((element) => {
Expand Down
Loading