Files
Gitea-Tools/create_pr.py
T
2026-06-21 15:35:57 -04:00

45 lines
1.2 KiB
Python
Executable File

import sys
import json
import urllib.request
import subprocess
import base64
host = "gitea.dadeschools.net"
org = "Contractor"
repo = "Timesheet"
p = subprocess.Popen(["git", "credential", "fill"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True)
out, _ = p.communicate(f"protocol=https\nhost=gitea.dadeschools.net\n\n")
user = ""
password = ""
for line in out.splitlines():
if line.startswith("username="):
user = line.split("=")[1]
if line.startswith("password="):
password = line.split("=")[1]
if not user or not password:
print("Could not get credentials")
sys.exit(1)
url = f"https://{host}/api/v1/repos/{org}/{repo}/pulls"
data = {
"title": "feat: Support PTO, Sick, Holiday, and Unpaid days",
"body": "Closes #6",
"head": "feat/6-absence-categories",
"base": "main"
}
req = urllib.request.Request(url, data=json.dumps(data).encode("utf-8"), headers={
"Content-Type": "application/json",
})
auth_b64 = base64.b64encode(f"{user}:{password}".encode("utf-8")).decode("utf-8")
req.add_header("Authorization", f"Basic {auth_b64}")
try:
with urllib.request.urlopen(req) as response:
print(response.read().decode())
except urllib.error.HTTPError as e:
print("Error:", e.read().decode())