GitPasha MCP Server - Ready for deployment
هذا الالتزام موجود في:
9
api/issues/__init__.py
Normal file
9
api/issues/__init__.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from api.issues.list import api_list_issues
|
||||
from api.issues.create import api_create_issue
|
||||
from api.issues.update import api_update_issue
|
||||
|
||||
__all__ = [
|
||||
"api_list_issues",
|
||||
"api_create_issue",
|
||||
"api_update_issue"
|
||||
]
|
||||
39
api/issues/create.py
Normal file
39
api/issues/create.py
Normal file
@@ -0,0 +1,39 @@
|
||||
import os
|
||||
from typing import Dict, Any, Optional, List
|
||||
from helpers import get_headers, build_client
|
||||
|
||||
BASE_URL = os.getenv(
|
||||
"GITPASHA_BASE_URL",
|
||||
"https://app.gitpasha.com/api/v1"
|
||||
).rstrip("/")
|
||||
|
||||
|
||||
def api_create_issue(
|
||||
repo: str,
|
||||
title: str,
|
||||
body: str = "",
|
||||
labels: Optional[List[str]] = None,
|
||||
assignees: Optional[List[str]] = None
|
||||
) -> 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: Dict[str, Any] = {"title": title, "body": body}
|
||||
if labels:
|
||||
payload["labels"] = labels
|
||||
if assignees:
|
||||
payload["assignees"] = assignees
|
||||
with build_client() as client:
|
||||
url = f"{BASE_URL}/repos/{repo}/issues"
|
||||
res = client.post(
|
||||
url,
|
||||
headers=get_headers(),
|
||||
json=payload
|
||||
)
|
||||
res.raise_for_status()
|
||||
data = res.json()
|
||||
return data
|
||||
38
api/issues/list.py
Normal file
38
api/issues/list.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import os
|
||||
from typing import List, Dict, Any, Optional
|
||||
from helpers import get_headers, build_client
|
||||
|
||||
|
||||
BASE_URL = os.getenv(
|
||||
"GITPASHA_BASE_URL",
|
||||
"https://app.gitpasha.com/api/v1"
|
||||
).rstrip("/")
|
||||
|
||||
|
||||
def api_list_issues(
|
||||
repo: str,
|
||||
state: Optional[str] = None
|
||||
) -> List[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}"
|
||||
|
||||
params = {}
|
||||
if state:
|
||||
params["state"] = state
|
||||
with build_client() as client:
|
||||
url = f"{BASE_URL}/repos/{repo}/issues"
|
||||
res = client.get(
|
||||
url,
|
||||
headers=get_headers(),
|
||||
params=params
|
||||
)
|
||||
res.raise_for_status()
|
||||
try:
|
||||
data = res.json()
|
||||
except Exception:
|
||||
data = []
|
||||
return data
|
||||
78
api/issues/update.py
Normal file
78
api/issues/update.py
Normal file
@@ -0,0 +1,78 @@
|
||||
import os
|
||||
from typing import Dict, Any, Optional, List
|
||||
from helpers import get_headers, build_client
|
||||
|
||||
BASE_URL = os.getenv(
|
||||
"GITPASHA_BASE_URL",
|
||||
"https://app.gitpasha.com/api/v1"
|
||||
).rstrip("/")
|
||||
|
||||
|
||||
def api_update_issue(
|
||||
repo: str,
|
||||
issue: str,
|
||||
title: Optional[str] = None,
|
||||
body: Optional[str] = None,
|
||||
state: Optional[str] = None,
|
||||
labels: Optional[List[str]] = None,
|
||||
assignees: Optional[List[str]] = None,
|
||||
comment: Optional[str] = None
|
||||
) -> Dict[str, Any]:
|
||||
repo = repo.strip()
|
||||
issue = issue.strip()
|
||||
|
||||
username = os.getenv("GITPASHA__USERNAME", "")
|
||||
|
||||
if "/" not in repo:
|
||||
if not username:
|
||||
raise ValueError("GITPASHA__USERNAME not set in .env")
|
||||
repo = f"{username}/{repo}"
|
||||
|
||||
out: Dict[str, Any] = {}
|
||||
with build_client() as client:
|
||||
patch_payload: Dict[str, Any] = {}
|
||||
if title is not None:
|
||||
patch_payload["title"] = title
|
||||
if body is not None:
|
||||
patch_payload["body"] = body
|
||||
if state is not None:
|
||||
patch_payload["state"] = state
|
||||
if labels is not None:
|
||||
patch_payload["labels"] = labels
|
||||
if assignees is not None:
|
||||
patch_payload["assignees"] = assignees
|
||||
|
||||
if patch_payload:
|
||||
url = f"{BASE_URL}/repos/{repo}/issues/{issue}"
|
||||
res = client.patch(
|
||||
url,
|
||||
headers=get_headers(),
|
||||
json=patch_payload
|
||||
)
|
||||
|
||||
if res.status_code == 405:
|
||||
res = client.put(
|
||||
url,
|
||||
headers=get_headers(),
|
||||
json=patch_payload
|
||||
)
|
||||
res.raise_for_status()
|
||||
out["update"] = res.json() if res.text else {"status": "ok"}
|
||||
|
||||
if comment:
|
||||
url_c = f"{BASE_URL}/repos/{repo}/issues/{issue}/comments"
|
||||
res_c = client.post(
|
||||
url_c,
|
||||
headers=get_headers(),
|
||||
json={
|
||||
"body": comment
|
||||
}
|
||||
)
|
||||
res_c.raise_for_status()
|
||||
out["comment"] = res_c.json() if res_c.text else {
|
||||
"status": "commented"
|
||||
}
|
||||
|
||||
return out or {
|
||||
"status": "no-op"
|
||||
}
|
||||
المرجع في مشكلة جديدة
حظر مستخدم