Refactored the chores script to improve the robustness of environment variable handling. This includes mandatory checks for the FORGEJO_TOKEN and default values or prompts for missing optional environment variables. Added assertion to ensure the token is present after retrieval which, combined with the KeyError, will provide better error handling. Optional variables now use a fallback value directly in the get method for concise expression. Resolves issue with silent failures when required environment settings are not provided.
This commit is contained in:
parent
619d7e9fef
commit
3d13ae755a
1 changed files with 10 additions and 7 deletions
|
@ -11,18 +11,21 @@ FORGEJO_URL = os.environ.get("FORGEJO_URL", "https://git.private.coffee")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
TOKEN = os.environ["FORGEJO_TOKEN"]
|
TOKEN = os.environ["FORGEJO_TOKEN"]
|
||||||
except KeyError:
|
assert TOKEN
|
||||||
|
except (KeyError, AssertionError):
|
||||||
logging.error("FORGEJO_TOKEN environment variable is required")
|
logging.error("FORGEJO_TOKEN environment variable is required")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
ASSIGNEES = os.environ.get("CHORES_ASSIGNEES", "").split()
|
ASSIGNEES = os.environ.get("CHORES_ASSIGNEES").split()
|
||||||
REPO_OWNER = os.environ.get("CHORES_REPO_OWNER", "PrivateCoffee")
|
REPO_OWNER = os.environ.get("CHORES_REPO_OWNER") or "PrivateCoffee"
|
||||||
REPO_NAME = os.environ.get("CHORES_REPO_NAME", "chores")
|
REPO_NAME = os.environ.get("CHORES_REPO_NAME") or "chores"
|
||||||
EXPIRY_DAYS = int(os.environ.get("CHORES_EXPIRY_DAYS", 2))
|
EXPIRY_DAYS = int(os.environ.get("CHORES_EXPIRY_DAYS") or 2)
|
||||||
CHORES = os.environ.get(
|
CHORES = (
|
||||||
"CHORES_TEXT", "Looks like you forgot to set the CHORES_TEXT environment variable."
|
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()
|
due_date = (datetime.utcnow() + timedelta(days=EXPIRY_DAYS)).isoformat()
|
||||||
|
|
||||||
payload = {
|
payload = {
|
||||||
|
|
Loading…
Reference in a new issue