V0.38.4 full composition (#237)

Co-authored-by: gobha <jasafpro@gmail.com>
Co-committed-by: gobha <jasafpro@gmail.com>
This commit is contained in:
2026-03-25 17:29:08 +00:00
committed by xcaliber
parent fe5894b6e2
commit 495bcc94f4
17 changed files with 943 additions and 39 deletions

View File

@@ -0,0 +1,25 @@
# gitea-client — CI status operations
load("star/http_helpers.star", "gitea_get")
def get_ci_status(conn, owner, repo, ref):
"""Get CI/CD job status for a commit or branch reference."""
path = "/repos/" + owner + "/" + repo + "/commits/" + ref + "/status"
data = gitea_get(conn, path)
if data == None:
return None
statuses = data.get("statuses", [])
items = []
for s in statuses:
items.append({
"context": s.get("context", s.get("name", "")),
"state": s.get("state", s.get("status", "")),
"description": s.get("description", ""),
"target_url": s.get("target_url", ""),
})
return {
"ref": ref,
"state": data.get("state", ""),
"statuses": items,
"count": len(items),
}

View File

@@ -0,0 +1,60 @@
# gitea-client — HTTP helpers
#
# Shared HTTP utilities for Gitea API calls.
# All functions take a `conn` dict from connections.get("gitea").
def auth_headers(conn):
"""Build authorization headers from a connection dict."""
token = conn.get("api_token", "")
if not token:
return {}
return {"Authorization": "token " + token}
def _base(conn):
"""Return base URL with trailing slash stripped."""
url = conn.get("base_url", "")
if url.endswith("/"):
url = url[:-1]
return url
def gitea_get(conn, path):
"""GET request to Gitea API. Returns decoded body or None."""
url = _base(conn) + "/api/v1" + path
resp = http.get(url=url, headers=auth_headers(conn))
if int(resp["status"]) >= 400:
return None
body = resp.get("body", "")
if not body:
return None
return json.decode(body)
def gitea_post(conn, path, data):
"""POST request to Gitea API. Returns decoded body or None."""
url = _base(conn) + "/api/v1" + path
hdrs = dict(auth_headers(conn), **{"Content-Type": "application/json"})
resp = http.post(url=url, body=json.encode(data), headers=hdrs)
if int(resp["status"]) >= 400:
return None
body = resp.get("body", "")
if not body:
return None
return json.decode(body)
def gitea_patch(conn, path, data):
"""PATCH request to Gitea API (via X-HTTP-Method-Override). Returns decoded body or None."""
url = _base(conn) + "/api/v1" + path
hdrs = dict(auth_headers(conn), **{
"Content-Type": "application/json",
"X-HTTP-Method-Override": "PATCH",
})
resp = http.post(url=url, body=json.encode(data), headers=hdrs)
if int(resp["status"]) >= 400:
return None
body = resp.get("body", "")
if not body:
return None
return json.decode(body)
def resp(status, data):
"""Build a standard JSON response dict."""
return {"status": status, "body": json.encode(data), "headers": {"Content-Type": "application/json"}}

View File

@@ -0,0 +1,91 @@
# gitea-client — Issue operations
load("star/http_helpers.star", "gitea_get", "gitea_post", "gitea_patch")
def get_issues(conn, owner, repo, state):
"""List issues for a repository."""
state = state or "open"
path = "/repos/" + owner + "/" + repo + "/issues?state=" + state + "&limit=50&type=issues"
data = gitea_get(conn, path)
if data == None:
return None
items = []
for i in data:
labels = [l.get("name", "") for l in (i.get("labels") or [])]
items.append({
"number": i.get("number", 0),
"title": i.get("title", ""),
"state": i.get("state", ""),
"labels": labels,
"assignee": (i.get("assignee") or {}).get("login", ""),
})
return items
def get_issue(conn, owner, repo, number):
"""Get full issue details including comments."""
path = "/repos/" + owner + "/" + repo + "/issues/" + str(number)
data = gitea_get(conn, path)
if data == None:
return None
comments_data = gitea_get(conn, path + "/comments") or []
comments = []
for c in comments_data:
comments.append({
"user": (c.get("user") or {}).get("login", ""),
"body": c.get("body", ""),
"created_at": c.get("created_at", ""),
})
return {
"number": data.get("number", 0),
"title": data.get("title", ""),
"body": data.get("body", ""),
"state": data.get("state", ""),
"labels": [l.get("name", "") for l in (data.get("labels") or [])],
"assignee": (data.get("assignee") or {}).get("login", ""),
"created_at": data.get("created_at", ""),
"comments": comments,
}
def create_issue(conn, owner, repo, title, body, labels):
"""Create a new issue."""
path = "/repos/" + owner + "/" + repo + "/issues"
payload = {"title": title}
if body:
payload["body"] = body
if labels:
payload["labels"] = [l.strip() for l in labels.split(",") if l.strip()]
data = gitea_post(conn, path, payload)
if data == None:
return None
return {
"number": data.get("number", 0),
"title": data.get("title", ""),
"html_url": data.get("html_url", ""),
}
def update_issue(conn, owner, repo, number, title, body, state):
"""Update an existing issue."""
path = "/repos/" + owner + "/" + repo + "/issues/" + str(number)
patch = {}
if title:
patch["title"] = title
if body:
patch["body"] = body
if state:
patch["state"] = state
data = gitea_patch(conn, path, patch)
if data == None:
return None
return {
"number": data.get("number", 0),
"state": data.get("state", ""),
"title": data.get("title", ""),
}
def add_comment(conn, owner, repo, number, body):
"""Add a comment to an issue."""
path = "/repos/" + owner + "/" + repo + "/issues/" + str(number) + "/comments"
data = gitea_post(conn, path, {"body": body})
if data == None:
return None
return {"id": data.get("id", 0), "body": data.get("body", "")}

View File

@@ -0,0 +1,21 @@
# gitea-client — Repository operations
load("star/http_helpers.star", "gitea_get")
def get_repos(conn):
"""List repositories accessible via the connection."""
data = gitea_get(conn, "/repos/search?limit=50&sort=updated")
if data == None:
return None
repos = data if type(data) == "list" else data.get("data", [])
out = []
for r in repos:
out.append({
"full_name": r.get("full_name", ""),
"name": r.get("name", ""),
"owner": r.get("owner", {}).get("login", ""),
"description": r.get("description", ""),
"html_url": r.get("html_url", ""),
"open_issues": r.get("open_issues_count", 0),
})
return out