Kumi
11bde9e12d
All checks were successful
/ chores (push) Successful in 19s
Ensured that the 'due_date' variable is now formatted in strict ISO 8601 compliance by removing microseconds and appending 'Z' to indicate UTC. This change aids in consistent date-time parsing across different systems and services that expect a standardized timestamp without fractional seconds.
56 lines
1.4 KiB
Python
56 lines
1.4 KiB
Python
import pathlib
|
|
import json
|
|
import argparse
|
|
import os
|
|
import urllib.request
|
|
import logging
|
|
|
|
from datetime import datetime, timedelta
|
|
|
|
FORGEJO_URL = os.environ.get("FORGEJO_URL") or "https://git.private.coffee"
|
|
|
|
try:
|
|
TOKEN = os.environ["FORGEJO_TOKEN"]
|
|
assert TOKEN
|
|
except (KeyError, AssertionError):
|
|
logging.error("FORGEJO_TOKEN environment variable is required")
|
|
exit(1)
|
|
|
|
ASSIGNEES = os.environ.get("CHORES_ASSIGNEES").split()
|
|
REPO_OWNER = os.environ.get("CHORES_REPO_OWNER") or "PrivateCoffee"
|
|
REPO_NAME = os.environ.get("CHORES_REPO_NAME") or "chores"
|
|
EXPIRY_DAYS = int(os.environ.get("CHORES_EXPIRY_DAYS") or 2)
|
|
CHORES = (
|
|
os.environ.get("CHORES_TEXT")
|
|
or "Looks like you forgot to set the CHORES_TEXT environment variable."
|
|
)
|
|
|
|
|
|
due_date = (datetime.utcnow() + timedelta(days=EXPIRY_DAYS)).isoformat().split(".")[0] + "Z"
|
|
|
|
payload = {
|
|
"title": "Weekly Chores",
|
|
"body": CHORES,
|
|
"due_date": due_date,
|
|
}
|
|
|
|
if ASSIGNEES:
|
|
payload["assignees"] = ASSIGNEES
|
|
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
"Accept": "application/json",
|
|
"Authorization": "token " + TOKEN,
|
|
}
|
|
|
|
print(f"Creating issue with payload:\n{payload}")
|
|
|
|
request = urllib.request.Request(
|
|
f"{FORGEJO_URL}/api/v1/repos/{REPO_OWNER}/{REPO_NAME}/issues",
|
|
data=json.dumps(payload).encode("utf-8"),
|
|
headers=headers,
|
|
method="POST",
|
|
)
|
|
|
|
with urllib.request.urlopen(request) as response:
|
|
print(response.read().decode("utf-8"))
|