1

Update issue sync script to include due dates

This commit is contained in:
Evan Pratten 2024-04-03 10:14:34 -04:00
parent 9c10ff4fe8
commit 11a84146f7

View File

@ -6,6 +6,8 @@ import requests
import subprocess
from textwrap import dedent
from pathlib import Path
from datetime import datetime
from typing import Optional
try:
import gitlab
@ -232,6 +234,35 @@ def main() -> int:
)
response.raise_for_status()
# Determine the due date assigned in GitLab
due_date: Optional[str] = issue.due_date
if due_date:
# Check if the card already has a due date
card_due_date = card.get("due", None)
if card_due_date:
card_due_date = card_due_date.split("T")[0]
# Convert to a useful format
due_date = datetime.strptime(due_date, "%Y-%m-%d")
card_due_date = datetime.strptime(card_due_date, "%Y-%m-%d") if card_due_date else None
# If the card has an earlier due date, skip
if card_due_date and due_date < card_due_date:
logger.debug(f"Skipping due date update for {card['id']} because it has an earlier due date already")
continue
# Update the due date
logger.info(f"Updating due date for card {card['id']} to {due_date}")
response = requests.put(
f"https://api.trello.com/1/cards/{card['id']}",
params={
"key": TRELLO_KEY,
"token": trello_api_token,
"due": due_date.isoformat(),
},
)
return 0