40 أسطر
874 B
Python
40 أسطر
874 B
Python
import os
|
|
from typing import Dict, Any
|
|
from helpers import get_headers, build_client
|
|
|
|
BASE_URL = os.getenv(
|
|
"GITPASHA_BASE_URL",
|
|
"https://app.gitpasha.com/api/v1"
|
|
).rstrip("/")
|
|
|
|
|
|
def api_open_pr(
|
|
repo: str,
|
|
title: str,
|
|
head: str,
|
|
base: str,
|
|
body: str = ""
|
|
) -> Dict[str, Any]:
|
|
username = os.getenv("GITPASHA__USERNAME", "")
|
|
|
|
if "/" not in repo:
|
|
if not username:
|
|
raise ValueError("GITPASHA__USERNAME not set in .env")
|
|
repo = f"{username}/{repo}"
|
|
|
|
payload = {
|
|
"title": title,
|
|
"head": head,
|
|
"base": base,
|
|
"body": body
|
|
}
|
|
with build_client() as client:
|
|
url = f"{BASE_URL}/repos/{repo}/pulls"
|
|
res = client.post(
|
|
url,
|
|
headers=get_headers(),
|
|
json=payload
|
|
)
|
|
res.raise_for_status()
|
|
return res.json()
|