Better handle merged tickets

This commit is contained in:
Michal Čihař 2020-08-18 13:08:50 +02:00
parent 57d039703b
commit 27251d7801

View file

@ -106,9 +106,15 @@ else:
ticket = source.get_ticket(i) ticket = source.get_ticket(i)
if ticket is None: if ticket is None:
break break
ticket["original_id"] = str(i)
queues.add(ticket["Queue"]) queues.add(ticket["Queue"])
ensure_user(ticket["Creator"]) ensure_user(ticket["Creator"])
ensure_user(ticket["Owner"]) ensure_user(ticket["Owner"])
if ticket["original_id"] != ticket["numerical_id"]:
# Merged ticket
history = []
else:
history = source.get_history(i) history = source.get_history(i)
for item in history: for item in history:
for a, title in item["Attachments"]: for a, title in item["Attachments"]:
@ -173,14 +179,29 @@ def get_user(userdata, attr="login"):
# Create tickets # Create tickets
for ticket in tickets: for ticket in tickets:
label = "RT-{}".format(ticket["ticket"]["numerical_id"]) label = "RT-{}".format(ticket["ticket"]["original_id"])
print("Importing {}".format(label)) print("Importing {}".format(label))
if ticket["ticket"]["original_id"] != ticket["ticket"]["numerical_id"]:
# Merged ticket
get_zammad(get_user(users[ticket["ticket"]["Creator"]])).ticket.create(
{
"title": "{} [{}]".format(ticket["ticket"]["Subject"], label),
"group": "Users",
"state_id": 4,
"note": "RT-import:{}".format(ticket["ticket"]["original_id"]),
"article": {
"subject": ticket["ticket"]["Subject"],
"body": "RT ticket merged into {}".format(ticket["ticket"]["numerical_id"]),
},
}
)
continue
new = get_zammad(get_user(users[ticket["ticket"]["Creator"]])).ticket.create( new = get_zammad(get_user(users[ticket["ticket"]["Creator"]])).ticket.create(
{ {
"title": "{} [{}]".format(ticket["ticket"]["Subject"], label), "title": "{} [{}]".format(ticket["ticket"]["Subject"], label),
"group": "Users", "group": "Users",
"state_id": STATUSMAP[ticket["ticket"]["Status"]], "state_id": STATUSMAP[ticket["ticket"]["Status"]],
"note": "RT-import:{}".format(ticket["ticket"]["numerical_id"]), "note": "RT-import:{}".format(ticket["ticket"]["original_id"]),
"article": { "article": {
"subject": ticket["ticket"]["Subject"], "subject": ticket["ticket"]["Subject"],
"body": ticket["history"][0]["Content"], "body": ticket["history"][0]["Content"],