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
13 changes: 12 additions & 1 deletion packages/cli/src/commands/alert/issues/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,18 @@ function applyIssueEdits(
const actionFilters = Array.isArray(body.actionFilters)
? (body.actionFilters as Record<string, unknown>[])
: [];
const filter = (actionFilters[0] as Record<string, unknown>) ?? {};
const existingFilter = actionFilters[0] as
| Record<string, unknown>
| undefined;
// When the rule has no action filter yet, a partial edit (e.g. only
// --action) must still emit a valid DataConditionGroup. Seed the same
// defaults the create path uses so the group carries a logicType and a
// conditions array; the workflows API rejects a group without a logic
// type. An existing filter keeps its own logicType/conditions.
const filter: Record<string, unknown> = existingFilter ?? {
logicType: matchToLogicType(undefined),
conditions: [],
};
if (actions !== undefined) {
filter.actions = actions;
}
Expand Down
42 changes: 42 additions & 0 deletions packages/cli/test/commands/alert/issues/edit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,48 @@ describe("alert issues edit", () => {
});
});

test("seeds logicType and conditions when the rule has no action filter yet", async () => {
const context = createContext();
resolveSpy.mockResolvedValue({ targets: [sampleTarget] });
getRuleSpy.mockResolvedValue(sampleRule);
getDocSpy.mockResolvedValue({
id: "42",
name: "Rule Alpha",
enabled: true,
config: { frequency: 30 },
triggers: {
logicType: "any-short",
conditions: [{ id: "old-condition" }],
},
});
putSpy.mockResolvedValue({ id: "42", name: "Rule Alpha", enabled: true });
const func = (await editCommand.loader()) as unknown as (
this: unknown,
flags: EditFlags,
arg: string
) => Promise<void>;

await func.call(
context,
{ action: ['{"id":"new-action"}'], json: true },
"test-org/test-project/42"
);

expect(putSpy).toHaveBeenCalledWith("test-org", "42", {
id: "42",
name: "Rule Alpha",
enabled: true,
config: { frequency: 30 },
triggers: {
logicType: "any-short",
conditions: [{ id: "old-condition" }],
},
actionFilters: [
{ logicType: "all", conditions: [], actions: [{ id: "new-action" }] },
],
});
});

test("maps the workflow enabled field to a status label in output", async () => {
const context = createContext();
resolveSpy.mockResolvedValue({ targets: [sampleTarget] });
Expand Down
Loading