Add automated chores issue creation workflow

Implemented a new Forgejo Action workflow to automatically create weekly
chores issues based on a Python script. This workflow triggers on
commits and the Python script uses project-specific environment
variables to customize the issue creation, including setting due dates
and assigning users. Streamlines project maintenance and ensures regular
task management.
This commit is contained in:
Kumi 2024-02-18 11:46:52 +01:00
parent 7a23fb6cf0
commit 94cd8089b1
Signed by: kumi
GPG key ID: ECBCC9082395383F
2 changed files with 60 additions and 0 deletions

View file

@ -0,0 +1,9 @@
on: [commit]
#schedule:
# - cron: '0 12 * * 5'
jobs:
chores:
steps:
- name: Create Chores Issue
run: python3 scripts/chores.py

51
scripts/chores.py Normal file
View file

@ -0,0 +1,51 @@
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", "https://git.private.coffee")
try:
TOKEN = os.environ["FORGEJO_TOKEN"]
except KeyError:
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", "PrivateCoffee")
REPO_NAME = os.environ.get("CHORES_REPO_NAME", "chores")
EXPIRY_DAYS = os.environ.get("CHORES_EXPIRY_DAYS", 2)
CHORES = os.environ.get(
"CHORES_TEXT", "Looks like you forgot to set the CHORES_TEXT environment variable."
)
due_date = (datetime.utcnow() + timedelta(days=EXPIRY_DAYS)).isoformat()
payload = {
"token": TOKEN,
"title": "Weekly Chores",
"body": CHORES,
"due_date": due_date,
}
if ASSIGNEES:
payload["assignees"] = ASSIGNEES
headers = {
"Content-Type": "application/json",
"Accept": "application/json",
}
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"))