80 lines
2.8 KiB
Python
80 lines
2.8 KiB
Python
import os
|
|
from app.db.session import SessionLocal
|
|
from app.models import Task
|
|
|
|
def sync_backlog():
|
|
filepath = "BACKLOG.md"
|
|
if not os.path.exists(filepath):
|
|
return False
|
|
|
|
db = SessionLocal()
|
|
try:
|
|
with open(filepath, "r", encoding="utf-8") as f:
|
|
lines = f.readlines()
|
|
|
|
table_lines = [l.strip() for l in lines if l.strip().startswith("|")]
|
|
|
|
if len(table_lines) > 2:
|
|
data_lines = table_lines[2:] # Skip header and separator
|
|
|
|
for line in data_lines:
|
|
cols = [c.strip() for c in line.split("|")]
|
|
if len(cols) >= 8:
|
|
todo = cols[1]
|
|
details = cols[2]
|
|
ansprechpartner = cols[3]
|
|
quelle = cols[4]
|
|
deadline = cols[5]
|
|
prioritaet = cols[6].lower()
|
|
umfang = cols[7]
|
|
|
|
if not todo:
|
|
continue
|
|
|
|
priority_val = 4
|
|
if "sehr hoch" in prioritaet:
|
|
priority_val = 1
|
|
elif "hoch" in prioritaet:
|
|
priority_val = 2
|
|
elif "mittel" in prioritaet:
|
|
priority_val = 3
|
|
|
|
# Build a structured description
|
|
description_parts = []
|
|
if details: description_parts.append(f"Details: {details}")
|
|
if ansprechpartner: description_parts.append(f"Ansprechpartner: {ansprechpartner}")
|
|
if deadline: description_parts.append(f"Deadline: {deadline}")
|
|
if umfang: description_parts.append(f"Umfang: {umfang}")
|
|
|
|
full_desc = "\n".join(description_parts)
|
|
|
|
existing_task = db.query(Task).filter(Task.title == todo).first()
|
|
if existing_task:
|
|
existing_task.description = full_desc
|
|
existing_task.origin = quelle
|
|
existing_task.priority = priority_val
|
|
else:
|
|
new_task = Task(
|
|
title=todo,
|
|
description=full_desc,
|
|
origin=quelle,
|
|
priority=priority_val,
|
|
status="open"
|
|
)
|
|
db.add(new_task)
|
|
|
|
db.commit()
|
|
return True
|
|
except Exception as e:
|
|
print(f"Error syncing backlog: {e}")
|
|
db.rollback()
|
|
return False
|
|
finally:
|
|
db.close()
|
|
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
success = sync_backlog()
|
|
print(f"Sync successful: {success}")
|