File size: 806 Bytes
9a2d4ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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}"