68c112d2c8
Ports dirigent's gitea scripts into a self-contained reliquary plugin. Scripts run via uv with PEP 723 inline deps — no project venv needed. Gitea connection inferred from `git remote get-url origin` with env-var overrides; only GITEA_TOKEN is mandatory. Workpad path and tickets directory are parameterized so the plugin works in any project. Label set externalized to labels.default.json with project-level override via .gitea-labels.json. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
65 lines
1.9 KiB
Python
65 lines
1.9 KiB
Python
#!/usr/bin/env python3
|
|
# /// script
|
|
# requires-python = ">=3.11"
|
|
# dependencies = ["httpx", "pydantic>=2", "python-dotenv"]
|
|
# ///
|
|
"""Set up labels in the configured Gitea repository.
|
|
|
|
Lookup order for the label set:
|
|
1. `.gitea-labels.json` in CWD (project override, total replacement of defaults).
|
|
2. `labels.default.json` shipped with the plugin (one level up from this script).
|
|
|
|
Skips labels that already exist in the repo (name match, case-insensitive).
|
|
|
|
Usage:
|
|
uv run setup_labels.py
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
from client import GiteaClient
|
|
from config import load_config
|
|
|
|
|
|
def load_labels() -> list[dict]:
|
|
project_override = Path.cwd() / ".gitea-labels.json"
|
|
if project_override.exists():
|
|
source = project_override
|
|
else:
|
|
source = Path(__file__).resolve().parent.parent / "labels.default.json"
|
|
if not source.exists():
|
|
print(f"Error: no labels file found at {source}", file=sys.stderr)
|
|
sys.exit(1)
|
|
data = json.loads(source.read_text(encoding="utf-8"))
|
|
if not isinstance(data, list):
|
|
print(f"Error: {source} must contain a JSON array of label objects.", file=sys.stderr)
|
|
sys.exit(1)
|
|
return data
|
|
|
|
|
|
def main() -> None:
|
|
labels = load_labels()
|
|
config = load_config()
|
|
with GiteaClient(config) as client:
|
|
existing = {label.name.lower() for label in client.list_labels()}
|
|
for label in labels:
|
|
name = label["name"]
|
|
if name.lower() in existing:
|
|
print(f" skip {name} (already exists)")
|
|
else:
|
|
client.create_label(
|
|
name,
|
|
label.get("color", "#cccccc"),
|
|
label.get("description", ""),
|
|
)
|
|
print(f" created {name}")
|
|
print("Done.")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|