GitPasha MCP Server - Ready for deployment

هذا الالتزام موجود في:
2025-11-22 16:18:29 +02:00
التزام fb1476f28a
35 ملفات معدلة مع 1545 إضافات و0 حذوفات

17
tools/__init__.py Normal file
عرض الملف

@@ -0,0 +1,17 @@
from tools.repo_create import repo_create_tool
from tools.repo_update import repo_update_tool
from tools.repo_delete import repo_delete_tool
from tools.issue_list import issue_list_tool
from tools.issue_create import issue_create_tool
from tools.issue_update import issue_update_tool
from tools.pr_open import pr_open_tool
__all__ = [
"repo_create_tool",
"repo_update_tool",
"repo_delete_tool",
"issue_list_tool",
"issue_create_tool",
"issue_update_tool",
"pr_open_tool",
]

39
tools/issue_create.py Normal file
عرض الملف

@@ -0,0 +1,39 @@
import json
from helpers import format_error, log
from api import api_create_issue
import httpx
def issue_create_tool(
repo: str,
title: str,
body: str = "",
labels_csv: str = "",
assignees_csv: str = ""
) -> str:
try:
labels = [
x.strip() for x in labels_csv.split(",") if x.strip()
] if labels_csv else None
assignees = [
x.strip() for x in assignees_csv.split(",") if x.strip()
] if assignees_csv else None
item = api_create_issue(
repo,
title=title,
body=body,
labels=labels,
assignees=assignees
)
return json.dumps(
{
"status": "success",
"item": item
},
ensure_ascii=False
)
except httpx.HTTPStatusError as e:
return format_error("Issue create failed", e)
except Exception as e:
log.exception("Unexpected error while creating issue")
return f"{e}"

25
tools/issue_list.py Normal file
عرض الملف

@@ -0,0 +1,25 @@
import json
from helpers import format_error, log
from api import api_list_issues
import httpx
def issue_list_tool(repo: str, state: str = "open") -> str:
try:
items = api_list_issues(
repo,
state if state in ("open", "closed", "all") else None
)
return json.dumps(
{
"status": "success",
"count": len(items),
"items": items
},
ensure_ascii=False
)
except httpx.HTTPStatusError as e:
return format_error("Issues list failed", e)
except Exception as e:
log.exception("Unexpected error while listing issues")
return f"{e}"

49
tools/issue_update.py Normal file
عرض الملف

@@ -0,0 +1,49 @@
import json
from helpers import format_error, log
from api import api_update_issue
import httpx
def issue_update_tool(
repo: str,
issue: str,
title: str = "",
body: str = "",
state: str = "",
labels_csv: str = "",
assignees_csv: str = "",
comment: str = "",
) -> str:
try:
labels = [
x.strip() for x in labels_csv.split(",") if x.strip()
] if labels_csv else None
assignees = [
x.strip() for x in assignees_csv.split(",") if x.strip()
] if assignees_csv else None
st = state or None
t = title or None
b = body or None
c = comment or None
out = api_update_issue(
repo,
issue,
title=t,
body=b,
state=st,
labels=labels,
assignees=assignees,
comment=c
)
return json.dumps(
{
"status": "success",
"result": out
},
ensure_ascii=False
)
except httpx.HTTPStatusError as e:
return format_error("Issue update failed", e)
except Exception as e:
log.exception("Unexpected error while updating issue")
return f"{e}"

33
tools/pr_open.py Normal file
عرض الملف

@@ -0,0 +1,33 @@
import json
from helpers import format_error, log
from api import api_open_pr
import httpx
def pr_open_tool(
repo: str,
title: str,
head: str,
base: str,
body: str = ""
) -> str:
try:
pr = api_open_pr(
repo,
title=title,
head=head,
base=base,
body=body
)
return json.dumps(
{
"status": "success",
"pr": pr
},
ensure_ascii=False
)
except httpx.HTTPStatusError as e:
return format_error("PR open failed", e)
except Exception as e:
log.exception("Unexpected error while opening PR")
return f"{e}"

47
tools/repo_create.py Normal file
عرض الملف

@@ -0,0 +1,47 @@
import os
import json
import asyncio
from helpers import log, format_error, suggest_description
from api import api_create_repo, api_create_readme
import httpx
def repo_create_tool(
name: str,
description: str = "",
private: bool = False,
create_readme: bool = True,
readme_content: str = "# Test Repository\n\nThis repository is for testing.\n",
) -> str:
api_key = os.getenv("GITPASHA_API_KEY", "")
if not api_key:
return "GITPASHA_API_KEY not set"
desc = description or suggest_description(name)
log.info(f"Creating repo: {name}")
try:
repo = api_create_repo(name, desc, private)
repo_id = repo.get("full_name") or repo.get("name") or name
repo_url = repo.get("html_url") or repo.get("web_url") or "N/A"
readme_status = "skipped"
if create_readme:
try:
r = api_create_readme(str(repo_id), readme_content)
readme_status = "created" if "error" not in r else "failed"
except Exception as e:
readme_status = f"failed: {e}"
result = {
"status": "success",
"name": name,
"description": desc,
"private": private,
"repo_url": repo_url,
"readme": readme_status
}
return json.dumps(result, ensure_ascii=False, indent=2)
except httpx.HTTPStatusError as e:
return format_error("Repo creation failed", e)
except Exception as e:
log.exception("Unexpected error")
return f"{e}"

22
tools/repo_delete.py Normal file
عرض الملف

@@ -0,0 +1,22 @@
import json
from helpers import format_error, log
from api import api_delete_repo
import httpx
def repo_delete_tool(repo: str) -> str:
try:
out = api_delete_repo(repo)
return json.dumps(
{
"status": "success",
"repo": repo,
"result": out
},
ensure_ascii=False
)
except httpx.HTTPStatusError as e:
return format_error("Repo delete failed", e)
except Exception as e:
log.exception("Unexpected error while deleting repo")
return f"{e}"

36
tools/repo_update.py Normal file
عرض الملف

@@ -0,0 +1,36 @@
import json
from helpers import format_error, log
from api import api_update_repo
import httpx
def repo_update_tool(
repo: str,
name: str = "",
description: str = "",
set_private: bool = False,
private: bool = False,
) -> str:
try:
new_name = name or None
new_desc = description or None
new_priv = private if set_private else None
out = api_update_repo(
repo,
name=new_name,
description=new_desc,
private=new_priv
)
return json.dumps(
{
"status": "success",
"repo": repo,
"result": out
},
ensure_ascii=False
)
except httpx.HTTPStatusError as e:
return format_error("Repo update failed", e)
except Exception as e:
log.exception("Unexpected error while updating repo")
return f"{e}"