56 lines
1.6 KiB
Python
56 lines
1.6 KiB
Python
from forgeclient import request
|
|
|
|
|
|
def _repo_summary(r):
|
|
"""Trim a full repo object down to the fields an agent actually needs."""
|
|
return {
|
|
"full_name": r.get("full_name"),
|
|
"description": r.get("description"),
|
|
"private": r.get("private"),
|
|
"default_branch": r.get("default_branch"),
|
|
"html_url": r.get("html_url"),
|
|
"clone_url": r.get("clone_url"),
|
|
"stars": r.get("stars_count"),
|
|
"updated_at": r.get("updated_at"),
|
|
}
|
|
|
|
|
|
def get_me():
|
|
user = request("GET", "/user")
|
|
if "error" in user:
|
|
return user
|
|
return {
|
|
"login": user.get("login"),
|
|
"full_name": user.get("full_name"),
|
|
"html_url": user.get("html_url"),
|
|
"is_admin": user.get("is_admin"),
|
|
}
|
|
|
|
|
|
def list_repos(limit=30):
|
|
limit = max(1, min(limit, 50))
|
|
data = request("GET", "/user/repos", params={"limit": limit})
|
|
if isinstance(data, dict) and "error" in data:
|
|
return data
|
|
return [_repo_summary(r) for r in data]
|
|
|
|
|
|
def create_repo(name, description="", private=False, auto_init=True,
|
|
default_branch="main", gitignores="", readme=""):
|
|
body = {
|
|
"name": name,
|
|
"description": description,
|
|
"private": bool(private),
|
|
"auto_init": bool(auto_init),
|
|
"default_branch": default_branch,
|
|
}
|
|
# .gitignore / README templates only apply when the repo is auto-initialized
|
|
if auto_init and gitignores:
|
|
body["gitignores"] = gitignores
|
|
if auto_init and readme:
|
|
body["readme"] = readme
|
|
|
|
r = request("POST", "/user/repos", json=body)
|
|
if "error" in r:
|
|
return r
|
|
return _repo_summary(r)
|