Skip to content

Commit 46ba6d7

Browse files
insertishclaude
andauthored
feat: delete OpenProject tickets when creation criteria is no longer satisfied (#1)
feat: delete OpenProject tickets when owner becomes unmapped When a Zammad ticket's owner changes to someone who is not in the ASSIGNEES mapping, the corresponding OpenProject work package is now deleted. This maintains consistency with the creation rule that prevents creating tickets for unmapped owners. The deletion logic: - Checks if an existing task has an unmapped owner - Deletes the OpenProject work package via DELETE API call - Returns early to prevent the update logic from running - Logs the deletion with owner ID for debugging This ensures that tickets only exist in OpenProject when they meet the same criteria required for creation (owner must be mapped). Co-authored-by: Claude <[email protected]>
1 parent dbfa756 commit 46ba6d7

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

main.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,28 @@ if (import.meta.main) {
111111

112112
// (2) create or update
113113
if (existingTask) {
114+
// Delete task if owner is no longer mapped
115+
if (!ASSIGNEES[ticket.owner_id]) {
116+
console.info(
117+
`Deleting task ${existingTask.id} - owner ${ticket.owner_id} is not mapped.`
118+
);
119+
120+
await fetch(
121+
`${OP_URL}/api/v3/work_packages/${existingTask.id}`,
122+
{
123+
method: "DELETE",
124+
headers: {
125+
Authorization: "Basic " + btoa("apikey:" + OP_TOKEN),
126+
},
127+
}
128+
).then((r) => {
129+
if (!r.ok) throw new Error(`Delete failed with status ${r.status}`);
130+
});
131+
132+
console.info("Deleted task successfully.");
133+
return new Response(null, { status: 200 });
134+
}
135+
114136
// update existing task
115137
await fetch(
116138
`${OP_URL}/api/v3/work_packages/${existingTask.id}?notify=false`,

0 commit comments

Comments
 (0)