Spaces:
Sleeping
Sleeping
| import requests | |
| from config import GITHUB_REPO, GITHUB_TOKEN | |
| def create_github_issue(title: str, description: str) -> str: | |
| """Create a GitHub issue if credentials are configured.""" | |
| if not GITHUB_TOKEN or not GITHUB_REPO: | |
| return "Ticketing is not configured. Set GITHUB_TOKEN and GITHUB_REPO." | |
| url = f"https://api.github.com/repos/{GITHUB_REPO}/issues" | |
| headers = { | |
| "Authorization": f"token {GITHUB_TOKEN}", | |
| "Accept": "application/vnd.github+json", | |
| } | |
| data = {"title": title, "body": description} | |
| response = requests.post(url, json=data, headers=headers, timeout=20) | |
| if response.status_code == 201: | |
| return response.json().get("html_url", "Ticket created.") | |
| return f"Failed to create ticket ({response.status_code}): {response.text}" | |