Files
timmy-config/training-data/code-patterns-gitea-api-&-forge.jsonl
Alexander Whitestone 71f25dbd99
Some checks failed
Smoke Test / smoke (pull_request) Failing after 22s
Architecture Lint / Linter Tests (pull_request) Successful in 26s
Validate Config / YAML Lint (pull_request) Failing after 16s
Validate Config / JSON Validate (pull_request) Successful in 18s
Validate Config / Python Syntax & Import Check (pull_request) Failing after 58s
Validate Config / Python Test Suite (pull_request) Has been skipped
Validate Config / Shell Script Lint (pull_request) Failing after 1m1s
Validate Config / Cron Syntax Check (pull_request) Successful in 14s
Validate Config / Deploy Script Dry Run (pull_request) Successful in 15s
Validate Config / Playbook Schema Validation (pull_request) Successful in 27s
Validate Training Data / validate (pull_request) Successful in 22s
PR Checklist / pr-checklist (pull_request) Successful in 4m49s
Architecture Lint / Lint Repository (pull_request) Failing after 12s
feat: 1K Gitea API & Forge code-pattern training pairs (#591)
- training/build_code_patterns_gitea.py: deterministic generator
  covering 4 domains (gitea_api, repo_management, issue_automation,
  pr_workflow) with 250 pairs each.
- Prompt/response format with provenance metadata (id, domain, tags,
  source_issue).
- Output committed to training-data/ and mirrored to ~/.hermes/training-data/.

Closes #591
2026-04-22 01:36:40 -04:00

1001 lines
827 KiB
JSON

{"id": "pr_workflow_0076", "domain": "pr_workflow", "prompt": "Design a concise Python snippet that Write a Python function that creates a pull request on Gitea via API. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef create_pull_request(repo: str, title: str, head: str, base: str, body: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls\"\n data = {\"title\": title, \"head\": head, \"base\": base, \"body\": body}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0167", "domain": "gitea_api", "prompt": "Build a reusable module function that Write a Python function that serializes a Python dict into JSON and sends it as the body of a PATCH request to Gitea. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef gitea_patch(base_url: str, path: str, token: str, data: dict):\n \"\"\"Serialize dict to JSON and PATCH.\"\"\"\n url = f\"{base_url.rstrip('/')}/api/v1{path}\"\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0159", "domain": "repo_management", "prompt": "Draft a minimal but complete solution that Write a Python function that clones a Gitea repo with --depth 1 for a shallow clone. Include docstrings and type hints.", "response": "import subprocess\n\ndef shallow_clone(repo_url: str, dest: str, branch: str = \"main\"):\n \"\"\"Clone with --depth 1 to save time and space.\"\"\"\n subprocess.run(\n [\"git\", \"clone\", \"--depth\", \"1\", \"--branch\", branch, repo_url, dest],\n check=True,\n capture_output=True,\n )\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0184", "domain": "gitea_api", "prompt": "Create a typed Python utility that Write a Python function that sets proper request headers (Authorization, Content-Type, Accept) for Gitea API calls. Optimize for minimal external dependencies.", "response": "def build_gitea_request(url: str, token: str, method: str = \"GET\", data: bytes | None = None):\n \"\"\"Build a request with standard headers.\"\"\"\n req = urllib.request.Request(url, data=data, method=method)\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n req.add_header(\"Accept\", \"application/json\")\n return req\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0027", "domain": "repo_management", "prompt": "Build a reusable module function that Write a Python function that lists all repos in a Gitea organization with pagination. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef list_org_repos(org: str, token: str, limit: int = 50, page: int = 1):\n url = f\"https://forge.example.com/api/v1/orgs/{org}/repos?limit={limit}&page={page}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0132", "domain": "pr_workflow", "prompt": "Using only the Python standard library, Write a Python function that checks whether a Gitea pull request is mergeable. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef is_mergeable(repo: str, pr_number: int, token: str) -> bool:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n data = json.loads(resp.read().decode())\n return data.get(\"mergeable\", False)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0239", "domain": "pr_workflow", "prompt": "Draft a minimal but complete solution that Write a Python function that approves a Gitea pull request via API. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef approve_pr(repo: str, pr_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/reviews\"\n data = {\"body\": \"LGTM\", \"event\": \"APPROVE\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0001", "domain": "gitea_api", "prompt": "Write a Python function that pings a Gitea instance to check if it is alive. Include error handling.", "response": "import urllib.request\nimport urllib.error\nimport json\n\ndef ping_gitea(base_url: str) -> bool:\n \"\"\"Check if Gitea is responding.\"\"\"\n try:\n req = urllib.request.Request(f\"{base_url}/api/v1/version\")\n with urllib.request.urlopen(req, timeout=5) as resp:\n return resp.status == 200\n except Exception:\n return False\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0008", "domain": "issue_automation", "prompt": "Author a defensive Python routine that Write a Python function that searches Gitea issues across an organization by keyword. Include error handling.", "response": "import urllib.request\nimport json\n\ndef search_issues(org: str, keyword: str, token: str):\n url = f\"https://forge.example.com/api/v1/repos/search?q={keyword}&uid=0&limit=50\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0202", "domain": "issue_automation", "prompt": "Using only the Python standard library, Write a Python function that filters Gitea issues by label name. Add timeout and connection cleanup.", "response": "def filter_by_label(issues: list[dict], label: str) -> list[dict]:\n return [i for i in issues if any(l.get(\"name\") == label for l in i.get(\"labels\", []))]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0045", "domain": "gitea_api", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that creates a reusable urllib Request object with authentication for repeated Gitea API calls. Add retry logic with exponential backoff.", "response": "import urllib.request\n\nclass AuthenticatedRequest:\n def __init__(self, base_url: str, token: str):\n self.base_url = base_url.rstrip(\"/\")\n self.token = token\n\n def build(self, path: str, method: str = \"GET\", data: bytes | None = None):\n url = f\"{self.base_url}/api/v1{path}\"\n req = urllib.request.Request(url, data=data, method=method)\n req.add_header(\"Authorization\", f\"token {self.token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n return req\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0197", "domain": "issue_automation", "prompt": "Build a reusable module function that Write a Python function that sets a milestone on a Gitea issue. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef set_milestone(repo: str, issue_number: int, milestone_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{issue_number}\"\n data = {\"milestone\": milestone_id}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0142", "domain": "gitea_api", "prompt": "Using only the Python standard library, Write a Python function that serializes a Python dict into JSON and sends it as the body of a PATCH request to Gitea. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef gitea_patch(base_url: str, path: str, token: str, data: dict):\n \"\"\"Serialize dict to JSON and PATCH.\"\"\"\n url = f\"{base_url.rstrip('/')}/api/v1{path}\"\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0220", "domain": "pr_workflow", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that generates a release notes draft from merged PRs since the last tag. Add timeout and connection cleanup.", "response": "def generate_release_notes(merged_prs: list[dict], tag: str) -> str:\n lines = [f\"## Release {tag}\", \"\"]\n for pr in merged_prs:\n lines.append(f\"- #{pr['number']} {pr['title']}\")\n return \"\n\".join(lines)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0024", "domain": "gitea_api", "prompt": "Create a typed Python utility that Write a Python function that attaches a custom User-Agent header to all Gitea API requests. Include error handling.", "response": "import urllib.request\n\ndef request_with_user_agent(url: str, token: str, agent: str = \"timmy-bot/1.0\"):\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"User-Agent\", agent)\n return req\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0170", "domain": "gitea_api", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that creates a reusable urllib Request object with authentication for repeated Gitea API calls. Include docstrings and type hints.", "response": "import urllib.request\n\nclass AuthenticatedRequest:\n def __init__(self, base_url: str, token: str):\n self.base_url = base_url.rstrip(\"/\")\n self.token = token\n\n def build(self, path: str, method: str = \"GET\", data: bytes | None = None):\n url = f\"{self.base_url}/api/v1{path}\"\n req = urllib.request.Request(url, data=data, method=method)\n req.add_header(\"Authorization\", f\"token {self.token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n return req\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0041", "domain": "gitea_api", "prompt": "Write a Python function that implements rate-limit awareness by reading the X-RateLimit-Remaining header. Add retry logic with exponential backoff.", "response": "import urllib.request\n\ndef check_rate_limit(resp: urllib.request.addinfourl) -> int:\n \"\"\"Read X-RateLimit-Remaining from response headers.\"\"\"\n remaining = resp.headers.get(\"X-RateLimit-Remaining\")\n return int(remaining) if remaining else -1\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0172", "domain": "gitea_api", "prompt": "Using only the Python standard library, Write a Python function that parses a Gitea API error response and extracts the human-readable message. Include docstrings and type hints.", "response": "import json\nimport urllib.error\n\ndef parse_error_body(e: urllib.error.HTTPError) -> str:\n \"\"\"Extract human-readable message from Gitea error response.\"\"\"\n try:\n body = json.loads(e.read().decode())\n return body.get(\"message\", str(e))\n except Exception:\n return str(e)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0099", "domain": "gitea_api", "prompt": "Draft a minimal but complete solution that Write a Python function that attaches a custom User-Agent header to all Gitea API requests. Log all failures for observability.", "response": "import urllib.request\n\ndef request_with_user_agent(url: str, token: str, agent: str = \"timmy-bot/1.0\"):\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"User-Agent\", agent)\n return req\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0221", "domain": "pr_workflow", "prompt": "Write a Python function that adds a label to a Gitea pull request. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef add_pr_label(repo: str, pr_number: int, label_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/labels\"\n data = {\"labels\": [label_id]}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0183", "domain": "gitea_api", "prompt": "Write a robust, production-ready function that Write a Python function that wraps the Gitea API in a typed dataclass response (Issue, PR, Comment). Optimize for minimal external dependencies.", "response": "from dataclasses import dataclass\nfrom typing import Any\n\n@dataclass\nclass Issue:\n number: int\n title: str\n state: str\n\n @classmethod\n def from_dict(cls, d: dict) -> \"Issue\":\n return cls(\n number=d.get(\"number\", 0),\n title=d.get(\"title\", \"\"),\n state=d.get(\"state\", \"\"),\n )\n\ndef parse_issues(raw: list[dict]) -> list[Issue]:\n \"\"\"Convert raw API response into typed Issue objects.\"\"\"\n return [Issue.from_dict(i) for i in raw]\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0027", "domain": "issue_automation", "prompt": "Build a reusable module function that Write a Python function that filters Gitea issues by label name. Add retry logic with exponential backoff.", "response": "def filter_by_label(issues: list[dict], label: str) -> list[dict]:\n return [i for i in issues if any(l.get(\"name\") == label for l in i.get(\"labels\", []))]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0077", "domain": "repo_management", "prompt": "Build a reusable module function that Write a Python function that lists all repos in a Gitea organization with pagination. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef list_org_repos(org: str, token: str, limit: int = 50, page: int = 1):\n url = f\"https://forge.example.com/api/v1/orgs/{org}/repos?limit={limit}&page={page}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0127", "domain": "gitea_api", "prompt": "Build a reusable module function that Write a Python function that reads a Gitea API token from standard local paths and returns it. Handle empty responses gracefully.", "response": "from pathlib import Path\n\ndef read_gitea_token() -> str:\n \"\"\"Read token from standard locations.\"\"\"\n for path in [\n Path.home() / \".hermes\" / \"gitea_token\",\n Path.home() / \".config\" / \"gitea\" / \"token\",\n ]:\n if path.exists():\n return path.read_text().strip()\n raise FileNotFoundError(\"No Gitea token found\")\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0143", "domain": "gitea_api", "prompt": "Write a robust, production-ready function that Write a Python function that safely reads the response body from a Gitea API call even when the server returns an empty body. Handle empty responses gracefully.", "response": "import urllib.request\n\ndef safe_read_response(resp: urllib.request.addinfourl) -> dict:\n \"\"\"Return parsed JSON or empty dict if body is empty.\"\"\"\n raw = resp.read().decode()\n if not raw.strip():\n return {}\n import json\n return json.loads(raw)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0030", "domain": "gitea_api", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that handles HTTP 401, 403, 404, and 500 errors from the Gitea API gracefully. Add retry logic with exponential backoff.", "response": "import urllib.error\n\nclass GiteaError(Exception):\n def __init__(self, status: int, message: str):\n self.status = status\n super().__init__(f\"Gitea {status}: {message}\")\n\ndef handle_gitea_error(e: urllib.error.HTTPError) -> None:\n \"\"\"Map HTTP errors to typed exceptions.\"\"\"\n body = e.read().decode(errors=\"replace\") if e.fp else \"\"\n if e.code == 401:\n raise GiteaError(401, f\"Unauthorized. Check your token. {body}\")\n if e.code == 403:\n raise GiteaError(403, f\"Forbidden. {body}\")\n if e.code == 404:\n raise GiteaError(404, f\"Not found. {body}\")\n if e.code >= 500:\n raise GiteaError(e.code, f\"Server error. {body}\")\n raise GiteaError(e.code, body)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0065", "domain": "pr_workflow", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that dismisses a review on a Gitea pull request. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef dismiss_review(repo: str, pr_number: int, review_id: int, token: str, message: str = \"\"):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/reviews/{review_id}/dismissals\"\n data = {\"message\": message or \"Dismissed\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0059", "domain": "pr_workflow", "prompt": "Draft a minimal but complete solution that Write a Python function that updates the description of an existing Gitea pull request. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef update_pr_description(repo: str, pr_number: int, new_body: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}\"\n data = {\"body\": new_body}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0244", "domain": "issue_automation", "prompt": "Create a typed Python utility that Write a Python function that unlocks a previously locked Gitea issue. Surface clear exception messages on failure.", "response": "import urllib.request\n\ndef unlock_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/lock\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0216", "domain": "repo_management", "prompt": "Design a concise Python snippet that Write a Python function that lists all collaborators on a Gitea repo. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef list_collaborators(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/collaborators\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0060", "domain": "gitea_api", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that implements a circuit breaker for Gitea API requests after 3 consecutive failures. Return typed dataclasses where appropriate.", "response": "class CircuitBreaker:\n def __init__(self, threshold: int = 3):\n self.failures = 0\n self.threshold = threshold\n self.open = False\n\n def call(self, fn, *args, **kwargs):\n if self.open:\n raise RuntimeError(\"Circuit breaker is OPEN\")\n try:\n result = fn(*args, **kwargs)\n self.failures = 0\n return result\n except Exception:\n self.failures += 1\n if self.failures >= self.threshold:\n self.open = True\n raise\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0014", "domain": "gitea_api", "prompt": "Create a typed Python utility that Write a Python function that measures the latency of a Gitea API call and raises a warning if it exceeds 2 seconds. Include error handling.", "response": "import time\nimport urllib.request\n\ndef timed_request(req: urllib.request.Request, threshold: float = 2.0):\n \"\"\"Execute request and warn if latency exceeds threshold.\"\"\"\n start = time.time()\n with urllib.request.urlopen(req, timeout=30) as resp:\n body = resp.read().decode()\n elapsed = time.time() - start\n if elapsed > threshold:\n print(f\"WARNING: Request took {elapsed:.2f}s\")\n return body\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0041", "domain": "repo_management", "prompt": "Write a Python function that lists all collaborators on a Gitea repo. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef list_collaborators(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/collaborators\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0172", "domain": "repo_management", "prompt": "Using only the Python standard library, Write a Python function that sets a repo topic (tag) via the Gitea API. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef set_repo_topic(repo: str, topic: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/topics\"\n data = {\"topics\": [topic]}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PUT\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0240", "domain": "repo_management", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that sets branch protection rules: no force-push, require status checks. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef set_strict_protection(repo: str, branch: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branch_protections\"\n data = {\n \"branch_name\": branch,\n \"enable_push\": False,\n \"enable_status_check\": True,\n \"status_check_contexts\": [\"ci/tests\"],\n }\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0110", "domain": "gitea_api", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that implements a circuit breaker for Gitea API requests after 3 consecutive failures. Validate inputs before making API calls.", "response": "class CircuitBreaker:\n def __init__(self, threshold: int = 3):\n self.failures = 0\n self.threshold = threshold\n self.open = False\n\n def call(self, fn, *args, **kwargs):\n if self.open:\n raise RuntimeError(\"Circuit breaker is OPEN\")\n try:\n result = fn(*args, **kwargs)\n self.failures = 0\n return result\n except Exception:\n self.failures += 1\n if self.failures >= self.threshold:\n self.open = True\n raise\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0016", "domain": "pr_workflow", "prompt": "Design a concise Python snippet that Write a Python function that gets the diff of a Gitea pull request as raw text. Include error handling.", "response": "import urllib.request\n\ndef get_pr_diff(repo: str, pr_number: int, token: str) -> str:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}.diff\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.read().decode()\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0037", "domain": "repo_management", "prompt": "Build a reusable module function that Write a Python function that deletes a webhook from a Gitea repo by its ID. Add retry logic with exponential backoff.", "response": "import urllib.request\n\ndef delete_webhook(repo: str, hook_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/hooks/{hook_id}\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0035", "domain": "pr_workflow", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that lists the files changed in a Gitea pull request. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef list_pr_files(repo: str, pr_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/files\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0193", "domain": "pr_workflow", "prompt": "Write a robust, production-ready function that Write a Python function that checks if a PR branch is behind the base branch and needs rebasing. Optimize for minimal external dependencies.", "response": "import subprocess\n\ndef is_behind(base: str, feature: str) -> bool:\n result = subprocess.run(\n [\"git\", \"merge-base\", f\"origin/{base}\", feature],\n capture_output=True, text=True, check=True,\n )\n merge_base = result.stdout.strip()\n result2 = subprocess.run(\n [\"git\", \"rev-parse\", f\"origin/{base}\"],\n capture_output=True, text=True, check=True,\n )\n return merge_base != result2.stdout.strip()\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0220", "domain": "repo_management", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that un-archives a Gitea repo via API. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef unarchive_repo(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"archived\": False}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0138", "domain": "repo_management", "prompt": "Author a defensive Python routine that Write a Python function that checks whether a branch exists in a remote Gitea repo without cloning. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef branch_exists(repo: str, branch: str, token: str) -> bool:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branches/{branch}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n try:\n with urllib.request.urlopen(req, timeout=10) as resp:\n return resp.status == 200\n except urllib.error.HTTPError as e:\n if e.code == 404:\n return False\n raise\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0068", "domain": "pr_workflow", "prompt": "Author a defensive Python routine that Write a Python function that checks if a PR branch is behind the base branch and needs rebasing. Return typed dataclasses where appropriate.", "response": "import subprocess\n\ndef is_behind(base: str, feature: str) -> bool:\n result = subprocess.run(\n [\"git\", \"merge-base\", f\"origin/{base}\", feature],\n capture_output=True, text=True, check=True,\n )\n merge_base = result.stdout.strip()\n result2 = subprocess.run(\n [\"git\", \"rev-parse\", f\"origin/{base}\"],\n capture_output=True, text=True, check=True,\n )\n return merge_base != result2.stdout.strip()\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0134", "domain": "pr_workflow", "prompt": "Create a typed Python utility that Write a Python function that updates the description of an existing Gitea pull request. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef update_pr_description(repo: str, pr_number: int, new_body: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}\"\n data = {\"body\": new_body}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0213", "domain": "repo_management", "prompt": "Write a robust, production-ready function that Write a Python function that checks whether a branch exists in a remote Gitea repo without cloning. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef branch_exists(repo: str, branch: str, token: str) -> bool:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branches/{branch}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n try:\n with urllib.request.urlopen(req, timeout=10) as resp:\n return resp.status == 200\n except urllib.error.HTTPError as e:\n if e.code == 404:\n return False\n raise\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0230", "domain": "repo_management", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that protects a branch in Gitea by requiring PR reviews before merge. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef protect_branch(repo: str, branch: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branch_protections\"\n data = {\"branch_name\": branch, \"enable_push\": False, \"enable_push_whitelist\": False}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0029", "domain": "pr_workflow", "prompt": "Draft a minimal but complete solution that Write a Python function that merges a Gitea pull request with retry logic for merge conflicts. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport urllib.error\nimport json\nimport time\n\ndef merge_pr(repo: str, number: int, token: str, method: str = \"squash\", retries: int = 3):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{number}/merge\"\n data = {\"Do\": method}\n for attempt in range(retries):\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n try:\n with urllib.request.urlopen(req, timeout=30) as resp:\n return True\n except urllib.error.HTTPError as e:\n if e.code == 405 and attempt < retries - 1:\n time.sleep(5)\n continue\n raise\n return False\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0164", "domain": "gitea_api", "prompt": "Create a typed Python utility that Write a Python function that measures the latency of a Gitea API call and raises a warning if it exceeds 2 seconds. Include docstrings and type hints.", "response": "import time\nimport urllib.request\n\ndef timed_request(req: urllib.request.Request, threshold: float = 2.0):\n \"\"\"Execute request and warn if latency exceeds threshold.\"\"\"\n start = time.time()\n with urllib.request.urlopen(req, timeout=30) as resp:\n body = resp.read().decode()\n elapsed = time.time() - start\n if elapsed > threshold:\n print(f\"WARNING: Request took {elapsed:.2f}s\")\n return body\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0245", "domain": "gitea_api", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that creates a reusable urllib Request object with authentication for repeated Gitea API calls. Surface clear exception messages on failure.", "response": "import urllib.request\n\nclass AuthenticatedRequest:\n def __init__(self, base_url: str, token: str):\n self.base_url = base_url.rstrip(\"/\")\n self.token = token\n\n def build(self, path: str, method: str = \"GET\", data: bytes | None = None):\n url = f\"{self.base_url}/api/v1{path}\"\n req = urllib.request.Request(url, data=data, method=method)\n req.add_header(\"Authorization\", f\"token {self.token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n return req\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0113", "domain": "issue_automation", "prompt": "Write a robust, production-ready function that Write a Python function that fetches the full timeline (comments) of a Gitea issue. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef get_issue_timeline(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/comments\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0124", "domain": "pr_workflow", "prompt": "Create a typed Python utility that Write a Python function that fetches the commit history of a PR branch. Validate inputs before making API calls.", "response": "import subprocess\n\ndef get_pr_commits(branch: str, base: str = \"main\") -> list[str]:\n result = subprocess.run(\n [\"git\", \"log\", f\"origin/{base}..{branch}\", \"--pretty=format:%H %s\"],\n capture_output=True, text=True, check=True,\n )\n return result.stdout.strip().split(\"\n\") if result.stdout.strip() else []\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0147", "domain": "issue_automation", "prompt": "Build a reusable module function that Write a Python function that sets a milestone on a Gitea issue. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef set_milestone(repo: str, issue_number: int, milestone_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{issue_number}\"\n data = {\"milestone\": milestone_id}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0249", "domain": "pr_workflow", "prompt": "Draft a minimal but complete solution that Write a Python function that fetches the commit history of a PR branch. Surface clear exception messages on failure.", "response": "import subprocess\n\ndef get_pr_commits(branch: str, base: str = \"main\") -> list[str]:\n result = subprocess.run(\n [\"git\", \"log\", f\"origin/{base}..{branch}\", \"--pretty=format:%H %s\"],\n capture_output=True, text=True, check=True,\n )\n return result.stdout.strip().split(\"\n\") if result.stdout.strip() else []\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0188", "domain": "gitea_api", "prompt": "Author a defensive Python routine that Write a Python function that converts a repo string 'owner/name' into a Gitea API path '/repos/owner/name'. Optimize for minimal external dependencies.", "response": "def repo_path(repo: str) -> str:\n \"\"\"Convert 'owner/name' to '/repos/owner/name'.\"\"\"\n if \"/\" not in repo:\n raise ValueError(\"Repo must be 'owner/name'\")\n return f\"/repos/{repo}\"\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0171", "domain": "pr_workflow", "prompt": "Write a Python function that adds a label to a Gitea pull request. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef add_pr_label(repo: str, pr_number: int, label_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/labels\"\n data = {\"labels\": [label_id]}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0066", "domain": "gitea_api", "prompt": "Design a concise Python snippet that Write a Python function that implements rate-limit awareness by reading the X-RateLimit-Remaining header. Return typed dataclasses where appropriate.", "response": "import urllib.request\n\ndef check_rate_limit(resp: urllib.request.addinfourl) -> int:\n \"\"\"Read X-RateLimit-Remaining from response headers.\"\"\"\n remaining = resp.headers.get(\"X-RateLimit-Remaining\")\n return int(remaining) if remaining else -1\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0181", "domain": "repo_management", "prompt": "Write a Python function that creates a custom label in a Gitea repo with a specific color. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef create_label(repo: str, name: str, color: str, token: str):\n owner, repo_name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{repo_name}/labels\"\n data = {\"name\": name, \"color\": color}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0122", "domain": "issue_automation", "prompt": "Using only the Python standard library, Write a Python function that sets a milestone on a Gitea issue. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef set_milestone(repo: str, issue_number: int, milestone_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{issue_number}\"\n data = {\"milestone\": milestone_id}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0052", "domain": "gitea_api", "prompt": "Using only the Python standard library, Write a Python function that reads a Gitea API token from standard local paths and returns it. Return typed dataclasses where appropriate.", "response": "from pathlib import Path\n\ndef read_gitea_token() -> str:\n \"\"\"Read token from standard locations.\"\"\"\n for path in [\n Path.home() / \".hermes\" / \"gitea_token\",\n Path.home() / \".config\" / \"gitea\" / \"token\",\n ]:\n if path.exists():\n return path.read_text().strip()\n raise FileNotFoundError(\"No Gitea token found\")\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0116", "domain": "pr_workflow", "prompt": "Design a concise Python snippet that Write a Python function that gets the diff of a Gitea pull request as raw text. Validate inputs before making API calls.", "response": "import urllib.request\n\ndef get_pr_diff(repo: str, pr_number: int, token: str) -> str:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}.diff\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.read().decode()\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0005", "domain": "gitea_api", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that handles HTTP 401, 403, 404, and 500 errors from the Gitea API gracefully. Include error handling.", "response": "import urllib.error\n\nclass GiteaError(Exception):\n def __init__(self, status: int, message: str):\n self.status = status\n super().__init__(f\"Gitea {status}: {message}\")\n\ndef handle_gitea_error(e: urllib.error.HTTPError) -> None:\n \"\"\"Map HTTP errors to typed exceptions.\"\"\"\n body = e.read().decode(errors=\"replace\") if e.fp else \"\"\n if e.code == 401:\n raise GiteaError(401, f\"Unauthorized. Check your token. {body}\")\n if e.code == 403:\n raise GiteaError(403, f\"Forbidden. {body}\")\n if e.code == 404:\n raise GiteaError(404, f\"Not found. {body}\")\n if e.code >= 500:\n raise GiteaError(e.code, f\"Server error. {body}\")\n raise GiteaError(e.code, body)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0049", "domain": "pr_workflow", "prompt": "Draft a minimal but complete solution that Write a Python function that fetches the commit history of a PR branch. Add retry logic with exponential backoff.", "response": "import subprocess\n\ndef get_pr_commits(branch: str, base: str = \"main\") -> list[str]:\n result = subprocess.run(\n [\"git\", \"log\", f\"origin/{base}..{branch}\", \"--pretty=format:%H %s\"],\n capture_output=True, text=True, check=True,\n )\n return result.stdout.strip().split(\"\n\") if result.stdout.strip() else []\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0056", "domain": "gitea_api", "prompt": "Design a concise Python snippet that Write a Python function that iterates through all pages of a paginated Gitea API endpoint. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef paginate_all(url_template: str, token: str, params: dict, limit: int = 50):\n \"\"\"Iterate all pages of a paginated Gitea endpoint.\"\"\"\n page = 1\n while True:\n params[\"page\"] = page\n params[\"limit\"] = limit\n req = urllib.request.Request(url_template + \"?\" + urllib.parse.urlencode(params))\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n batch = json.loads(resp.read().decode())\n if not batch:\n break\n yield from batch\n if len(batch) < limit:\n break\n page += 1\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0158", "domain": "pr_workflow", "prompt": "Author a defensive Python routine that Write a Python function that rebases a feature branch onto the base branch before opening a PR. Include docstrings and type hints.", "response": "import subprocess\n\ndef rebase_branch(feature: str, base: str = \"main\"):\n subprocess.run([\"git\", \"checkout\", feature], check=True, capture_output=True)\n subprocess.run([\"git\", \"fetch\", \"origin\", base], check=True, capture_output=True)\n subprocess.run([\"git\", \"rebase\", f\"origin/{base}\"], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0152", "domain": "issue_automation", "prompt": "Using only the Python standard library, Write a Python function that filters Gitea issues by label name. Include docstrings and type hints.", "response": "def filter_by_label(issues: list[dict], label: str) -> list[dict]:\n return [i for i in issues if any(l.get(\"name\") == label for l in i.get(\"labels\", []))]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0193", "domain": "issue_automation", "prompt": "Write a robust, production-ready function that Write a Python function that locks a Gitea issue to prevent further comments. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef lock_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/lock\"\n req = urllib.request.Request(url, data=json.dumps({}).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0232", "domain": "gitea_api", "prompt": "Using only the Python standard library, Write a Python function that uses urllib (no external deps) to POST JSON data to the Gitea API. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef gitea_post_json(base_url: str, path: str, token: str, data: dict):\n \"\"\"POST JSON to Gitea API using only stdlib.\"\"\"\n url = f\"{base_url.rstrip('/')}/api/v1{path}\"\n body = json.dumps(data).encode(\"utf-8\")\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n req.add_header(\"Accept\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n raw = resp.read().decode()\n return json.loads(raw) if raw.strip() else {}\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0054", "domain": "gitea_api", "prompt": "Create a typed Python utility that Write a Python function that makes an authenticated GET request to the Gitea API with retries and exponential backoff. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport urllib.error\nimport json\nimport time\n\ndef gitea_get_with_retries(url: str, token: str, retries: int = 3, backoff: float = 1.5):\n \"\"\"Authenticated GET with exponential backoff.\"\"\"\n for attempt in range(retries):\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n try:\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n except urllib.error.HTTPError as e:\n if 400 <= e.code < 500 and e.code != 429:\n raise\n if attempt == retries - 1:\n raise\n except urllib.error.URLError:\n if attempt == retries - 1:\n raise\n time.sleep(backoff ** attempt)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0176", "domain": "pr_workflow", "prompt": "Design a concise Python snippet that Write a Python function that creates a pull request on Gitea via API. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef create_pull_request(repo: str, title: str, head: str, base: str, body: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls\"\n data = {\"title\": title, \"head\": head, \"base\": base, \"body\": body}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0093", "domain": "issue_automation", "prompt": "Write a robust, production-ready function that Write a Python function that locks a Gitea issue to prevent further comments. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef lock_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/lock\"\n req = urllib.request.Request(url, data=json.dumps({}).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0055", "domain": "gitea_api", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that handles HTTP 401, 403, 404, and 500 errors from the Gitea API gracefully. Return typed dataclasses where appropriate.", "response": "import urllib.error\n\nclass GiteaError(Exception):\n def __init__(self, status: int, message: str):\n self.status = status\n super().__init__(f\"Gitea {status}: {message}\")\n\ndef handle_gitea_error(e: urllib.error.HTTPError) -> None:\n \"\"\"Map HTTP errors to typed exceptions.\"\"\"\n body = e.read().decode(errors=\"replace\") if e.fp else \"\"\n if e.code == 401:\n raise GiteaError(401, f\"Unauthorized. Check your token. {body}\")\n if e.code == 403:\n raise GiteaError(403, f\"Forbidden. {body}\")\n if e.code == 404:\n raise GiteaError(404, f\"Not found. {body}\")\n if e.code >= 500:\n raise GiteaError(e.code, f\"Server error. {body}\")\n raise GiteaError(e.code, body)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0206", "domain": "repo_management", "prompt": "Design a concise Python snippet that Write a Python function that creates a custom label in a Gitea repo with a specific color. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef create_label(repo: str, name: str, color: str, token: str):\n owner, repo_name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{repo_name}/labels\"\n data = {\"name\": name, \"color\": color}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0204", "domain": "issue_automation", "prompt": "Create a typed Python utility that Write a Python function that closes a Gitea issue via API. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef close_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"state\": \"closed\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0003", "domain": "issue_automation", "prompt": "Write a robust, production-ready function that Write a Python function that posts a comment on a Gitea issue via API. Include error handling.", "response": "import urllib.request\nimport json\n\ndef comment_on_issue(repo: str, number: int, body: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/comments\"\n data = {\"body\": body}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0104", "domain": "repo_management", "prompt": "Create a typed Python utility that Write a Python function that lists all branches in a Gitea repo. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef list_branches(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branches\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0106", "domain": "repo_management", "prompt": "Design a concise Python snippet that Write a Python function that creates a custom label in a Gitea repo with a specific color. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef create_label(repo: str, name: str, color: str, token: str):\n owner, repo_name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{repo_name}/labels\"\n data = {\"name\": name, \"color\": color}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0163", "domain": "pr_workflow", "prompt": "Write a robust, production-ready function that Write a Python function that closes a pull request without merging it. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef close_pr(repo: str, pr_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}\"\n data = {\"state\": \"closed\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0047", "domain": "repo_management", "prompt": "Build a reusable module function that Write a Python function that sets a repo topic (tag) via the Gitea API. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef set_repo_topic(repo: str, topic: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/topics\"\n data = {\"topics\": [topic]}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PUT\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0250", "domain": "repo_management", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that syncs a fork with its upstream parent repo via Gitea API. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef sync_fork(repo: str, token: str, branch: str = \"main\"):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls\"\n data = {\"title\": \"Sync upstream\", \"head\": f\"upstream:{branch}\", \"base\": branch, \"body\": \"Automated sync\"}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0181", "domain": "gitea_api", "prompt": "Write a Python function that iterates through all pages of a paginated Gitea API endpoint. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef paginate_all(url_template: str, token: str, params: dict, limit: int = 50):\n \"\"\"Iterate all pages of a paginated Gitea endpoint.\"\"\"\n page = 1\n while True:\n params[\"page\"] = page\n params[\"limit\"] = limit\n req = urllib.request.Request(url_template + \"?\" + urllib.parse.urlencode(params))\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n batch = json.loads(resp.read().decode())\n if not batch:\n break\n yield from batch\n if len(batch) < limit:\n break\n page += 1\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0135", "domain": "issue_automation", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that finds all unassigned open issues in a Gitea repo. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef find_unassigned_issues(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues?state=open&type=issues&limit=100\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n issues = json.loads(resp.read().decode())\n return [i for i in issues if not i.get(\"assignee\") and not i.get(\"pull_request\")]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0238", "domain": "issue_automation", "prompt": "Author a defensive Python routine that Write a Python function that fetches the full timeline (comments) of a Gitea issue. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef get_issue_timeline(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/comments\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0119", "domain": "repo_management", "prompt": "Draft a minimal but complete solution that Write a Python function that archives a Gitea repo (read-only) via API. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef archive_repo(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"archived\": True}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0165", "domain": "issue_automation", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that auto-triangles Gitea issues by running a classifier on the title and body. Include docstrings and type hints.", "response": "import random\n\ndef triage_issue(title: str, body: str) -> str:\n \"\"\"Simple rule-based triage classifier.\"\"\"\n text = (title + \" \" + body).lower()\n if any(w in text for w in [\"bug\", \"crash\", \"error\", \"fix\"]):\n return \"bug\"\n if any(w in text for w in [\"feature\", \"add\", \"implement\", \"support\"]):\n return \"feature\"\n if any(w in text for w in [\"docs\", \"documentation\", \"readme\"]):\n return \"documentation\"\n return \"ops\"\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0135", "domain": "pr_workflow", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that lists the files changed in a Gitea pull request. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef list_pr_files(repo: str, pr_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/files\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0242", "domain": "pr_workflow", "prompt": "Using only the Python standard library, Write a Python function that triggers a CI pipeline by pushing an empty commit on a PR branch. Surface clear exception messages on failure.", "response": "import subprocess\n\ndef trigger_ci(repo_url: str, branch: str):\n subprocess.run(\n [\"git\", \"commit\", \"--allow-empty\", \"-m\", \"ci: trigger pipeline\"],\n check=True, capture_output=True,\n )\n subprocess.run([\"git\", \"push\", repo_url, branch], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0247", "domain": "gitea_api", "prompt": "Build a reusable module function that Write a Python function that parses a Gitea API error response and extracts the human-readable message. Surface clear exception messages on failure.", "response": "import json\nimport urllib.error\n\ndef parse_error_body(e: urllib.error.HTTPError) -> str:\n \"\"\"Extract human-readable message from Gitea error response.\"\"\"\n try:\n body = json.loads(e.read().decode())\n return body.get(\"message\", str(e))\n except Exception:\n return str(e)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0090", "domain": "pr_workflow", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that dismisses a review on a Gitea pull request. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef dismiss_review(repo: str, pr_number: int, review_id: int, token: str, message: str = \"\"):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/reviews/{review_id}/dismissals\"\n data = {\"message\": message or \"Dismissed\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0020", "domain": "repo_management", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that un-archives a Gitea repo via API. Include error handling.", "response": "import urllib.request\nimport json\n\ndef unarchive_repo(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"archived\": False}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0007", "domain": "issue_automation", "prompt": "Build a reusable module function that Write a Python function that labels a batch of Gitea issues with the same label. Include error handling.", "response": "import urllib.request\nimport json\n\ndef batch_label_issues(repo: str, numbers: list[int], label_id: int, token: str):\n owner, name = repo.split(\"/\")\n for num in numbers:\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{num}/labels\"\n data = {\"labels\": [label_id]}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30):\n pass\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0125", "domain": "issue_automation", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that updates the title of a Gitea issue via API. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef update_issue_title(repo: str, number: int, new_title: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"title\": new_title}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0005", "domain": "issue_automation", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that assigns a Gitea issue to a specific user. Include error handling.", "response": "import urllib.request\nimport json\n\ndef assign_issue(repo: str, number: int, assignees: list[str], token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"assignees\": assignees}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0026", "domain": "issue_automation", "prompt": "Design a concise Python snippet that Write a Python function that fetches open issues from a Gitea repo and filters out pull requests. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef fetch_open_issues(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues?state=open&type=issues&limit=100\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return [i for i in json.loads(resp.read().decode()) if not i.get(\"pull_request\")]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0076", "domain": "repo_management", "prompt": "Design a concise Python snippet that Write a Python function that creates a new Gitea repo under an organization via API. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef create_repo(org: str, name: str, token: str, description: str = \"\", private: bool = False):\n url = f\"https://forge.example.com/api/v1/orgs/{org}/repos\"\n data = {\"name\": name, \"description\": description, \"private\": private}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0070", "domain": "issue_automation", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that subscribes a user to notifications on a Gitea issue. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef subscribe_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/subscriptions\"\n req = urllib.request.Request(url, data=json.dumps({}).encode(), method=\"PUT\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0045", "domain": "repo_management", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that un-archives a Gitea repo via API. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef unarchive_repo(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"archived\": False}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0219", "domain": "pr_workflow", "prompt": "Draft a minimal but complete solution that Write a Python function that auto-squashes all commits on a PR branch before merging. Add timeout and connection cleanup.", "response": "import subprocess\n\ndef autosquash_branch(branch: str, base: str = \"main\"):\n subprocess.run([\"git\", \"checkout\", branch], check=True, capture_output=True)\n subprocess.run([\"git\", \"reset\", f\"origin/{base}\"], check=True, capture_output=True)\n subprocess.run([\"git\", \"add\", \"-A\"], check=True, capture_output=True)\n subprocess.run([\"git\", \"commit\", \"-m\", f\"feat: squash {branch}\"], check=True, capture_output=True)\n subprocess.run([\"git\", \"push\", \"--force-with-lease\", \"origin\", branch], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0153", "domain": "gitea_api", "prompt": "Write a robust, production-ready function that Write a Python function that builds a Gitea API URL with query parameters for pagination. Include docstrings and type hints.", "response": "import urllib.parse\n\ndef build_api_url(base_url: str, path: str, params: dict | None = None) -> str:\n \"\"\"Build a Gitea API URL with optional query params.\"\"\"\n url = f\"{base_url.rstrip('/')}/api/v1{path}\"\n if params:\n clean = {k: v for k, v in params.items() if v is not None}\n url += \"?\" + urllib.parse.urlencode(clean)\n return url\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0213", "domain": "gitea_api", "prompt": "Write a robust, production-ready function that Write a Python function that converts a repo string 'owner/name' into a Gitea API path '/repos/owner/name'. Add timeout and connection cleanup.", "response": "def repo_path(repo: str) -> str:\n \"\"\"Convert 'owner/name' to '/repos/owner/name'.\"\"\"\n if \"/\" not in repo:\n raise ValueError(\"Repo must be 'owner/name'\")\n return f\"/repos/{repo}\"\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0245", "domain": "issue_automation", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that subscribes a user to notifications on a Gitea issue. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef subscribe_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/subscriptions\"\n req = urllib.request.Request(url, data=json.dumps({}).encode(), method=\"PUT\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0088", "domain": "issue_automation", "prompt": "Author a defensive Python routine that Write a Python function that fetches the full timeline (comments) of a Gitea issue. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef get_issue_timeline(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/comments\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0016", "domain": "gitea_api", "prompt": "Design a concise Python snippet that Write a Python function that implements rate-limit awareness by reading the X-RateLimit-Remaining header. Include error handling.", "response": "import urllib.request\n\ndef check_rate_limit(resp: urllib.request.addinfourl) -> int:\n \"\"\"Read X-RateLimit-Remaining from response headers.\"\"\"\n remaining = resp.headers.get(\"X-RateLimit-Remaining\")\n return int(remaining) if remaining else -1\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0187", "domain": "repo_management", "prompt": "Build a reusable module function that Write a Python function that deletes a webhook from a Gitea repo by its ID. Optimize for minimal external dependencies.", "response": "import urllib.request\n\ndef delete_webhook(repo: str, hook_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/hooks/{hook_id}\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0137", "domain": "gitea_api", "prompt": "Build a reusable module function that Write a Python function that validates a Gitea API token by calling the /user endpoint. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef validate_token(base_url: str, token: str) -> bool:\n \"\"\"Verify a token by calling the /user endpoint.\"\"\"\n req = urllib.request.Request(f\"{base_url}/api/v1/user\")\n req.add_header(\"Authorization\", f\"token {token}\")\n try:\n with urllib.request.urlopen(req, timeout=10) as resp:\n data = json.loads(resp.read().decode())\n return \"login\" in data\n except urllib.error.HTTPError as e:\n if e.code == 401:\n return False\n raise\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0086", "domain": "repo_management", "prompt": "Design a concise Python snippet that Write a Python function that updates a repo's description and website via the Gitea API. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef update_repo_description(repo: str, description: str, website: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"description\": description, \"website\": website}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0029", "domain": "gitea_api", "prompt": "Draft a minimal but complete solution that Write a Python function that makes an authenticated GET request to the Gitea API with retries and exponential backoff. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport urllib.error\nimport json\nimport time\n\ndef gitea_get_with_retries(url: str, token: str, retries: int = 3, backoff: float = 1.5):\n \"\"\"Authenticated GET with exponential backoff.\"\"\"\n for attempt in range(retries):\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n try:\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n except urllib.error.HTTPError as e:\n if 400 <= e.code < 500 and e.code != 429:\n raise\n if attempt == retries - 1:\n raise\n except urllib.error.URLError:\n if attempt == retries - 1:\n raise\n time.sleep(backoff ** attempt)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0198", "domain": "repo_management", "prompt": "Author a defensive Python routine that Write a Python function that gets the default branch of a Gitea repo. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef get_default_branch(repo: str, token: str) -> str:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n data = json.loads(resp.read().decode())\n return data.get(\"default_branch\", \"main\")\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0224", "domain": "pr_workflow", "prompt": "Create a typed Python utility that Write a Python function that fetches the commit history of a PR branch. Add timeout and connection cleanup.", "response": "import subprocess\n\ndef get_pr_commits(branch: str, base: str = \"main\") -> list[str]:\n result = subprocess.run(\n [\"git\", \"log\", f\"origin/{base}..{branch}\", \"--pretty=format:%H %s\"],\n capture_output=True, text=True, check=True,\n )\n return result.stdout.strip().split(\"\n\") if result.stdout.strip() else []\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0058", "domain": "issue_automation", "prompt": "Author a defensive Python routine that Write a Python function that searches Gitea issues across an organization by keyword. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef search_issues(org: str, keyword: str, token: str):\n url = f\"https://forge.example.com/api/v1/repos/search?q={keyword}&uid=0&limit=50\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0191", "domain": "issue_automation", "prompt": "Write a Python function that migrates issues from one Gitea repo to another by creating copies. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef migrate_issue(source_repo: str, target_repo: str, issue: dict, token: str):\n owner, name = target_repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues\"\n data = {\n \"title\": f\"[Migrated] {issue['title']}\",\n \"body\": issue.get(\"body\", \"\"),\n }\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0025", "domain": "repo_management", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that syncs a fork with its upstream parent repo via Gitea API. Include error handling.", "response": "import urllib.request\nimport json\n\ndef sync_fork(repo: str, token: str, branch: str = \"main\"):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls\"\n data = {\"title\": \"Sync upstream\", \"head\": f\"upstream:{branch}\", \"base\": branch, \"body\": \"Automated sync\"}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0061", "domain": "issue_automation", "prompt": "Write a Python function that counts open issues per label in a Gitea repo. Return typed dataclasses where appropriate.", "response": "from collections import Counter\n\ndef count_issues_per_label(issues: list[dict]) -> Counter:\n counts = Counter()\n for i in issues:\n for label in i.get(\"labels\", []):\n counts[label.get(\"name\", \"unknown\")] += 1\n return counts\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0021", "domain": "repo_management", "prompt": "Write a Python function that transfers a Gitea repo from one owner to another. Include error handling.", "response": "import urllib.request\nimport json\n\ndef transfer_repo(repo: str, new_owner: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/transfer\"\n data = {\"new_owner\": new_owner}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0017", "domain": "gitea_api", "prompt": "Build a reusable module function that Write a Python function that serializes a Python dict into JSON and sends it as the body of a PATCH request to Gitea. Include error handling.", "response": "import urllib.request\nimport json\n\ndef gitea_patch(base_url: str, path: str, token: str, data: dict):\n \"\"\"Serialize dict to JSON and PATCH.\"\"\"\n url = f\"{base_url.rstrip('/')}/api/v1{path}\"\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0248", "domain": "issue_automation", "prompt": "Author a defensive Python routine that Write a Python function that removes a milestone from a Gitea issue. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef remove_milestone(repo: str, issue_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{issue_number}\"\n data = {\"milestone\": 0}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0161", "domain": "pr_workflow", "prompt": "Write a Python function that calculates the net line change (additions - deletions) across all files in a PR. Include docstrings and type hints.", "response": "def net_line_change(files: list[dict]) -> int:\n return sum(f.get(\"additions\", 0) - f.get(\"deletions\", 0) for f in files)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0018", "domain": "pr_workflow", "prompt": "Author a defensive Python routine that Write a Python function that checks if a PR branch is behind the base branch and needs rebasing. Include error handling.", "response": "import subprocess\n\ndef is_behind(base: str, feature: str) -> bool:\n result = subprocess.run(\n [\"git\", \"merge-base\", f\"origin/{base}\", feature],\n capture_output=True, text=True, check=True,\n )\n merge_base = result.stdout.strip()\n result2 = subprocess.run(\n [\"git\", \"rev-parse\", f\"origin/{base}\"],\n capture_output=True, text=True, check=True,\n )\n return merge_base != result2.stdout.strip()\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0179", "domain": "gitea_api", "prompt": "Draft a minimal but complete solution that Write a Python function that makes an authenticated GET request to the Gitea API with retries and exponential backoff. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport urllib.error\nimport json\nimport time\n\ndef gitea_get_with_retries(url: str, token: str, retries: int = 3, backoff: float = 1.5):\n \"\"\"Authenticated GET with exponential backoff.\"\"\"\n for attempt in range(retries):\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n try:\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n except urllib.error.HTTPError as e:\n if 400 <= e.code < 500 and e.code != 429:\n raise\n if attempt == retries - 1:\n raise\n except urllib.error.URLError:\n if attempt == retries - 1:\n raise\n time.sleep(backoff ** attempt)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0073", "domain": "repo_management", "prompt": "Write a robust, production-ready function that Write a Python function that gets the default branch of a Gitea repo. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef get_default_branch(repo: str, token: str) -> str:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n data = json.loads(resp.read().decode())\n return data.get(\"default_branch\", \"main\")\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0244", "domain": "pr_workflow", "prompt": "Create a typed Python utility that Write a Python function that auto-squashes all commits on a PR branch before merging. Surface clear exception messages on failure.", "response": "import subprocess\n\ndef autosquash_branch(branch: str, base: str = \"main\"):\n subprocess.run([\"git\", \"checkout\", branch], check=True, capture_output=True)\n subprocess.run([\"git\", \"reset\", f\"origin/{base}\"], check=True, capture_output=True)\n subprocess.run([\"git\", \"add\", \"-A\"], check=True, capture_output=True)\n subprocess.run([\"git\", \"commit\", \"-m\", f\"feat: squash {branch}\"], check=True, capture_output=True)\n subprocess.run([\"git\", \"push\", \"--force-with-lease\", \"origin\", branch], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0093", "domain": "repo_management", "prompt": "Write a robust, production-ready function that Write a Python function that enables issue tracking on a Gitea repo via API. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef enable_issues(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"has_issues\": True}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0226", "domain": "issue_automation", "prompt": "Design a concise Python snippet that Write a Python function that fetches open issues from a Gitea repo and filters out pull requests. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef fetch_open_issues(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues?state=open&type=issues&limit=100\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return [i for i in json.loads(resp.read().decode()) if not i.get(\"pull_request\")]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0191", "domain": "gitea_api", "prompt": "Write a Python function that implements rate-limit awareness by reading the X-RateLimit-Remaining header. Optimize for minimal external dependencies.", "response": "import urllib.request\n\ndef check_rate_limit(resp: urllib.request.addinfourl) -> int:\n \"\"\"Read X-RateLimit-Remaining from response headers.\"\"\"\n remaining = resp.headers.get(\"X-RateLimit-Remaining\")\n return int(remaining) if remaining else -1\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0057", "domain": "repo_management", "prompt": "Build a reusable module function that Write a Python function that lists all labels in a Gitea repo. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef list_labels(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/labels\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0032", "domain": "issue_automation", "prompt": "Using only the Python standard library, Write a Python function that labels a batch of Gitea issues with the same label. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef batch_label_issues(repo: str, numbers: list[int], label_id: int, token: str):\n owner, name = repo.split(\"/\")\n for num in numbers:\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{num}/labels\"\n data = {\"labels\": [label_id]}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30):\n pass\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0146", "domain": "pr_workflow", "prompt": "Design a concise Python snippet that Write a Python function that adds a label to a Gitea pull request. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef add_pr_label(repo: str, pr_number: int, label_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/labels\"\n data = {\"labels\": [label_id]}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0037", "domain": "pr_workflow", "prompt": "Build a reusable module function that Write a Python function that detects destructive deletions in a PR (any file losing >50% of lines). Add retry logic with exponential backoff.", "response": "def detect_destructive(files: list[dict], threshold: float = 0.5) -> list[str]:\n flagged = []\n for f in files:\n if f.get(\"status\") == \"modified\" and f.get(\"deletions\", 0) > 0:\n total = f.get(\"additions\", 0) + f.get(\"deletions\", 0)\n if total > 0 and f[\"deletions\"] / total > threshold:\n flagged.append(f[\"filename\"])\n return flagged\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0080", "domain": "repo_management", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that protects a branch in Gitea by requiring PR reviews before merge. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef protect_branch(repo: str, branch: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branch_protections\"\n data = {\"branch_name\": branch, \"enable_push\": False, \"enable_push_whitelist\": False}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0119", "domain": "gitea_api", "prompt": "Draft a minimal but complete solution that Write a Python function that compares two Gitea API base URLs and normalizes them by stripping trailing slashes. Validate inputs before making API calls.", "response": "def normalize_base_url(url: str) -> str:\n \"\"\"Strip trailing slashes and ensure no duplicate slashes.\"\"\"\n return url.rstrip(\"/\")\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0126", "domain": "issue_automation", "prompt": "Design a concise Python snippet that Write a Python function that fetches open issues from a Gitea repo and filters out pull requests. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef fetch_open_issues(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues?state=open&type=issues&limit=100\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return [i for i in json.loads(resp.read().decode()) if not i.get(\"pull_request\")]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0185", "domain": "issue_automation", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that finds all unassigned open issues in a Gitea repo. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef find_unassigned_issues(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues?state=open&type=issues&limit=100\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n issues = json.loads(resp.read().decode())\n return [i for i in issues if not i.get(\"assignee\") and not i.get(\"pull_request\")]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0120", "domain": "repo_management", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that un-archives a Gitea repo via API. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef unarchive_repo(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"archived\": False}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0072", "domain": "pr_workflow", "prompt": "Using only the Python standard library, Write a Python function that removes a label from a Gitea pull request. Return typed dataclasses where appropriate.", "response": "import urllib.request\n\ndef remove_pr_label(repo: str, pr_number: int, label_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/labels/{label_id}\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0243", "domain": "issue_automation", "prompt": "Write a robust, production-ready function that Write a Python function that locks a Gitea issue to prevent further comments. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef lock_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/lock\"\n req = urllib.request.Request(url, data=json.dumps({}).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0063", "domain": "gitea_api", "prompt": "Write a robust, production-ready function that Write a Python function that converts a repo string 'owner/name' into a Gitea API path '/repos/owner/name'. Return typed dataclasses where appropriate.", "response": "def repo_path(repo: str) -> str:\n \"\"\"Convert 'owner/name' to '/repos/owner/name'.\"\"\"\n if \"/\" not in repo:\n raise ValueError(\"Repo must be 'owner/name'\")\n return f\"/repos/{repo}\"\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0087", "domain": "repo_management", "prompt": "Build a reusable module function that Write a Python function that deletes a webhook from a Gitea repo by its ID. Log all failures for observability.", "response": "import urllib.request\n\ndef delete_webhook(repo: str, hook_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/hooks/{hook_id}\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0179", "domain": "repo_management", "prompt": "Draft a minimal but complete solution that Write a Python function that lists all branches in a Gitea repo. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef list_branches(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branches\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0003", "domain": "repo_management", "prompt": "Write a robust, production-ready function that Write a Python function that sets a webhook on a Gitea repo to trigger on push events. Include error handling.", "response": "import urllib.request\nimport json\n\ndef set_push_webhook(repo: str, token: str, webhook_url: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/hooks\"\n data = {\n \"type\": \"gitea\",\n \"config\": {\"url\": webhook_url, \"content_type\": \"json\"},\n \"events\": [\"push\"],\n \"active\": True,\n }\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0046", "domain": "issue_automation", "prompt": "Design a concise Python snippet that Write a Python function that unsubscribes a user from notifications on a Gitea issue. Add retry logic with exponential backoff.", "response": "import urllib.request\n\ndef unsubscribe_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/subscriptions\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0163", "domain": "gitea_api", "prompt": "Write a robust, production-ready function that Write a Python function that converts a repo string 'owner/name' into a Gitea API path '/repos/owner/name'. Include docstrings and type hints.", "response": "def repo_path(repo: str) -> str:\n \"\"\"Convert 'owner/name' to '/repos/owner/name'.\"\"\"\n if \"/\" not in repo:\n raise ValueError(\"Repo must be 'owner/name'\")\n return f\"/repos/{repo}\"\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0182", "domain": "pr_workflow", "prompt": "Using only the Python standard library, Write a Python function that checks whether a Gitea pull request is mergeable. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef is_mergeable(repo: str, pr_number: int, token: str) -> bool:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n data = json.loads(resp.read().decode())\n return data.get(\"mergeable\", False)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0021", "domain": "gitea_api", "prompt": "Write a Python function that retries only on 5xx and 429 errors, but fails immediately on 4xx (except 429). Include error handling.", "response": "import urllib.request\nimport urllib.error\nimport time\n\ndef smart_retry(req: urllib.request.Request, retries: int = 3):\n \"\"\"Retry on 5xx and 429; fail fast on other 4xx.\"\"\"\n for attempt in range(retries):\n try:\n return urllib.request.urlopen(req, timeout=30)\n except urllib.error.HTTPError as e:\n if e.code == 429 or e.code >= 500:\n if attempt == retries - 1:\n raise\n time.sleep(2 ** attempt)\n else:\n raise\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0167", "domain": "pr_workflow", "prompt": "Build a reusable module function that Write a Python function that triggers a CI pipeline by pushing an empty commit on a PR branch. Include docstrings and type hints.", "response": "import subprocess\n\ndef trigger_ci(repo_url: str, branch: str):\n subprocess.run(\n [\"git\", \"commit\", \"--allow-empty\", \"-m\", \"ci: trigger pipeline\"],\n check=True, capture_output=True,\n )\n subprocess.run([\"git\", \"push\", repo_url, branch], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0083", "domain": "issue_automation", "prompt": "Write a robust, production-ready function that Write a Python function that searches Gitea issues across an organization by keyword. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef search_issues(org: str, keyword: str, token: str):\n url = f\"https://forge.example.com/api/v1/repos/search?q={keyword}&uid=0&limit=50\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0178", "domain": "gitea_api", "prompt": "Author a defensive Python routine that Write a Python function that builds a Gitea API URL with query parameters for pagination. Optimize for minimal external dependencies.", "response": "import urllib.parse\n\ndef build_api_url(base_url: str, path: str, params: dict | None = None) -> str:\n \"\"\"Build a Gitea API URL with optional query params.\"\"\"\n url = f\"{base_url.rstrip('/')}/api/v1{path}\"\n if params:\n clean = {k: v for k, v in params.items() if v is not None}\n url += \"?\" + urllib.parse.urlencode(clean)\n return url\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0141", "domain": "gitea_api", "prompt": "Write a Python function that implements rate-limit awareness by reading the X-RateLimit-Remaining header. Handle empty responses gracefully.", "response": "import urllib.request\n\ndef check_rate_limit(resp: urllib.request.addinfourl) -> int:\n \"\"\"Read X-RateLimit-Remaining from response headers.\"\"\"\n remaining = resp.headers.get(\"X-RateLimit-Remaining\")\n return int(remaining) if remaining else -1\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0179", "domain": "issue_automation", "prompt": "Draft a minimal but complete solution that Write a Python function that closes a Gitea issue via API. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef close_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"state\": \"closed\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0097", "domain": "gitea_api", "prompt": "Build a reusable module function that Write a Python function that parses a Gitea API error response and extracts the human-readable message. Log all failures for observability.", "response": "import json\nimport urllib.error\n\ndef parse_error_body(e: urllib.error.HTTPError) -> str:\n \"\"\"Extract human-readable message from Gitea error response.\"\"\"\n try:\n body = json.loads(e.read().decode())\n return body.get(\"message\", str(e))\n except Exception:\n return str(e)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0103", "domain": "issue_automation", "prompt": "Write a robust, production-ready function that Write a Python function that posts a comment on a Gitea issue via API. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef comment_on_issue(repo: str, number: int, body: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/comments\"\n data = {\"body\": body}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0200", "domain": "pr_workflow", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that cherry-picks a commit from one branch to another via Gitea API. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef cherry_pick_commit(repo: str, commit_sha: str, target_branch: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/git/commits\"\n data = {\"message\": f\"cherry-pick {commit_sha}\", \"parents\": [target_branch], \"tree\": commit_sha}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0033", "domain": "issue_automation", "prompt": "Write a robust, production-ready function that Write a Python function that searches Gitea issues across an organization by keyword. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef search_issues(org: str, keyword: str, token: str):\n url = f\"https://forge.example.com/api/v1/repos/search?q={keyword}&uid=0&limit=50\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0152", "domain": "pr_workflow", "prompt": "Using only the Python standard library, Write a Python function that checks if an open pull request already exists for a given issue (by scanning title/body/branch). Include docstrings and type hints.", "response": "def issue_has_open_pr(prs: list[dict], issue_number: int) -> bool:\n num_str = str(issue_number)\n for pr in prs:\n combined = f\"{pr.get('title','')} {pr.get('body','')} {pr.get('head',{}).get('ref','')}\"\n if num_str in combined:\n return True\n return False\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0017", "domain": "pr_workflow", "prompt": "Build a reusable module function that Write a Python function that triggers a CI pipeline by pushing an empty commit on a PR branch. Include error handling.", "response": "import subprocess\n\ndef trigger_ci(repo_url: str, branch: str):\n subprocess.run(\n [\"git\", \"commit\", \"--allow-empty\", \"-m\", \"ci: trigger pipeline\"],\n check=True, capture_output=True,\n )\n subprocess.run([\"git\", \"push\", repo_url, branch], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0059", "domain": "gitea_api", "prompt": "Draft a minimal but complete solution that Write a Python function that sets proper request headers (Authorization, Content-Type, Accept) for Gitea API calls. Return typed dataclasses where appropriate.", "response": "def build_gitea_request(url: str, token: str, method: str = \"GET\", data: bytes | None = None):\n \"\"\"Build a request with standard headers.\"\"\"\n req = urllib.request.Request(url, data=data, method=method)\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n req.add_header(\"Accept\", \"application/json\")\n return req\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0241", "domain": "repo_management", "prompt": "Write a Python function that lists all collaborators on a Gitea repo. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef list_collaborators(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/collaborators\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0008", "domain": "gitea_api", "prompt": "Author a defensive Python routine that Write a Python function that wraps the Gitea API in a typed dataclass response (Issue, PR, Comment). Include error handling.", "response": "from dataclasses import dataclass\nfrom typing import Any\n\n@dataclass\nclass Issue:\n number: int\n title: str\n state: str\n\n @classmethod\n def from_dict(cls, d: dict) -> \"Issue\":\n return cls(\n number=d.get(\"number\", 0),\n title=d.get(\"title\", \"\"),\n state=d.get(\"state\", \"\"),\n )\n\ndef parse_issues(raw: list[dict]) -> list[Issue]:\n \"\"\"Convert raw API response into typed Issue objects.\"\"\"\n return [Issue.from_dict(i) for i in raw]\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0167", "domain": "issue_automation", "prompt": "Build a reusable module function that Write a Python function that generates a markdown summary report of open issues for a repo. Include docstrings and type hints.", "response": "def generate_issue_report(repo: str, issues: list[dict]) -> str:\n lines = [f\"# Issue Report for {repo}\", \"\"]\n for i in issues:\n lines.append(f\"- #{i['number']} [{i['state']}] {i['title']}\")\n return \"\n\".join(lines)\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0096", "domain": "pr_workflow", "prompt": "Design a concise Python snippet that Write a Python function that adds a label to a Gitea pull request. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef add_pr_label(repo: str, pr_number: int, label_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/labels\"\n data = {\"labels\": [label_id]}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0124", "domain": "repo_management", "prompt": "Create a typed Python utility that Write a Python function that renames a branch in a Gitea repo via API. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef rename_branch(repo: str, old: str, new: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branches/{old}\"\n data = {\"name\": new}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0088", "domain": "pr_workflow", "prompt": "Author a defensive Python routine that Write a Python function that closes a pull request without merging it. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef close_pr(repo: str, pr_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}\"\n data = {\"state\": \"closed\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0048", "domain": "issue_automation", "prompt": "Author a defensive Python routine that Write a Python function that removes a milestone from a Gitea issue. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef remove_milestone(repo: str, issue_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{issue_number}\"\n data = {\"milestone\": 0}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0213", "domain": "pr_workflow", "prompt": "Write a robust, production-ready function that Write a Python function that closes a pull request without merging it. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef close_pr(repo: str, pr_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}\"\n data = {\"state\": \"closed\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0115", "domain": "pr_workflow", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that dismisses a review on a Gitea pull request. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef dismiss_review(repo: str, pr_number: int, review_id: int, token: str, message: str = \"\"):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/reviews/{review_id}/dismissals\"\n data = {\"message\": message or \"Dismissed\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0001", "domain": "repo_management", "prompt": "Write a Python function that creates a new Gitea repo under an organization via API. Include error handling.", "response": "import urllib.request\nimport json\n\ndef create_repo(org: str, name: str, token: str, description: str = \"\", private: bool = False):\n url = f\"https://forge.example.com/api/v1/orgs/{org}/repos\"\n data = {\"name\": name, \"description\": description, \"private\": private}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0172", "domain": "pr_workflow", "prompt": "Using only the Python standard library, Write a Python function that removes a label from a Gitea pull request. Include docstrings and type hints.", "response": "import urllib.request\n\ndef remove_pr_label(repo: str, pr_number: int, label_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/labels/{label_id}\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0061", "domain": "repo_management", "prompt": "Write a Python function that updates a repo's description and website via the Gitea API. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef update_repo_description(repo: str, description: str, website: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"description\": description, \"website\": website}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0056", "domain": "repo_management", "prompt": "Design a concise Python snippet that Write a Python function that creates a custom label in a Gitea repo with a specific color. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef create_label(repo: str, name: str, color: str, token: str):\n owner, repo_name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{repo_name}/labels\"\n data = {\"name\": name, \"color\": color}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0104", "domain": "gitea_api", "prompt": "Create a typed Python utility that Write a Python function that makes an authenticated GET request to the Gitea API with retries and exponential backoff. Validate inputs before making API calls.", "response": "import urllib.request\nimport urllib.error\nimport json\nimport time\n\ndef gitea_get_with_retries(url: str, token: str, retries: int = 3, backoff: float = 1.5):\n \"\"\"Authenticated GET with exponential backoff.\"\"\"\n for attempt in range(retries):\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n try:\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n except urllib.error.HTTPError as e:\n if 400 <= e.code < 500 and e.code != 429:\n raise\n if attempt == retries - 1:\n raise\n except urllib.error.URLError:\n if attempt == retries - 1:\n raise\n time.sleep(backoff ** attempt)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0145", "domain": "gitea_api", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that creates a reusable urllib Request object with authentication for repeated Gitea API calls. Handle empty responses gracefully.", "response": "import urllib.request\n\nclass AuthenticatedRequest:\n def __init__(self, base_url: str, token: str):\n self.base_url = base_url.rstrip(\"/\")\n self.token = token\n\n def build(self, path: str, method: str = \"GET\", data: bytes | None = None):\n url = f\"{self.base_url}/api/v1{path}\"\n req = urllib.request.Request(url, data=data, method=method)\n req.add_header(\"Authorization\", f\"token {self.token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n return req\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0151", "domain": "repo_management", "prompt": "Write a Python function that creates a new Gitea repo under an organization via API. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef create_repo(org: str, name: str, token: str, description: str = \"\", private: bool = False):\n url = f\"https://forge.example.com/api/v1/orgs/{org}/repos\"\n data = {\"name\": name, \"description\": description, \"private\": private}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0111", "domain": "pr_workflow", "prompt": "Write a Python function that calculates the net line change (additions - deletions) across all files in a PR. Validate inputs before making API calls.", "response": "def net_line_change(files: list[dict]) -> int:\n return sum(f.get(\"additions\", 0) - f.get(\"deletions\", 0) for f in files)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0241", "domain": "gitea_api", "prompt": "Write a Python function that implements rate-limit awareness by reading the X-RateLimit-Remaining header. Surface clear exception messages on failure.", "response": "import urllib.request\n\ndef check_rate_limit(resp: urllib.request.addinfourl) -> int:\n \"\"\"Read X-RateLimit-Remaining from response headers.\"\"\"\n remaining = resp.headers.get(\"X-RateLimit-Remaining\")\n return int(remaining) if remaining else -1\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0175", "domain": "pr_workflow", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that cherry-picks a commit from one branch to another via Gitea API. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef cherry_pick_commit(repo: str, commit_sha: str, target_branch: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/git/commits\"\n data = {\"message\": f\"cherry-pick {commit_sha}\", \"parents\": [target_branch], \"tree\": commit_sha}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0011", "domain": "repo_management", "prompt": "Write a Python function that updates a repo's description and website via the Gitea API. Include error handling.", "response": "import urllib.request\nimport json\n\ndef update_repo_description(repo: str, description: str, website: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"description\": description, \"website\": website}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0229", "domain": "repo_management", "prompt": "Draft a minimal but complete solution that Write a Python function that lists all branches in a Gitea repo. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef list_branches(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branches\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0058", "domain": "repo_management", "prompt": "Author a defensive Python routine that Write a Python function that creates a milestone in a Gitea repo with a due date. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\nfrom datetime import datetime, timezone\n\ndef create_milestone(repo: str, title: str, due_date: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/milestones\"\n data = {\"title\": title, \"due_on\": due_date}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0211", "domain": "issue_automation", "prompt": "Write a Python function that counts open issues per label in a Gitea repo. Add timeout and connection cleanup.", "response": "from collections import Counter\n\ndef count_issues_per_label(issues: list[dict]) -> Counter:\n counts = Counter()\n for i in issues:\n for label in i.get(\"labels\", []):\n counts[label.get(\"name\", \"unknown\")] += 1\n return counts\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0238", "domain": "repo_management", "prompt": "Author a defensive Python routine that Write a Python function that checks whether a branch exists in a remote Gitea repo without cloning. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef branch_exists(repo: str, branch: str, token: str) -> bool:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branches/{branch}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n try:\n with urllib.request.urlopen(req, timeout=10) as resp:\n return resp.status == 200\n except urllib.error.HTTPError as e:\n if e.code == 404:\n return False\n raise\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0112", "domain": "pr_workflow", "prompt": "Using only the Python standard library, Write a Python function that detects destructive deletions in a PR (any file losing >50% of lines). Validate inputs before making API calls.", "response": "def detect_destructive(files: list[dict], threshold: float = 0.5) -> list[str]:\n flagged = []\n for f in files:\n if f.get(\"status\") == \"modified\" and f.get(\"deletions\", 0) > 0:\n total = f.get(\"additions\", 0) + f.get(\"deletions\", 0)\n if total > 0 and f[\"deletions\"] / total > threshold:\n flagged.append(f[\"filename\"])\n return flagged\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0234", "domain": "repo_management", "prompt": "Create a typed Python utility that Write a Python function that clones a Gitea repo with --depth 1 for a shallow clone. Surface clear exception messages on failure.", "response": "import subprocess\n\ndef shallow_clone(repo_url: str, dest: str, branch: str = \"main\"):\n \"\"\"Clone with --depth 1 to save time and space.\"\"\"\n subprocess.run(\n [\"git\", \"clone\", \"--depth\", \"1\", \"--branch\", branch, repo_url, dest],\n check=True,\n capture_output=True,\n )\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0091", "domain": "gitea_api", "prompt": "Write a Python function that implements rate-limit awareness by reading the X-RateLimit-Remaining header. Log all failures for observability.", "response": "import urllib.request\n\ndef check_rate_limit(resp: urllib.request.addinfourl) -> int:\n \"\"\"Read X-RateLimit-Remaining from response headers.\"\"\"\n remaining = resp.headers.get(\"X-RateLimit-Remaining\")\n return int(remaining) if remaining else -1\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0180", "domain": "issue_automation", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that assigns a Gitea issue to a specific user. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef assign_issue(repo: str, number: int, assignees: list[str], token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"assignees\": assignees}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0149", "domain": "issue_automation", "prompt": "Draft a minimal but complete solution that Write a Python function that finds issues created by a specific user in a Gitea repo. Handle empty responses gracefully.", "response": "def find_issues_by_author(issues: list[dict], username: str) -> list[dict]:\n return [i for i in issues if i.get(\"user\", {}).get(\"login\") == username]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0250", "domain": "gitea_api", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that closes idle Gitea API connections after 30 seconds to prevent socket exhaustion. Surface clear exception messages on failure.", "response": "import urllib.request\nimport socket\n\nclass TimeoutHTTPHandler(urllib.request.HTTPHandler):\n def __init__(self, timeout: int = 30):\n self.timeout = timeout\n super().__init__()\n\n def http_open(self, req):\n return self.do_open(lambda host, port: http.client.HTTPConnection(host, port, timeout=self.timeout), req)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0102", "domain": "repo_management", "prompt": "Using only the Python standard library, Write a Python function that lists all repos in a Gitea organization with pagination. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef list_org_repos(org: str, token: str, limit: int = 50, page: int = 1):\n url = f\"https://forge.example.com/api/v1/orgs/{org}/repos?limit={limit}&page={page}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0111", "domain": "gitea_api", "prompt": "Write a Python function that logs Gitea API requests and responses for debugging. Validate inputs before making API calls.", "response": "import logging\nimport urllib.request\n\nlogger = logging.getLogger(\"gitea\")\n\ndef logged_request(req: urllib.request.Request):\n \"\"\"Execute a request and log the exchange.\"\"\"\n logger.debug(\"%s %s\", req.get_method(), req.full_url)\n with urllib.request.urlopen(req, timeout=30) as resp:\n body = resp.read().decode()\n logger.debug(\"Response %d: %s\", resp.status, body[:500])\n return body\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0154", "domain": "gitea_api", "prompt": "Create a typed Python utility that Write a Python function that makes an authenticated GET request to the Gitea API with retries and exponential backoff. Include docstrings and type hints.", "response": "import urllib.request\nimport urllib.error\nimport json\nimport time\n\ndef gitea_get_with_retries(url: str, token: str, retries: int = 3, backoff: float = 1.5):\n \"\"\"Authenticated GET with exponential backoff.\"\"\"\n for attempt in range(retries):\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n try:\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n except urllib.error.HTTPError as e:\n if 400 <= e.code < 500 and e.code != 429:\n raise\n if attempt == retries - 1:\n raise\n except urllib.error.URLError:\n if attempt == retries - 1:\n raise\n time.sleep(backoff ** attempt)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0036", "domain": "pr_workflow", "prompt": "Design a concise Python snippet that Write a Python function that calculates the net line change (additions - deletions) across all files in a PR. Add retry logic with exponential backoff.", "response": "def net_line_change(files: list[dict]) -> int:\n return sum(f.get(\"additions\", 0) - f.get(\"deletions\", 0) for f in files)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0162", "domain": "repo_management", "prompt": "Using only the Python standard library, Write a Python function that deletes a webhook from a Gitea repo by its ID. Include docstrings and type hints.", "response": "import urllib.request\n\ndef delete_webhook(repo: str, hook_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/hooks/{hook_id}\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0065", "domain": "issue_automation", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that auto-triangles Gitea issues by running a classifier on the title and body. Return typed dataclasses where appropriate.", "response": "import random\n\ndef triage_issue(title: str, body: str) -> str:\n \"\"\"Simple rule-based triage classifier.\"\"\"\n text = (title + \" \" + body).lower()\n if any(w in text for w in [\"bug\", \"crash\", \"error\", \"fix\"]):\n return \"bug\"\n if any(w in text for w in [\"feature\", \"add\", \"implement\", \"support\"]):\n return \"feature\"\n if any(w in text for w in [\"docs\", \"documentation\", \"readme\"]):\n return \"documentation\"\n return \"ops\"\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0128", "domain": "repo_management", "prompt": "Author a defensive Python routine that Write a Python function that sets a webhook on a Gitea repo to trigger on push events. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef set_push_webhook(repo: str, token: str, webhook_url: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/hooks\"\n data = {\n \"type\": \"gitea\",\n \"config\": {\"url\": webhook_url, \"content_type\": \"json\"},\n \"events\": [\"push\"],\n \"active\": True,\n }\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0031", "domain": "issue_automation", "prompt": "Write a Python function that checks whether a Gitea issue already has a bot comment to avoid duplicate comments. Add retry logic with exponential backoff.", "response": "def has_bot_comment(comments: list[dict], bot_marker: str = \"🤖\") -> bool:\n return any(bot_marker in c.get(\"body\", \"\") for c in comments)\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0134", "domain": "issue_automation", "prompt": "Create a typed Python utility that Write a Python function that calculates the age of a Gitea issue in days from its created_at timestamp. Handle empty responses gracefully.", "response": "from datetime import datetime, timezone\n\ndef issue_age_days(created_at: str) -> int:\n \"\"\"Calculate age of an issue in days.\"\"\"\n fmt = \"%Y-%m-%dT%H:%M:%SZ\"\n created = datetime.strptime(created_at, fmt).replace(tzinfo=timezone.utc)\n return (datetime.now(timezone.utc) - created).days\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0014", "domain": "issue_automation", "prompt": "Create a typed Python utility that Write a Python function that detects stale issues (no activity for 30 days) in a Gitea repo. Include error handling.", "response": "from datetime import datetime, timezone\n\ndef find_stale_issues(issues: list[dict], days: int = 30) -> list[dict]:\n now = datetime.now(timezone.utc)\n stale = []\n for i in issues:\n updated = datetime.fromisoformat(i[\"updated_at\"].replace(\"Z\", \"+00:00\"))\n if (now - updated).days > days:\n stale.append(i)\n return stale\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0127", "domain": "repo_management", "prompt": "Build a reusable module function that Write a Python function that lists all repos in a Gitea organization with pagination. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef list_org_repos(org: str, token: str, limit: int = 50, page: int = 1):\n url = f\"https://forge.example.com/api/v1/orgs/{org}/repos?limit={limit}&page={page}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0145", "domain": "pr_workflow", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that generates a release notes draft from merged PRs since the last tag. Handle empty responses gracefully.", "response": "def generate_release_notes(merged_prs: list[dict], tag: str) -> str:\n lines = [f\"## Release {tag}\", \"\"]\n for pr in merged_prs:\n lines.append(f\"- #{pr['number']} {pr['title']}\")\n return \"\n\".join(lines)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0174", "domain": "repo_management", "prompt": "Create a typed Python utility that Write a Python function that renames a branch in a Gitea repo via API. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef rename_branch(repo: str, old: str, new: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branches/{old}\"\n data = {\"name\": new}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0012", "domain": "gitea_api", "prompt": "Using only the Python standard library, Write a Python function that validates a Gitea API token by calling the /user endpoint. Include error handling.", "response": "import urllib.request\nimport json\n\ndef validate_token(base_url: str, token: str) -> bool:\n \"\"\"Verify a token by calling the /user endpoint.\"\"\"\n req = urllib.request.Request(f\"{base_url}/api/v1/user\")\n req.add_header(\"Authorization\", f\"token {token}\")\n try:\n with urllib.request.urlopen(req, timeout=10) as resp:\n data = json.loads(resp.read().decode())\n return \"login\" in data\n except urllib.error.HTTPError as e:\n if e.code == 401:\n return False\n raise\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0039", "domain": "gitea_api", "prompt": "Draft a minimal but complete solution that Write a Python function that measures the latency of a Gitea API call and raises a warning if it exceeds 2 seconds. Add retry logic with exponential backoff.", "response": "import time\nimport urllib.request\n\ndef timed_request(req: urllib.request.Request, threshold: float = 2.0):\n \"\"\"Execute request and warn if latency exceeds threshold.\"\"\"\n start = time.time()\n with urllib.request.urlopen(req, timeout=30) as resp:\n body = resp.read().decode()\n elapsed = time.time() - start\n if elapsed > threshold:\n print(f\"WARNING: Request took {elapsed:.2f}s\")\n return body\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0126", "domain": "pr_workflow", "prompt": "Design a concise Python snippet that Write a Python function that creates a pull request on Gitea via API. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef create_pull_request(repo: str, title: str, head: str, base: str, body: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls\"\n data = {\"title\": title, \"head\": head, \"base\": base, \"body\": body}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0212", "domain": "gitea_api", "prompt": "Using only the Python standard library, Write a Python function that validates a Gitea API token by calling the /user endpoint. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef validate_token(base_url: str, token: str) -> bool:\n \"\"\"Verify a token by calling the /user endpoint.\"\"\"\n req = urllib.request.Request(f\"{base_url}/api/v1/user\")\n req.add_header(\"Authorization\", f\"token {token}\")\n try:\n with urllib.request.urlopen(req, timeout=10) as resp:\n data = json.loads(resp.read().decode())\n return \"login\" in data\n except urllib.error.HTTPError as e:\n if e.code == 401:\n return False\n raise\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0224", "domain": "issue_automation", "prompt": "Create a typed Python utility that Write a Python function that finds issues created by a specific user in a Gitea repo. Add timeout and connection cleanup.", "response": "def find_issues_by_author(issues: list[dict], username: str) -> list[dict]:\n return [i for i in issues if i.get(\"user\", {}).get(\"login\") == username]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0201", "domain": "gitea_api", "prompt": "Write a Python function that pings a Gitea instance to check if it is alive. Add timeout and connection cleanup.", "response": "import urllib.request\nimport urllib.error\nimport json\n\ndef ping_gitea(base_url: str) -> bool:\n \"\"\"Check if Gitea is responding.\"\"\"\n try:\n req = urllib.request.Request(f\"{base_url}/api/v1/version\")\n with urllib.request.urlopen(req, timeout=5) as resp:\n return resp.status == 200\n except Exception:\n return False\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0223", "domain": "issue_automation", "prompt": "Write a robust, production-ready function that Write a Python function that removes a milestone from a Gitea issue. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef remove_milestone(repo: str, issue_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{issue_number}\"\n data = {\"milestone\": 0}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0171", "domain": "gitea_api", "prompt": "Write a Python function that retries only on 5xx and 429 errors, but fails immediately on 4xx (except 429). Include docstrings and type hints.", "response": "import urllib.request\nimport urllib.error\nimport time\n\ndef smart_retry(req: urllib.request.Request, retries: int = 3):\n \"\"\"Retry on 5xx and 429; fail fast on other 4xx.\"\"\"\n for attempt in range(retries):\n try:\n return urllib.request.urlopen(req, timeout=30)\n except urllib.error.HTTPError as e:\n if e.code == 429 or e.code >= 500:\n if attempt == retries - 1:\n raise\n time.sleep(2 ** attempt)\n else:\n raise\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0027", "domain": "pr_workflow", "prompt": "Build a reusable module function that Write a Python function that checks if an open pull request already exists for a given issue (by scanning title/body/branch). Add retry logic with exponential backoff.", "response": "def issue_has_open_pr(prs: list[dict], issue_number: int) -> bool:\n num_str = str(issue_number)\n for pr in prs:\n combined = f\"{pr.get('title','')} {pr.get('body','')} {pr.get('head',{}).get('ref','')}\"\n if num_str in combined:\n return True\n return False\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0171", "domain": "repo_management", "prompt": "Write a Python function that transfers a Gitea repo from one owner to another. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef transfer_repo(repo: str, new_owner: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/transfer\"\n data = {\"new_owner\": new_owner}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0177", "domain": "pr_workflow", "prompt": "Build a reusable module function that Write a Python function that checks if an open pull request already exists for a given issue (by scanning title/body/branch). Optimize for minimal external dependencies.", "response": "def issue_has_open_pr(prs: list[dict], issue_number: int) -> bool:\n num_str = str(issue_number)\n for pr in prs:\n combined = f\"{pr.get('title','')} {pr.get('body','')} {pr.get('head',{}).get('ref','')}\"\n if num_str in combined:\n return True\n return False\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0218", "domain": "pr_workflow", "prompt": "Author a defensive Python routine that Write a Python function that checks if a PR branch is behind the base branch and needs rebasing. Add timeout and connection cleanup.", "response": "import subprocess\n\ndef is_behind(base: str, feature: str) -> bool:\n result = subprocess.run(\n [\"git\", \"merge-base\", f\"origin/{base}\", feature],\n capture_output=True, text=True, check=True,\n )\n merge_base = result.stdout.strip()\n result2 = subprocess.run(\n [\"git\", \"rev-parse\", f\"origin/{base}\"],\n capture_output=True, text=True, check=True,\n )\n return merge_base != result2.stdout.strip()\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0175", "domain": "repo_management", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that syncs a fork with its upstream parent repo via Gitea API. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef sync_fork(repo: str, token: str, branch: str = \"main\"):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls\"\n data = {\"title\": \"Sync upstream\", \"head\": f\"upstream:{branch}\", \"base\": branch, \"body\": \"Automated sync\"}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0200", "domain": "repo_management", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that syncs a fork with its upstream parent repo via Gitea API. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef sync_fork(repo: str, token: str, branch: str = \"main\"):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls\"\n data = {\"title\": \"Sync upstream\", \"head\": f\"upstream:{branch}\", \"base\": branch, \"body\": \"Automated sync\"}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0190", "domain": "pr_workflow", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that dismisses a review on a Gitea pull request. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef dismiss_review(repo: str, pr_number: int, review_id: int, token: str, message: str = \"\"):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/reviews/{review_id}/dismissals\"\n data = {\"message\": message or \"Dismissed\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0065", "domain": "gitea_api", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that caches Gitea API responses for 60 seconds to avoid redundant requests. Return typed dataclasses where appropriate.", "response": "import time\nimport json\n\nclass TimedCache:\n def __init__(self, ttl: int = 60):\n self.ttl = ttl\n self.store = {}\n\n def get(self, key: str, fetch_fn):\n now = time.time()\n if key in self.store:\n value, expiry = self.store[key]\n if now < expiry:\n return value\n value = fetch_fn()\n self.store[key] = (value, now + self.ttl)\n return value\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0004", "domain": "issue_automation", "prompt": "Create a typed Python utility that Write a Python function that closes a Gitea issue via API. Include error handling.", "response": "import urllib.request\nimport json\n\ndef close_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"state\": \"closed\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0061", "domain": "pr_workflow", "prompt": "Write a Python function that calculates the net line change (additions - deletions) across all files in a PR. Return typed dataclasses where appropriate.", "response": "def net_line_change(files: list[dict]) -> int:\n return sum(f.get(\"additions\", 0) - f.get(\"deletions\", 0) for f in files)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0015", "domain": "pr_workflow", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that dismisses a review on a Gitea pull request. Include error handling.", "response": "import urllib.request\nimport json\n\ndef dismiss_review(repo: str, pr_number: int, review_id: int, token: str, message: str = \"\"):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/reviews/{review_id}/dismissals\"\n data = {\"message\": message or \"Dismissed\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0013", "domain": "repo_management", "prompt": "Write a robust, production-ready function that Write a Python function that checks whether a branch exists in a remote Gitea repo without cloning. Include error handling.", "response": "import urllib.request\nimport json\n\ndef branch_exists(repo: str, branch: str, token: str) -> bool:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branches/{branch}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n try:\n with urllib.request.urlopen(req, timeout=10) as resp:\n return resp.status == 200\n except urllib.error.HTTPError as e:\n if e.code == 404:\n return False\n raise\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0224", "domain": "repo_management", "prompt": "Create a typed Python utility that Write a Python function that renames a branch in a Gitea repo via API. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef rename_branch(repo: str, old: str, new: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branches/{old}\"\n data = {\"name\": new}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0174", "domain": "gitea_api", "prompt": "Create a typed Python utility that Write a Python function that attaches a custom User-Agent header to all Gitea API requests. Include docstrings and type hints.", "response": "import urllib.request\n\ndef request_with_user_agent(url: str, token: str, agent: str = \"timmy-bot/1.0\"):\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"User-Agent\", agent)\n return req\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0050", "domain": "issue_automation", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that updates the title of a Gitea issue via API. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef update_issue_title(repo: str, number: int, new_title: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"title\": new_title}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0101", "domain": "issue_automation", "prompt": "Write a Python function that fetches open issues from a Gitea repo and filters out pull requests. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef fetch_open_issues(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues?state=open&type=issues&limit=100\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return [i for i in json.loads(resp.read().decode()) if not i.get(\"pull_request\")]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0242", "domain": "issue_automation", "prompt": "Using only the Python standard library, Write a Python function that generates a markdown summary report of open issues for a repo. Surface clear exception messages on failure.", "response": "def generate_issue_report(repo: str, issues: list[dict]) -> str:\n lines = [f\"# Issue Report for {repo}\", \"\"]\n for i in issues:\n lines.append(f\"- #{i['number']} [{i['state']}] {i['title']}\")\n return \"\n\".join(lines)\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0165", "domain": "repo_management", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that sets branch protection rules: no force-push, require status checks. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef set_strict_protection(repo: str, branch: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branch_protections\"\n data = {\n \"branch_name\": branch,\n \"enable_push\": False,\n \"enable_status_check\": True,\n \"status_check_contexts\": [\"ci/tests\"],\n }\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0042", "domain": "gitea_api", "prompt": "Using only the Python standard library, Write a Python function that serializes a Python dict into JSON and sends it as the body of a PATCH request to Gitea. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef gitea_patch(base_url: str, path: str, token: str, data: dict):\n \"\"\"Serialize dict to JSON and PATCH.\"\"\"\n url = f\"{base_url.rstrip('/')}/api/v1{path}\"\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0032", "domain": "repo_management", "prompt": "Using only the Python standard library, Write a Python function that lists all labels in a Gitea repo. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef list_labels(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/labels\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0047", "domain": "issue_automation", "prompt": "Build a reusable module function that Write a Python function that sets a milestone on a Gitea issue. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef set_milestone(repo: str, issue_number: int, milestone_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{issue_number}\"\n data = {\"milestone\": milestone_id}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0064", "domain": "pr_workflow", "prompt": "Create a typed Python utility that Write a Python function that approves a Gitea pull request via API. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef approve_pr(repo: str, pr_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/reviews\"\n data = {\"body\": \"LGTM\", \"event\": \"APPROVE\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0078", "domain": "repo_management", "prompt": "Author a defensive Python routine that Write a Python function that sets a webhook on a Gitea repo to trigger on push events. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef set_push_webhook(repo: str, token: str, webhook_url: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/hooks\"\n data = {\n \"type\": \"gitea\",\n \"config\": {\"url\": webhook_url, \"content_type\": \"json\"},\n \"events\": [\"push\"],\n \"active\": True,\n }\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0044", "domain": "gitea_api", "prompt": "Create a typed Python utility that Write a Python function that compares two Gitea API base URLs and normalizes them by stripping trailing slashes. Add retry logic with exponential backoff.", "response": "def normalize_base_url(url: str) -> str:\n \"\"\"Strip trailing slashes and ensure no duplicate slashes.\"\"\"\n return url.rstrip(\"/\")\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0031", "domain": "gitea_api", "prompt": "Write a Python function that iterates through all pages of a paginated Gitea API endpoint. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef paginate_all(url_template: str, token: str, params: dict, limit: int = 50):\n \"\"\"Iterate all pages of a paginated Gitea endpoint.\"\"\"\n page = 1\n while True:\n params[\"page\"] = page\n params[\"limit\"] = limit\n req = urllib.request.Request(url_template + \"?\" + urllib.parse.urlencode(params))\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n batch = json.loads(resp.read().decode())\n if not batch:\n break\n yield from batch\n if len(batch) < limit:\n break\n page += 1\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0211", "domain": "gitea_api", "prompt": "Write a Python function that logs Gitea API requests and responses for debugging. Add timeout and connection cleanup.", "response": "import logging\nimport urllib.request\n\nlogger = logging.getLogger(\"gitea\")\n\ndef logged_request(req: urllib.request.Request):\n \"\"\"Execute a request and log the exchange.\"\"\"\n logger.debug(\"%s %s\", req.get_method(), req.full_url)\n with urllib.request.urlopen(req, timeout=30) as resp:\n body = resp.read().decode()\n logger.debug(\"Response %d: %s\", resp.status, body[:500])\n return body\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0089", "domain": "repo_management", "prompt": "Draft a minimal but complete solution that Write a Python function that forks a Gitea repo into another organization via API. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef fork_repo(repo: str, org: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/forks\"\n data = {\"organization\": org}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0195", "domain": "gitea_api", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that creates a reusable urllib Request object with authentication for repeated Gitea API calls. Optimize for minimal external dependencies.", "response": "import urllib.request\n\nclass AuthenticatedRequest:\n def __init__(self, base_url: str, token: str):\n self.base_url = base_url.rstrip(\"/\")\n self.token = token\n\n def build(self, path: str, method: str = \"GET\", data: bytes | None = None):\n url = f\"{self.base_url}/api/v1{path}\"\n req = urllib.request.Request(url, data=data, method=method)\n req.add_header(\"Authorization\", f\"token {self.token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n return req\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0142", "domain": "issue_automation", "prompt": "Using only the Python standard library, Write a Python function that generates a markdown summary report of open issues for a repo. Handle empty responses gracefully.", "response": "def generate_issue_report(repo: str, issues: list[dict]) -> str:\n lines = [f\"# Issue Report for {repo}\", \"\"]\n for i in issues:\n lines.append(f\"- #{i['number']} [{i['state']}] {i['title']}\")\n return \"\n\".join(lines)\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0074", "domain": "issue_automation", "prompt": "Create a typed Python utility that Write a Python function that finds issues created by a specific user in a Gitea repo. Return typed dataclasses where appropriate.", "response": "def find_issues_by_author(issues: list[dict], username: str) -> list[dict]:\n return [i for i in issues if i.get(\"user\", {}).get(\"login\") == username]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0158", "domain": "issue_automation", "prompt": "Author a defensive Python routine that Write a Python function that searches Gitea issues across an organization by keyword. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef search_issues(org: str, keyword: str, token: str):\n url = f\"https://forge.example.com/api/v1/repos/search?q={keyword}&uid=0&limit=50\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0018", "domain": "gitea_api", "prompt": "Author a defensive Python routine that Write a Python function that safely reads the response body from a Gitea API call even when the server returns an empty body. Include error handling.", "response": "import urllib.request\n\ndef safe_read_response(resp: urllib.request.addinfourl) -> dict:\n \"\"\"Return parsed JSON or empty dict if body is empty.\"\"\"\n raw = resp.read().decode()\n if not raw.strip():\n return {}\n import json\n return json.loads(raw)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0245", "domain": "repo_management", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that un-archives a Gitea repo via API. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef unarchive_repo(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"archived\": False}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0151", "domain": "issue_automation", "prompt": "Write a Python function that fetches open issues from a Gitea repo and filters out pull requests. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef fetch_open_issues(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues?state=open&type=issues&limit=100\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return [i for i in json.loads(resp.read().decode()) if not i.get(\"pull_request\")]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0073", "domain": "gitea_api", "prompt": "Write a robust, production-ready function that Write a Python function that builds a Gitea API search query for issues across all repos in an organization. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport urllib.parse\n\ndef search_issues_url(org: str, query: str, state: str = \"open\") -> str:\n \"\"\"Build cross-repo issue search URL.\"\"\"\n params = urllib.parse.urlencode({\n \"q\": query,\n \"state\": state,\n \"type\": \"issues\",\n })\n return f\"/repos/search?{params}\"\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0143", "domain": "pr_workflow", "prompt": "Write a robust, production-ready function that Write a Python function that checks if a PR branch is behind the base branch and needs rebasing. Handle empty responses gracefully.", "response": "import subprocess\n\ndef is_behind(base: str, feature: str) -> bool:\n result = subprocess.run(\n [\"git\", \"merge-base\", f\"origin/{base}\", feature],\n capture_output=True, text=True, check=True,\n )\n merge_base = result.stdout.strip()\n result2 = subprocess.run(\n [\"git\", \"rev-parse\", f\"origin/{base}\"],\n capture_output=True, text=True, check=True,\n )\n return merge_base != result2.stdout.strip()\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0100", "domain": "repo_management", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that syncs a fork with its upstream parent repo via Gitea API. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef sync_fork(repo: str, token: str, branch: str = \"main\"):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls\"\n data = {\"title\": \"Sync upstream\", \"head\": f\"upstream:{branch}\", \"base\": branch, \"body\": \"Automated sync\"}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0023", "domain": "gitea_api", "prompt": "Write a robust, production-ready function that Write a Python function that builds a Gitea API search query for issues across all repos in an organization. Include error handling.", "response": "import urllib.request\nimport urllib.parse\n\ndef search_issues_url(org: str, query: str, state: str = \"open\") -> str:\n \"\"\"Build cross-repo issue search URL.\"\"\"\n params = urllib.parse.urlencode({\n \"q\": query,\n \"state\": state,\n \"type\": \"issues\",\n })\n return f\"/repos/search?{params}\"\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0021", "domain": "pr_workflow", "prompt": "Write a Python function that adds a label to a Gitea pull request. Include error handling.", "response": "import urllib.request\nimport json\n\ndef add_pr_label(repo: str, pr_number: int, label_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/labels\"\n data = {\"labels\": [label_id]}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0001", "domain": "pr_workflow", "prompt": "Write a Python function that creates a pull request on Gitea via API. Include error handling.", "response": "import urllib.request\nimport json\n\ndef create_pull_request(repo: str, title: str, head: str, base: str, body: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls\"\n data = {\"title\": title, \"head\": head, \"base\": base, \"body\": body}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0076", "domain": "gitea_api", "prompt": "Design a concise Python snippet that Write a Python function that pings a Gitea instance to check if it is alive. Log all failures for observability.", "response": "import urllib.request\nimport urllib.error\nimport json\n\ndef ping_gitea(base_url: str) -> bool:\n \"\"\"Check if Gitea is responding.\"\"\"\n try:\n req = urllib.request.Request(f\"{base_url}/api/v1/version\")\n with urllib.request.urlopen(req, timeout=5) as resp:\n return resp.status == 200\n except Exception:\n return False\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0187", "domain": "issue_automation", "prompt": "Build a reusable module function that Write a Python function that reopens a closed Gitea issue via API. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef reopen_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"state\": \"open\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0215", "domain": "repo_management", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that sets branch protection rules: no force-push, require status checks. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef set_strict_protection(repo: str, branch: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branch_protections\"\n data = {\n \"branch_name\": branch,\n \"enable_push\": False,\n \"enable_status_check\": True,\n \"status_check_contexts\": [\"ci/tests\"],\n }\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0082", "domain": "pr_workflow", "prompt": "Using only the Python standard library, Write a Python function that checks whether a Gitea pull request is mergeable. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef is_mergeable(repo: str, pr_number: int, token: str) -> bool:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n data = json.loads(resp.read().decode())\n return data.get(\"mergeable\", False)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0136", "domain": "gitea_api", "prompt": "Design a concise Python snippet that Write a Python function that logs Gitea API requests and responses for debugging. Handle empty responses gracefully.", "response": "import logging\nimport urllib.request\n\nlogger = logging.getLogger(\"gitea\")\n\ndef logged_request(req: urllib.request.Request):\n \"\"\"Execute a request and log the exchange.\"\"\"\n logger.debug(\"%s %s\", req.get_method(), req.full_url)\n with urllib.request.urlopen(req, timeout=30) as resp:\n body = resp.read().decode()\n logger.debug(\"Response %d: %s\", resp.status, body[:500])\n return body\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0064", "domain": "issue_automation", "prompt": "Create a typed Python utility that Write a Python function that detects stale issues (no activity for 30 days) in a Gitea repo. Return typed dataclasses where appropriate.", "response": "from datetime import datetime, timezone\n\ndef find_stale_issues(issues: list[dict], days: int = 30) -> list[dict]:\n now = datetime.now(timezone.utc)\n stale = []\n for i in issues:\n updated = datetime.fromisoformat(i[\"updated_at\"].replace(\"Z\", \"+00:00\"))\n if (now - updated).days > days:\n stale.append(i)\n return stale\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0098", "domain": "issue_automation", "prompt": "Author a defensive Python routine that Write a Python function that removes a milestone from a Gitea issue. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef remove_milestone(repo: str, issue_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{issue_number}\"\n data = {\"milestone\": 0}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0205", "domain": "gitea_api", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that handles HTTP 401, 403, 404, and 500 errors from the Gitea API gracefully. Add timeout and connection cleanup.", "response": "import urllib.error\n\nclass GiteaError(Exception):\n def __init__(self, status: int, message: str):\n self.status = status\n super().__init__(f\"Gitea {status}: {message}\")\n\ndef handle_gitea_error(e: urllib.error.HTTPError) -> None:\n \"\"\"Map HTTP errors to typed exceptions.\"\"\"\n body = e.read().decode(errors=\"replace\") if e.fp else \"\"\n if e.code == 401:\n raise GiteaError(401, f\"Unauthorized. Check your token. {body}\")\n if e.code == 403:\n raise GiteaError(403, f\"Forbidden. {body}\")\n if e.code == 404:\n raise GiteaError(404, f\"Not found. {body}\")\n if e.code >= 500:\n raise GiteaError(e.code, f\"Server error. {body}\")\n raise GiteaError(e.code, body)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0078", "domain": "pr_workflow", "prompt": "Author a defensive Python routine that Write a Python function that lists all open pull requests for a Gitea repo. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef list_open_prs(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls?state=open&limit=100\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0152", "domain": "gitea_api", "prompt": "Using only the Python standard library, Write a Python function that reads a Gitea API token from standard local paths and returns it. Include docstrings and type hints.", "response": "from pathlib import Path\n\ndef read_gitea_token() -> str:\n \"\"\"Read token from standard locations.\"\"\"\n for path in [\n Path.home() / \".hermes\" / \"gitea_token\",\n Path.home() / \".config\" / \"gitea\" / \"token\",\n ]:\n if path.exists():\n return path.read_text().strip()\n raise FileNotFoundError(\"No Gitea token found\")\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0113", "domain": "gitea_api", "prompt": "Write a robust, production-ready function that Write a Python function that converts a repo string 'owner/name' into a Gitea API path '/repos/owner/name'. Validate inputs before making API calls.", "response": "def repo_path(repo: str) -> str:\n \"\"\"Convert 'owner/name' to '/repos/owner/name'.\"\"\"\n if \"/\" not in repo:\n raise ValueError(\"Repo must be 'owner/name'\")\n return f\"/repos/{repo}\"\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0175", "domain": "gitea_api", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that closes idle Gitea API connections after 30 seconds to prevent socket exhaustion. Include docstrings and type hints.", "response": "import urllib.request\nimport socket\n\nclass TimeoutHTTPHandler(urllib.request.HTTPHandler):\n def __init__(self, timeout: int = 30):\n self.timeout = timeout\n super().__init__()\n\n def http_open(self, req):\n return self.do_open(lambda host, port: http.client.HTTPConnection(host, port, timeout=self.timeout), req)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0091", "domain": "repo_management", "prompt": "Write a Python function that lists all collaborators on a Gitea repo. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef list_collaborators(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/collaborators\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0196", "domain": "gitea_api", "prompt": "Design a concise Python snippet that Write a Python function that retries only on 5xx and 429 errors, but fails immediately on 4xx (except 429). Optimize for minimal external dependencies.", "response": "import urllib.request\nimport urllib.error\nimport time\n\ndef smart_retry(req: urllib.request.Request, retries: int = 3):\n \"\"\"Retry on 5xx and 429; fail fast on other 4xx.\"\"\"\n for attempt in range(retries):\n try:\n return urllib.request.urlopen(req, timeout=30)\n except urllib.error.HTTPError as e:\n if e.code == 429 or e.code >= 500:\n if attempt == retries - 1:\n raise\n time.sleep(2 ** attempt)\n else:\n raise\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0006", "domain": "repo_management", "prompt": "Design a concise Python snippet that Write a Python function that creates a custom label in a Gitea repo with a specific color. Include error handling.", "response": "import urllib.request\nimport json\n\ndef create_label(repo: str, name: str, color: str, token: str):\n owner, repo_name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{repo_name}/labels\"\n data = {\"name\": name, \"color\": color}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0079", "domain": "repo_management", "prompt": "Draft a minimal but complete solution that Write a Python function that lists all branches in a Gitea repo. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef list_branches(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branches\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0246", "domain": "issue_automation", "prompt": "Design a concise Python snippet that Write a Python function that unsubscribes a user from notifications on a Gitea issue. Surface clear exception messages on failure.", "response": "import urllib.request\n\ndef unsubscribe_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/subscriptions\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0158", "domain": "repo_management", "prompt": "Author a defensive Python routine that Write a Python function that creates a milestone in a Gitea repo with a due date. Include docstrings and type hints.", "response": "import urllib.request\nimport json\nfrom datetime import datetime, timezone\n\ndef create_milestone(repo: str, title: str, due_date: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/milestones\"\n data = {\"title\": title, \"due_on\": due_date}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0147", "domain": "repo_management", "prompt": "Build a reusable module function that Write a Python function that sets a repo topic (tag) via the Gitea API. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef set_repo_topic(repo: str, topic: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/topics\"\n data = {\"topics\": [topic]}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PUT\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0112", "domain": "repo_management", "prompt": "Using only the Python standard library, Write a Python function that deletes a webhook from a Gitea repo by its ID. Validate inputs before making API calls.", "response": "import urllib.request\n\ndef delete_webhook(repo: str, hook_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/hooks/{hook_id}\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0146", "domain": "issue_automation", "prompt": "Design a concise Python snippet that Write a Python function that unsubscribes a user from notifications on a Gitea issue. Handle empty responses gracefully.", "response": "import urllib.request\n\ndef unsubscribe_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/subscriptions\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0115", "domain": "issue_automation", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that auto-triangles Gitea issues by running a classifier on the title and body. Validate inputs before making API calls.", "response": "import random\n\ndef triage_issue(title: str, body: str) -> str:\n \"\"\"Simple rule-based triage classifier.\"\"\"\n text = (title + \" \" + body).lower()\n if any(w in text for w in [\"bug\", \"crash\", \"error\", \"fix\"]):\n return \"bug\"\n if any(w in text for w in [\"feature\", \"add\", \"implement\", \"support\"]):\n return \"feature\"\n if any(w in text for w in [\"docs\", \"documentation\", \"readme\"]):\n return \"documentation\"\n return \"ops\"\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0184", "domain": "issue_automation", "prompt": "Create a typed Python utility that Write a Python function that calculates the age of a Gitea issue in days from its created_at timestamp. Optimize for minimal external dependencies.", "response": "from datetime import datetime, timezone\n\ndef issue_age_days(created_at: str) -> int:\n \"\"\"Calculate age of an issue in days.\"\"\"\n fmt = \"%Y-%m-%dT%H:%M:%SZ\"\n created = datetime.strptime(created_at, fmt).replace(tzinfo=timezone.utc)\n return (datetime.now(timezone.utc) - created).days\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0057", "domain": "issue_automation", "prompt": "Build a reusable module function that Write a Python function that labels a batch of Gitea issues with the same label. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef batch_label_issues(repo: str, numbers: list[int], label_id: int, token: str):\n owner, name = repo.split(\"/\")\n for num in numbers:\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{num}/labels\"\n data = {\"labels\": [label_id]}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30):\n pass\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0166", "domain": "pr_workflow", "prompt": "Design a concise Python snippet that Write a Python function that gets the diff of a Gitea pull request as raw text. Include docstrings and type hints.", "response": "import urllib.request\n\ndef get_pr_diff(repo: str, pr_number: int, token: str) -> str:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}.diff\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.read().decode()\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0242", "domain": "repo_management", "prompt": "Using only the Python standard library, Write a Python function that adds a deploy key to a Gitea repo for CI access. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef add_deploy_key(repo: str, title: str, key: str, token: str, read_only: bool = True):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/keys\"\n data = {\"title\": title, \"key\": key, \"read_only\": read_only}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0106", "domain": "issue_automation", "prompt": "Design a concise Python snippet that Write a Python function that checks whether a Gitea issue already has a bot comment to avoid duplicate comments. Validate inputs before making API calls.", "response": "def has_bot_comment(comments: list[dict], bot_marker: str = \"🤖\") -> bool:\n return any(bot_marker in c.get(\"body\", \"\") for c in comments)\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0087", "domain": "pr_workflow", "prompt": "Build a reusable module function that Write a Python function that detects destructive deletions in a PR (any file losing >50% of lines). Log all failures for observability.", "response": "def detect_destructive(files: list[dict], threshold: float = 0.5) -> list[str]:\n flagged = []\n for f in files:\n if f.get(\"status\") == \"modified\" and f.get(\"deletions\", 0) > 0:\n total = f.get(\"additions\", 0) + f.get(\"deletions\", 0)\n if total > 0 and f[\"deletions\"] / total > threshold:\n flagged.append(f[\"filename\"])\n return flagged\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0052", "domain": "pr_workflow", "prompt": "Using only the Python standard library, Write a Python function that checks if an open pull request already exists for a given issue (by scanning title/body/branch). Return typed dataclasses where appropriate.", "response": "def issue_has_open_pr(prs: list[dict], issue_number: int) -> bool:\n num_str = str(issue_number)\n for pr in prs:\n combined = f\"{pr.get('title','')} {pr.get('body','')} {pr.get('head',{}).get('ref','')}\"\n if num_str in combined:\n return True\n return False\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0053", "domain": "pr_workflow", "prompt": "Write a robust, production-ready function that Write a Python function that lists all open pull requests for a Gitea repo. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef list_open_prs(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls?state=open&limit=100\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0023", "domain": "repo_management", "prompt": "Write a robust, production-ready function that Write a Python function that gets the default branch of a Gitea repo. Include error handling.", "response": "import urllib.request\nimport json\n\ndef get_default_branch(repo: str, token: str) -> str:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n data = json.loads(resp.read().decode())\n return data.get(\"default_branch\", \"main\")\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0173", "domain": "repo_management", "prompt": "Write a robust, production-ready function that Write a Python function that gets the default branch of a Gitea repo. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef get_default_branch(repo: str, token: str) -> str:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n data = json.loads(resp.read().decode())\n return data.get(\"default_branch\", \"main\")\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0115", "domain": "gitea_api", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that caches Gitea API responses for 60 seconds to avoid redundant requests. Validate inputs before making API calls.", "response": "import time\nimport json\n\nclass TimedCache:\n def __init__(self, ttl: int = 60):\n self.ttl = ttl\n self.store = {}\n\n def get(self, key: str, fetch_fn):\n now = time.time()\n if key in self.store:\n value, expiry = self.store[key]\n if now < expiry:\n return value\n value = fetch_fn()\n self.store[key] = (value, now + self.ttl)\n return value\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0216", "domain": "issue_automation", "prompt": "Design a concise Python snippet that Write a Python function that migrates issues from one Gitea repo to another by creating copies. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef migrate_issue(source_repo: str, target_repo: str, issue: dict, token: str):\n owner, name = target_repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues\"\n data = {\n \"title\": f\"[Migrated] {issue['title']}\",\n \"body\": issue.get(\"body\", \"\"),\n }\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0075", "domain": "repo_management", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that syncs a fork with its upstream parent repo via Gitea API. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef sync_fork(repo: str, token: str, branch: str = \"main\"):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls\"\n data = {\"title\": \"Sync upstream\", \"head\": f\"upstream:{branch}\", \"base\": branch, \"body\": \"Automated sync\"}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0230", "domain": "issue_automation", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that assigns a Gitea issue to a specific user. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef assign_issue(repo: str, number: int, assignees: list[str], token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"assignees\": assignees}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0210", "domain": "issue_automation", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that finds all unassigned open issues in a Gitea repo. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef find_unassigned_issues(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues?state=open&type=issues&limit=100\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n issues = json.loads(resp.read().decode())\n return [i for i in issues if not i.get(\"assignee\") and not i.get(\"pull_request\")]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0244", "domain": "repo_management", "prompt": "Create a typed Python utility that Write a Python function that archives a Gitea repo (read-only) via API. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef archive_repo(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"archived\": True}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0188", "domain": "repo_management", "prompt": "Author a defensive Python routine that Write a Python function that checks whether a branch exists in a remote Gitea repo without cloning. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef branch_exists(repo: str, branch: str, token: str) -> bool:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branches/{branch}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n try:\n with urllib.request.urlopen(req, timeout=10) as resp:\n return resp.status == 200\n except urllib.error.HTTPError as e:\n if e.code == 404:\n return False\n raise\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0092", "domain": "pr_workflow", "prompt": "Using only the Python standard library, Write a Python function that triggers a CI pipeline by pushing an empty commit on a PR branch. Log all failures for observability.", "response": "import subprocess\n\ndef trigger_ci(repo_url: str, branch: str):\n subprocess.run(\n [\"git\", \"commit\", \"--allow-empty\", \"-m\", \"ci: trigger pipeline\"],\n check=True, capture_output=True,\n )\n subprocess.run([\"git\", \"push\", repo_url, branch], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0020", "domain": "gitea_api", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that creates a reusable urllib Request object with authentication for repeated Gitea API calls. Include error handling.", "response": "import urllib.request\n\nclass AuthenticatedRequest:\n def __init__(self, base_url: str, token: str):\n self.base_url = base_url.rstrip(\"/\")\n self.token = token\n\n def build(self, path: str, method: str = \"GET\", data: bytes | None = None):\n url = f\"{self.base_url}/api/v1{path}\"\n req = urllib.request.Request(url, data=data, method=method)\n req.add_header(\"Authorization\", f\"token {self.token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n return req\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0108", "domain": "issue_automation", "prompt": "Author a defensive Python routine that Write a Python function that searches Gitea issues across an organization by keyword. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef search_issues(org: str, keyword: str, token: str):\n url = f\"https://forge.example.com/api/v1/repos/search?q={keyword}&uid=0&limit=50\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0201", "domain": "pr_workflow", "prompt": "Write a Python function that creates a pull request on Gitea via API. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef create_pull_request(repo: str, title: str, head: str, base: str, body: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls\"\n data = {\"title\": title, \"head\": head, \"base\": base, \"body\": body}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0017", "domain": "repo_management", "prompt": "Build a reusable module function that Write a Python function that adds a deploy key to a Gitea repo for CI access. Include error handling.", "response": "import urllib.request\nimport json\n\ndef add_deploy_key(repo: str, title: str, key: str, token: str, read_only: bool = True):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/keys\"\n data = {\"title\": title, \"key\": key, \"read_only\": read_only}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0089", "domain": "issue_automation", "prompt": "Draft a minimal but complete solution that Write a Python function that detects stale issues (no activity for 30 days) in a Gitea repo. Log all failures for observability.", "response": "from datetime import datetime, timezone\n\ndef find_stale_issues(issues: list[dict], days: int = 30) -> list[dict]:\n now = datetime.now(timezone.utc)\n stale = []\n for i in issues:\n updated = datetime.fromisoformat(i[\"updated_at\"].replace(\"Z\", \"+00:00\"))\n if (now - updated).days > days:\n stale.append(i)\n return stale\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0109", "domain": "gitea_api", "prompt": "Draft a minimal but complete solution that Write a Python function that sets proper request headers (Authorization, Content-Type, Accept) for Gitea API calls. Validate inputs before making API calls.", "response": "def build_gitea_request(url: str, token: str, method: str = \"GET\", data: bytes | None = None):\n \"\"\"Build a request with standard headers.\"\"\"\n req = urllib.request.Request(url, data=data, method=method)\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n req.add_header(\"Accept\", \"application/json\")\n return req\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0149", "domain": "repo_management", "prompt": "Draft a minimal but complete solution that Write a Python function that renames a branch in a Gitea repo via API. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef rename_branch(repo: str, old: str, new: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branches/{old}\"\n data = {\"name\": new}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0248", "domain": "repo_management", "prompt": "Author a defensive Python routine that Write a Python function that gets the default branch of a Gitea repo. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef get_default_branch(repo: str, token: str) -> str:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n data = json.loads(resp.read().decode())\n return data.get(\"default_branch\", \"main\")\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0037", "domain": "issue_automation", "prompt": "Build a reusable module function that Write a Python function that reopens a closed Gitea issue via API. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef reopen_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"state\": \"open\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0183", "domain": "pr_workflow", "prompt": "Write a robust, production-ready function that Write a Python function that rebases a feature branch onto the base branch before opening a PR. Optimize for minimal external dependencies.", "response": "import subprocess\n\ndef rebase_branch(feature: str, base: str = \"main\"):\n subprocess.run([\"git\", \"checkout\", feature], check=True, capture_output=True)\n subprocess.run([\"git\", \"fetch\", \"origin\", base], check=True, capture_output=True)\n subprocess.run([\"git\", \"rebase\", f\"origin/{base}\"], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0079", "domain": "issue_automation", "prompt": "Draft a minimal but complete solution that Write a Python function that closes a Gitea issue via API. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef close_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"state\": \"closed\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0119", "domain": "issue_automation", "prompt": "Draft a minimal but complete solution that Write a Python function that unlocks a previously locked Gitea issue. Validate inputs before making API calls.", "response": "import urllib.request\n\ndef unlock_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/lock\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0045", "domain": "issue_automation", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that subscribes a user to notifications on a Gitea issue. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef subscribe_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/subscriptions\"\n req = urllib.request.Request(url, data=json.dumps({}).encode(), method=\"PUT\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0196", "domain": "pr_workflow", "prompt": "Design a concise Python snippet that Write a Python function that adds a label to a Gitea pull request. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef add_pr_label(repo: str, pr_number: int, label_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/labels\"\n data = {\"labels\": [label_id]}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0231", "domain": "repo_management", "prompt": "Write a Python function that creates a custom label in a Gitea repo with a specific color. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef create_label(repo: str, name: str, color: str, token: str):\n owner, repo_name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{repo_name}/labels\"\n data = {\"name\": name, \"color\": color}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0038", "domain": "repo_management", "prompt": "Author a defensive Python routine that Write a Python function that checks whether a branch exists in a remote Gitea repo without cloning. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef branch_exists(repo: str, branch: str, token: str) -> bool:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branches/{branch}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n try:\n with urllib.request.urlopen(req, timeout=10) as resp:\n return resp.status == 200\n except urllib.error.HTTPError as e:\n if e.code == 404:\n return False\n raise\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0196", "domain": "issue_automation", "prompt": "Design a concise Python snippet that Write a Python function that unsubscribes a user from notifications on a Gitea issue. Optimize for minimal external dependencies.", "response": "import urllib.request\n\ndef unsubscribe_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/subscriptions\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0077", "domain": "gitea_api", "prompt": "Build a reusable module function that Write a Python function that reads a Gitea API token from standard local paths and returns it. Log all failures for observability.", "response": "from pathlib import Path\n\ndef read_gitea_token() -> str:\n \"\"\"Read token from standard locations.\"\"\"\n for path in [\n Path.home() / \".hermes\" / \"gitea_token\",\n Path.home() / \".config\" / \"gitea\" / \"token\",\n ]:\n if path.exists():\n return path.read_text().strip()\n raise FileNotFoundError(\"No Gitea token found\")\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0207", "domain": "pr_workflow", "prompt": "Build a reusable module function that Write a Python function that checks whether a Gitea pull request is mergeable. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef is_mergeable(repo: str, pr_number: int, token: str) -> bool:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n data = json.loads(resp.read().decode())\n return data.get(\"mergeable\", False)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0188", "domain": "issue_automation", "prompt": "Author a defensive Python routine that Write a Python function that fetches the full timeline (comments) of a Gitea issue. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef get_issue_timeline(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/comments\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0083", "domain": "repo_management", "prompt": "Write a robust, production-ready function that Write a Python function that creates a milestone in a Gitea repo with a due date. Log all failures for observability.", "response": "import urllib.request\nimport json\nfrom datetime import datetime, timezone\n\ndef create_milestone(repo: str, title: str, due_date: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/milestones\"\n data = {\"title\": title, \"due_on\": due_date}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0073", "domain": "issue_automation", "prompt": "Write a robust, production-ready function that Write a Python function that removes a milestone from a Gitea issue. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef remove_milestone(repo: str, issue_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{issue_number}\"\n data = {\"milestone\": 0}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0176", "domain": "issue_automation", "prompt": "Design a concise Python snippet that Write a Python function that fetches open issues from a Gitea repo and filters out pull requests. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef fetch_open_issues(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues?state=open&type=issues&limit=100\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return [i for i in json.loads(resp.read().decode()) if not i.get(\"pull_request\")]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0216", "domain": "gitea_api", "prompt": "Design a concise Python snippet that Write a Python function that implements rate-limit awareness by reading the X-RateLimit-Remaining header. Add timeout and connection cleanup.", "response": "import urllib.request\n\ndef check_rate_limit(resp: urllib.request.addinfourl) -> int:\n \"\"\"Read X-RateLimit-Remaining from response headers.\"\"\"\n remaining = resp.headers.get(\"X-RateLimit-Remaining\")\n return int(remaining) if remaining else -1\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0132", "domain": "gitea_api", "prompt": "Using only the Python standard library, Write a Python function that uses urllib (no external deps) to POST JSON data to the Gitea API. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef gitea_post_json(base_url: str, path: str, token: str, data: dict):\n \"\"\"POST JSON to Gitea API using only stdlib.\"\"\"\n url = f\"{base_url.rstrip('/')}/api/v1{path}\"\n body = json.dumps(data).encode(\"utf-8\")\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n req.add_header(\"Accept\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n raw = resp.read().decode()\n return json.loads(raw) if raw.strip() else {}\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0141", "domain": "pr_workflow", "prompt": "Write a Python function that gets the diff of a Gitea pull request as raw text. Handle empty responses gracefully.", "response": "import urllib.request\n\ndef get_pr_diff(repo: str, pr_number: int, token: str) -> str:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}.diff\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.read().decode()\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0169", "domain": "issue_automation", "prompt": "Draft a minimal but complete solution that Write a Python function that unlocks a previously locked Gitea issue. Include docstrings and type hints.", "response": "import urllib.request\n\ndef unlock_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/lock\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0189", "domain": "gitea_api", "prompt": "Draft a minimal but complete solution that Write a Python function that measures the latency of a Gitea API call and raises a warning if it exceeds 2 seconds. Optimize for minimal external dependencies.", "response": "import time\nimport urllib.request\n\ndef timed_request(req: urllib.request.Request, threshold: float = 2.0):\n \"\"\"Execute request and warn if latency exceeds threshold.\"\"\"\n start = time.time()\n with urllib.request.urlopen(req, timeout=30) as resp:\n body = resp.read().decode()\n elapsed = time.time() - start\n if elapsed > threshold:\n print(f\"WARNING: Request took {elapsed:.2f}s\")\n return body\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0039", "domain": "repo_management", "prompt": "Draft a minimal but complete solution that Write a Python function that forks a Gitea repo into another organization via API. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef fork_repo(repo: str, org: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/forks\"\n data = {\"organization\": org}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0208", "domain": "pr_workflow", "prompt": "Author a defensive Python routine that Write a Python function that rebases a feature branch onto the base branch before opening a PR. Add timeout and connection cleanup.", "response": "import subprocess\n\ndef rebase_branch(feature: str, base: str = \"main\"):\n subprocess.run([\"git\", \"checkout\", feature], check=True, capture_output=True)\n subprocess.run([\"git\", \"fetch\", \"origin\", base], check=True, capture_output=True)\n subprocess.run([\"git\", \"rebase\", f\"origin/{base}\"], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0206", "domain": "issue_automation", "prompt": "Design a concise Python snippet that Write a Python function that checks whether a Gitea issue already has a bot comment to avoid duplicate comments. Add timeout and connection cleanup.", "response": "def has_bot_comment(comments: list[dict], bot_marker: str = \"🤖\") -> bool:\n return any(bot_marker in c.get(\"body\", \"\") for c in comments)\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0124", "domain": "issue_automation", "prompt": "Create a typed Python utility that Write a Python function that finds issues created by a specific user in a Gitea repo. Validate inputs before making API calls.", "response": "def find_issues_by_author(issues: list[dict], username: str) -> list[dict]:\n return [i for i in issues if i.get(\"user\", {}).get(\"login\") == username]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0120", "domain": "gitea_api", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that creates a reusable urllib Request object with authentication for repeated Gitea API calls. Validate inputs before making API calls.", "response": "import urllib.request\n\nclass AuthenticatedRequest:\n def __init__(self, base_url: str, token: str):\n self.base_url = base_url.rstrip(\"/\")\n self.token = token\n\n def build(self, path: str, method: str = \"GET\", data: bytes | None = None):\n url = f\"{self.base_url}/api/v1{path}\"\n req = urllib.request.Request(url, data=data, method=method)\n req.add_header(\"Authorization\", f\"token {self.token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n return req\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0144", "domain": "pr_workflow", "prompt": "Create a typed Python utility that Write a Python function that auto-squashes all commits on a PR branch before merging. Handle empty responses gracefully.", "response": "import subprocess\n\ndef autosquash_branch(branch: str, base: str = \"main\"):\n subprocess.run([\"git\", \"checkout\", branch], check=True, capture_output=True)\n subprocess.run([\"git\", \"reset\", f\"origin/{base}\"], check=True, capture_output=True)\n subprocess.run([\"git\", \"add\", \"-A\"], check=True, capture_output=True)\n subprocess.run([\"git\", \"commit\", \"-m\", f\"feat: squash {branch}\"], check=True, capture_output=True)\n subprocess.run([\"git\", \"push\", \"--force-with-lease\", \"origin\", branch], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0122", "domain": "repo_management", "prompt": "Using only the Python standard library, Write a Python function that sets a repo topic (tag) via the Gitea API. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef set_repo_topic(repo: str, topic: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/topics\"\n data = {\"topics\": [topic]}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PUT\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0129", "domain": "issue_automation", "prompt": "Draft a minimal but complete solution that Write a Python function that closes a Gitea issue via API. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef close_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"state\": \"closed\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0098", "domain": "repo_management", "prompt": "Author a defensive Python routine that Write a Python function that gets the default branch of a Gitea repo. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef get_default_branch(repo: str, token: str) -> str:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n data = json.loads(resp.read().decode())\n return data.get(\"default_branch\", \"main\")\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0130", "domain": "gitea_api", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that handles HTTP 401, 403, 404, and 500 errors from the Gitea API gracefully. Handle empty responses gracefully.", "response": "import urllib.error\n\nclass GiteaError(Exception):\n def __init__(self, status: int, message: str):\n self.status = status\n super().__init__(f\"Gitea {status}: {message}\")\n\ndef handle_gitea_error(e: urllib.error.HTTPError) -> None:\n \"\"\"Map HTTP errors to typed exceptions.\"\"\"\n body = e.read().decode(errors=\"replace\") if e.fp else \"\"\n if e.code == 401:\n raise GiteaError(401, f\"Unauthorized. Check your token. {body}\")\n if e.code == 403:\n raise GiteaError(403, f\"Forbidden. {body}\")\n if e.code == 404:\n raise GiteaError(404, f\"Not found. {body}\")\n if e.code >= 500:\n raise GiteaError(e.code, f\"Server error. {body}\")\n raise GiteaError(e.code, body)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0036", "domain": "issue_automation", "prompt": "Design a concise Python snippet that Write a Python function that counts open issues per label in a Gitea repo. Add retry logic with exponential backoff.", "response": "from collections import Counter\n\ndef count_issues_per_label(issues: list[dict]) -> Counter:\n counts = Counter()\n for i in issues:\n for label in i.get(\"labels\", []):\n counts[label.get(\"name\", \"unknown\")] += 1\n return counts\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0105", "domain": "gitea_api", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that handles HTTP 401, 403, 404, and 500 errors from the Gitea API gracefully. Validate inputs before making API calls.", "response": "import urllib.error\n\nclass GiteaError(Exception):\n def __init__(self, status: int, message: str):\n self.status = status\n super().__init__(f\"Gitea {status}: {message}\")\n\ndef handle_gitea_error(e: urllib.error.HTTPError) -> None:\n \"\"\"Map HTTP errors to typed exceptions.\"\"\"\n body = e.read().decode(errors=\"replace\") if e.fp else \"\"\n if e.code == 401:\n raise GiteaError(401, f\"Unauthorized. Check your token. {body}\")\n if e.code == 403:\n raise GiteaError(403, f\"Forbidden. {body}\")\n if e.code == 404:\n raise GiteaError(404, f\"Not found. {body}\")\n if e.code >= 500:\n raise GiteaError(e.code, f\"Server error. {body}\")\n raise GiteaError(e.code, body)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0094", "domain": "issue_automation", "prompt": "Create a typed Python utility that Write a Python function that unlocks a previously locked Gitea issue. Log all failures for observability.", "response": "import urllib.request\n\ndef unlock_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/lock\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0099", "domain": "pr_workflow", "prompt": "Draft a minimal but complete solution that Write a Python function that fetches the commit history of a PR branch. Log all failures for observability.", "response": "import subprocess\n\ndef get_pr_commits(branch: str, base: str = \"main\") -> list[str]:\n result = subprocess.run(\n [\"git\", \"log\", f\"origin/{base}..{branch}\", \"--pretty=format:%H %s\"],\n capture_output=True, text=True, check=True,\n )\n return result.stdout.strip().split(\"\n\") if result.stdout.strip() else []\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0016", "domain": "issue_automation", "prompt": "Design a concise Python snippet that Write a Python function that migrates issues from one Gitea repo to another by creating copies. Include error handling.", "response": "import urllib.request\nimport json\n\ndef migrate_issue(source_repo: str, target_repo: str, issue: dict, token: str):\n owner, name = target_repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues\"\n data = {\n \"title\": f\"[Migrated] {issue['title']}\",\n \"body\": issue.get(\"body\", \"\"),\n }\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0049", "domain": "issue_automation", "prompt": "Draft a minimal but complete solution that Write a Python function that finds issues created by a specific user in a Gitea repo. Add retry logic with exponential backoff.", "response": "def find_issues_by_author(issues: list[dict], username: str) -> list[dict]:\n return [i for i in issues if i.get(\"user\", {}).get(\"login\") == username]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0071", "domain": "issue_automation", "prompt": "Write a Python function that unsubscribes a user from notifications on a Gitea issue. Return typed dataclasses where appropriate.", "response": "import urllib.request\n\ndef unsubscribe_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/subscriptions\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0155", "domain": "gitea_api", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that handles HTTP 401, 403, 404, and 500 errors from the Gitea API gracefully. Include docstrings and type hints.", "response": "import urllib.error\n\nclass GiteaError(Exception):\n def __init__(self, status: int, message: str):\n self.status = status\n super().__init__(f\"Gitea {status}: {message}\")\n\ndef handle_gitea_error(e: urllib.error.HTTPError) -> None:\n \"\"\"Map HTTP errors to typed exceptions.\"\"\"\n body = e.read().decode(errors=\"replace\") if e.fp else \"\"\n if e.code == 401:\n raise GiteaError(401, f\"Unauthorized. Check your token. {body}\")\n if e.code == 403:\n raise GiteaError(403, f\"Forbidden. {body}\")\n if e.code == 404:\n raise GiteaError(404, f\"Not found. {body}\")\n if e.code >= 500:\n raise GiteaError(e.code, f\"Server error. {body}\")\n raise GiteaError(e.code, body)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0149", "domain": "gitea_api", "prompt": "Draft a minimal but complete solution that Write a Python function that attaches a custom User-Agent header to all Gitea API requests. Handle empty responses gracefully.", "response": "import urllib.request\n\ndef request_with_user_agent(url: str, token: str, agent: str = \"timmy-bot/1.0\"):\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"User-Agent\", agent)\n return req\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0143", "domain": "issue_automation", "prompt": "Write a robust, production-ready function that Write a Python function that locks a Gitea issue to prevent further comments. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef lock_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/lock\"\n req = urllib.request.Request(url, data=json.dumps({}).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0249", "domain": "issue_automation", "prompt": "Draft a minimal but complete solution that Write a Python function that finds issues created by a specific user in a Gitea repo. Surface clear exception messages on failure.", "response": "def find_issues_by_author(issues: list[dict], username: str) -> list[dict]:\n return [i for i in issues if i.get(\"user\", {}).get(\"login\") == username]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0041", "domain": "pr_workflow", "prompt": "Write a Python function that gets the diff of a Gitea pull request as raw text. Add retry logic with exponential backoff.", "response": "import urllib.request\n\ndef get_pr_diff(repo: str, pr_number: int, token: str) -> str:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}.diff\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.read().decode()\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0209", "domain": "pr_workflow", "prompt": "Draft a minimal but complete solution that Write a Python function that updates the description of an existing Gitea pull request. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef update_pr_description(repo: str, pr_number: int, new_body: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}\"\n data = {\"body\": new_body}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0024", "domain": "pr_workflow", "prompt": "Create a typed Python utility that Write a Python function that fetches the commit history of a PR branch. Include error handling.", "response": "import subprocess\n\ndef get_pr_commits(branch: str, base: str = \"main\") -> list[str]:\n result = subprocess.run(\n [\"git\", \"log\", f\"origin/{base}..{branch}\", \"--pretty=format:%H %s\"],\n capture_output=True, text=True, check=True,\n )\n return result.stdout.strip().split(\"\n\") if result.stdout.strip() else []\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0063", "domain": "pr_workflow", "prompt": "Write a robust, production-ready function that Write a Python function that closes a pull request without merging it. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef close_pr(repo: str, pr_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}\"\n data = {\"state\": \"closed\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0117", "domain": "gitea_api", "prompt": "Build a reusable module function that Write a Python function that serializes a Python dict into JSON and sends it as the body of a PATCH request to Gitea. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef gitea_patch(base_url: str, path: str, token: str, data: dict):\n \"\"\"Serialize dict to JSON and PATCH.\"\"\"\n url = f\"{base_url.rstrip('/')}/api/v1{path}\"\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0121", "domain": "pr_workflow", "prompt": "Write a Python function that adds a label to a Gitea pull request. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef add_pr_label(repo: str, pr_number: int, label_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/labels\"\n data = {\"labels\": [label_id]}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0083", "domain": "pr_workflow", "prompt": "Write a robust, production-ready function that Write a Python function that rebases a feature branch onto the base branch before opening a PR. Log all failures for observability.", "response": "import subprocess\n\ndef rebase_branch(feature: str, base: str = \"main\"):\n subprocess.run([\"git\", \"checkout\", feature], check=True, capture_output=True)\n subprocess.run([\"git\", \"fetch\", \"origin\", base], check=True, capture_output=True)\n subprocess.run([\"git\", \"rebase\", f\"origin/{base}\"], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0080", "domain": "pr_workflow", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that posts a review comment on a Gitea pull request. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef review_comment(repo: str, pr_number: int, body: str, token: str, path: str = \"\", position: int = 0):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/reviews\"\n data = {\"body\": body, \"event\": \"COMMENT\"}\n if path:\n data[\"comments\"] = [{\"path\": path, \"position\": position, \"body\": body}]\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0182", "domain": "repo_management", "prompt": "Using only the Python standard library, Write a Python function that lists all labels in a Gitea repo. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef list_labels(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/labels\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0135", "domain": "repo_management", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that performs a sparse checkout of a single directory from a Gitea repo. Handle empty responses gracefully.", "response": "import subprocess\nfrom pathlib import Path\n\ndef sparse_checkout(repo_url: str, dest: str, directory: str):\n \"\"\"Sparse checkout a single directory.\"\"\"\n Path(dest).mkdir(parents=True, exist_ok=True)\n subprocess.run([\"git\", \"init\", dest], check=True, capture_output=True)\n subprocess.run([\"git\", \"-C\", dest, \"remote\", \"add\", \"origin\", repo_url], check=True, capture_output=True)\n subprocess.run([\"git\", \"-C\", dest, \"config\", \"core.sparseCheckout\", \"true\"], check=True, capture_output=True)\n sparse_file = Path(dest) / \".git\" / \"info\" / \"sparse-checkout\"\n sparse_file.write_text(directory + \"\\n\")\n subprocess.run([\"git\", \"-C\", dest, \"pull\", \"origin\", \"main\"], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0035", "domain": "repo_management", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that performs a sparse checkout of a single directory from a Gitea repo. Add retry logic with exponential backoff.", "response": "import subprocess\nfrom pathlib import Path\n\ndef sparse_checkout(repo_url: str, dest: str, directory: str):\n \"\"\"Sparse checkout a single directory.\"\"\"\n Path(dest).mkdir(parents=True, exist_ok=True)\n subprocess.run([\"git\", \"init\", dest], check=True, capture_output=True)\n subprocess.run([\"git\", \"-C\", dest, \"remote\", \"add\", \"origin\", repo_url], check=True, capture_output=True)\n subprocess.run([\"git\", \"-C\", dest, \"config\", \"core.sparseCheckout\", \"true\"], check=True, capture_output=True)\n sparse_file = Path(dest) / \".git\" / \"info\" / \"sparse-checkout\"\n sparse_file.write_text(directory + \"\\n\")\n subprocess.run([\"git\", \"-C\", dest, \"pull\", \"origin\", \"main\"], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0169", "domain": "pr_workflow", "prompt": "Draft a minimal but complete solution that Write a Python function that auto-squashes all commits on a PR branch before merging. Include docstrings and type hints.", "response": "import subprocess\n\ndef autosquash_branch(branch: str, base: str = \"main\"):\n subprocess.run([\"git\", \"checkout\", branch], check=True, capture_output=True)\n subprocess.run([\"git\", \"reset\", f\"origin/{base}\"], check=True, capture_output=True)\n subprocess.run([\"git\", \"add\", \"-A\"], check=True, capture_output=True)\n subprocess.run([\"git\", \"commit\", \"-m\", f\"feat: squash {branch}\"], check=True, capture_output=True)\n subprocess.run([\"git\", \"push\", \"--force-with-lease\", \"origin\", branch], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0195", "domain": "pr_workflow", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that generates a release notes draft from merged PRs since the last tag. Optimize for minimal external dependencies.", "response": "def generate_release_notes(merged_prs: list[dict], tag: str) -> str:\n lines = [f\"## Release {tag}\", \"\"]\n for pr in merged_prs:\n lines.append(f\"- #{pr['number']} {pr['title']}\")\n return \"\n\".join(lines)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0019", "domain": "issue_automation", "prompt": "Draft a minimal but complete solution that Write a Python function that unlocks a previously locked Gitea issue. Include error handling.", "response": "import urllib.request\n\ndef unlock_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/lock\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0232", "domain": "repo_management", "prompt": "Using only the Python standard library, Write a Python function that lists all labels in a Gitea repo. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef list_labels(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/labels\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0168", "domain": "gitea_api", "prompt": "Author a defensive Python routine that Write a Python function that safely reads the response body from a Gitea API call even when the server returns an empty body. Include docstrings and type hints.", "response": "import urllib.request\n\ndef safe_read_response(resp: urllib.request.addinfourl) -> dict:\n \"\"\"Return parsed JSON or empty dict if body is empty.\"\"\"\n raw = resp.read().decode()\n if not raw.strip():\n return {}\n import json\n return json.loads(raw)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0033", "domain": "pr_workflow", "prompt": "Write a robust, production-ready function that Write a Python function that rebases a feature branch onto the base branch before opening a PR. Add retry logic with exponential backoff.", "response": "import subprocess\n\ndef rebase_branch(feature: str, base: str = \"main\"):\n subprocess.run([\"git\", \"checkout\", feature], check=True, capture_output=True)\n subprocess.run([\"git\", \"fetch\", \"origin\", base], check=True, capture_output=True)\n subprocess.run([\"git\", \"rebase\", f\"origin/{base}\"], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0170", "domain": "repo_management", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that un-archives a Gitea repo via API. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef unarchive_repo(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"archived\": False}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0203", "domain": "repo_management", "prompt": "Write a robust, production-ready function that Write a Python function that sets a webhook on a Gitea repo to trigger on push events. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef set_push_webhook(repo: str, token: str, webhook_url: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/hooks\"\n data = {\n \"type\": \"gitea\",\n \"config\": {\"url\": webhook_url, \"content_type\": \"json\"},\n \"events\": [\"push\"],\n \"active\": True,\n }\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0218", "domain": "gitea_api", "prompt": "Author a defensive Python routine that Write a Python function that safely reads the response body from a Gitea API call even when the server returns an empty body. Add timeout and connection cleanup.", "response": "import urllib.request\n\ndef safe_read_response(resp: urllib.request.addinfourl) -> dict:\n \"\"\"Return parsed JSON or empty dict if body is empty.\"\"\"\n raw = resp.read().decode()\n if not raw.strip():\n return {}\n import json\n return json.loads(raw)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0178", "domain": "pr_workflow", "prompt": "Author a defensive Python routine that Write a Python function that lists all open pull requests for a Gitea repo. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef list_open_prs(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls?state=open&limit=100\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0172", "domain": "issue_automation", "prompt": "Using only the Python standard library, Write a Python function that sets a milestone on a Gitea issue. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef set_milestone(repo: str, issue_number: int, milestone_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{issue_number}\"\n data = {\"milestone\": milestone_id}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0066", "domain": "issue_automation", "prompt": "Design a concise Python snippet that Write a Python function that migrates issues from one Gitea repo to another by creating copies. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef migrate_issue(source_repo: str, target_repo: str, issue: dict, token: str):\n owner, name = target_repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues\"\n data = {\n \"title\": f\"[Migrated] {issue['title']}\",\n \"body\": issue.get(\"body\", \"\"),\n }\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0042", "domain": "pr_workflow", "prompt": "Using only the Python standard library, Write a Python function that triggers a CI pipeline by pushing an empty commit on a PR branch. Add retry logic with exponential backoff.", "response": "import subprocess\n\ndef trigger_ci(repo_url: str, branch: str):\n subprocess.run(\n [\"git\", \"commit\", \"--allow-empty\", \"-m\", \"ci: trigger pipeline\"],\n check=True, capture_output=True,\n )\n subprocess.run([\"git\", \"push\", repo_url, branch], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0050", "domain": "gitea_api", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that closes idle Gitea API connections after 30 seconds to prevent socket exhaustion. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport socket\n\nclass TimeoutHTTPHandler(urllib.request.HTTPHandler):\n def __init__(self, timeout: int = 30):\n self.timeout = timeout\n super().__init__()\n\n def http_open(self, req):\n return self.do_open(lambda host, port: http.client.HTTPConnection(host, port, timeout=self.timeout), req)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0025", "domain": "pr_workflow", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that cherry-picks a commit from one branch to another via Gitea API. Include error handling.", "response": "import urllib.request\nimport json\n\ndef cherry_pick_commit(repo: str, commit_sha: str, target_branch: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/git/commits\"\n data = {\"message\": f\"cherry-pick {commit_sha}\", \"parents\": [target_branch], \"tree\": commit_sha}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0084", "domain": "issue_automation", "prompt": "Create a typed Python utility that Write a Python function that calculates the age of a Gitea issue in days from its created_at timestamp. Log all failures for observability.", "response": "from datetime import datetime, timezone\n\ndef issue_age_days(created_at: str) -> int:\n \"\"\"Calculate age of an issue in days.\"\"\"\n fmt = \"%Y-%m-%dT%H:%M:%SZ\"\n created = datetime.strptime(created_at, fmt).replace(tzinfo=timezone.utc)\n return (datetime.now(timezone.utc) - created).days\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0222", "domain": "issue_automation", "prompt": "Using only the Python standard library, Write a Python function that sets a milestone on a Gitea issue. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef set_milestone(repo: str, issue_number: int, milestone_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{issue_number}\"\n data = {\"milestone\": milestone_id}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0164", "domain": "repo_management", "prompt": "Create a typed Python utility that Write a Python function that forks a Gitea repo into another organization via API. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef fork_repo(repo: str, org: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/forks\"\n data = {\"organization\": org}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0125", "domain": "pr_workflow", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that cherry-picks a commit from one branch to another via Gitea API. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef cherry_pick_commit(repo: str, commit_sha: str, target_branch: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/git/commits\"\n data = {\"message\": f\"cherry-pick {commit_sha}\", \"parents\": [target_branch], \"tree\": commit_sha}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0075", "domain": "issue_automation", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that updates the title of a Gitea issue via API. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef update_issue_title(repo: str, number: int, new_title: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"title\": new_title}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0121", "domain": "issue_automation", "prompt": "Write a Python function that unsubscribes a user from notifications on a Gitea issue. Validate inputs before making API calls.", "response": "import urllib.request\n\ndef unsubscribe_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/subscriptions\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0007", "domain": "repo_management", "prompt": "Build a reusable module function that Write a Python function that lists all labels in a Gitea repo. Include error handling.", "response": "import urllib.request\nimport json\n\ndef list_labels(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/labels\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0068", "domain": "issue_automation", "prompt": "Author a defensive Python routine that Write a Python function that locks a Gitea issue to prevent further comments. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef lock_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/lock\"\n req = urllib.request.Request(url, data=json.dumps({}).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0035", "domain": "issue_automation", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that finds all unassigned open issues in a Gitea repo. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef find_unassigned_issues(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues?state=open&type=issues&limit=100\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n issues = json.loads(resp.read().decode())\n return [i for i in issues if not i.get(\"assignee\") and not i.get(\"pull_request\")]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0082", "domain": "repo_management", "prompt": "Using only the Python standard library, Write a Python function that lists all labels in a Gitea repo. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef list_labels(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/labels\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0244", "domain": "gitea_api", "prompt": "Create a typed Python utility that Write a Python function that compares two Gitea API base URLs and normalizes them by stripping trailing slashes. Surface clear exception messages on failure.", "response": "def normalize_base_url(url: str) -> str:\n \"\"\"Strip trailing slashes and ensure no duplicate slashes.\"\"\"\n return url.rstrip(\"/\")\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0189", "domain": "repo_management", "prompt": "Draft a minimal but complete solution that Write a Python function that forks a Gitea repo into another organization via API. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef fork_repo(repo: str, org: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/forks\"\n data = {\"organization\": org}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0234", "domain": "issue_automation", "prompt": "Create a typed Python utility that Write a Python function that calculates the age of a Gitea issue in days from its created_at timestamp. Surface clear exception messages on failure.", "response": "from datetime import datetime, timezone\n\ndef issue_age_days(created_at: str) -> int:\n \"\"\"Calculate age of an issue in days.\"\"\"\n fmt = \"%Y-%m-%dT%H:%M:%SZ\"\n created = datetime.strptime(created_at, fmt).replace(tzinfo=timezone.utc)\n return (datetime.now(timezone.utc) - created).days\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0140", "domain": "repo_management", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that sets branch protection rules: no force-push, require status checks. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef set_strict_protection(repo: str, branch: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branch_protections\"\n data = {\n \"branch_name\": branch,\n \"enable_push\": False,\n \"enable_status_check\": True,\n \"status_check_contexts\": [\"ci/tests\"],\n }\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0065", "domain": "repo_management", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that sets branch protection rules: no force-push, require status checks. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef set_strict_protection(repo: str, branch: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branch_protections\"\n data = {\n \"branch_name\": branch,\n \"enable_push\": False,\n \"enable_status_check\": True,\n \"status_check_contexts\": [\"ci/tests\"],\n }\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0160", "domain": "issue_automation", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that finds all unassigned open issues in a Gitea repo. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef find_unassigned_issues(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues?state=open&type=issues&limit=100\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n issues = json.loads(resp.read().decode())\n return [i for i in issues if not i.get(\"assignee\") and not i.get(\"pull_request\")]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0133", "domain": "repo_management", "prompt": "Write a robust, production-ready function that Write a Python function that creates a milestone in a Gitea repo with a due date. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\nfrom datetime import datetime, timezone\n\ndef create_milestone(repo: str, title: str, due_date: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/milestones\"\n data = {\"title\": title, \"due_on\": due_date}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0077", "domain": "issue_automation", "prompt": "Build a reusable module function that Write a Python function that filters Gitea issues by label name. Log all failures for observability.", "response": "def filter_by_label(issues: list[dict], label: str) -> list[dict]:\n return [i for i in issues if any(l.get(\"name\") == label for l in i.get(\"labels\", []))]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0193", "domain": "repo_management", "prompt": "Write a robust, production-ready function that Write a Python function that enables issue tracking on a Gitea repo via API. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef enable_issues(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"has_issues\": True}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0207", "domain": "gitea_api", "prompt": "Build a reusable module function that Write a Python function that uses urllib (no external deps) to POST JSON data to the Gitea API. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef gitea_post_json(base_url: str, path: str, token: str, data: dict):\n \"\"\"POST JSON to Gitea API using only stdlib.\"\"\"\n url = f\"{base_url.rstrip('/')}/api/v1{path}\"\n body = json.dumps(data).encode(\"utf-8\")\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n req.add_header(\"Accept\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n raw = resp.read().decode()\n return json.loads(raw) if raw.strip() else {}\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0184", "domain": "repo_management", "prompt": "Create a typed Python utility that Write a Python function that clones a Gitea repo with --depth 1 for a shallow clone. Optimize for minimal external dependencies.", "response": "import subprocess\n\ndef shallow_clone(repo_url: str, dest: str, branch: str = \"main\"):\n \"\"\"Clone with --depth 1 to save time and space.\"\"\"\n subprocess.run(\n [\"git\", \"clone\", \"--depth\", \"1\", \"--branch\", branch, repo_url, dest],\n check=True,\n capture_output=True,\n )\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0073", "domain": "pr_workflow", "prompt": "Write a robust, production-ready function that Write a Python function that blocks merging if a PR does not have at least one approved review. Return typed dataclasses where appropriate.", "response": "def require_approval(pr: dict, reviews: list[dict]) -> bool:\n if pr.get(\"state\") != \"open\":\n return False\n approvals = [r for r in reviews if r.get(\"state\") == \"APPROVED\"]\n return len(approvals) >= 1\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0131", "domain": "repo_management", "prompt": "Write a Python function that creates a custom label in a Gitea repo with a specific color. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef create_label(repo: str, name: str, color: str, token: str):\n owner, repo_name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{repo_name}/labels\"\n data = {\"name\": name, \"color\": color}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0118", "domain": "gitea_api", "prompt": "Author a defensive Python routine that Write a Python function that safely reads the response body from a Gitea API call even when the server returns an empty body. Validate inputs before making API calls.", "response": "import urllib.request\n\ndef safe_read_response(resp: urllib.request.addinfourl) -> dict:\n \"\"\"Return parsed JSON or empty dict if body is empty.\"\"\"\n raw = resp.read().decode()\n if not raw.strip():\n return {}\n import json\n return json.loads(raw)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0101", "domain": "repo_management", "prompt": "Write a Python function that creates a new Gitea repo under an organization via API. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef create_repo(org: str, name: str, token: str, description: str = \"\", private: bool = False):\n url = f\"https://forge.example.com/api/v1/orgs/{org}/repos\"\n data = {\"name\": name, \"description\": description, \"private\": private}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0221", "domain": "repo_management", "prompt": "Write a Python function that transfers a Gitea repo from one owner to another. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef transfer_repo(repo: str, new_owner: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/transfer\"\n data = {\"new_owner\": new_owner}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0018", "domain": "repo_management", "prompt": "Author a defensive Python routine that Write a Python function that enables issue tracking on a Gitea repo via API. Include error handling.", "response": "import urllib.request\nimport json\n\ndef enable_issues(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"has_issues\": True}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0074", "domain": "pr_workflow", "prompt": "Create a typed Python utility that Write a Python function that fetches the commit history of a PR branch. Return typed dataclasses where appropriate.", "response": "import subprocess\n\ndef get_pr_commits(branch: str, base: str = \"main\") -> list[str]:\n result = subprocess.run(\n [\"git\", \"log\", f\"origin/{base}..{branch}\", \"--pretty=format:%H %s\"],\n capture_output=True, text=True, check=True,\n )\n return result.stdout.strip().split(\"\n\") if result.stdout.strip() else []\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0091", "domain": "issue_automation", "prompt": "Write a Python function that migrates issues from one Gitea repo to another by creating copies. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef migrate_issue(source_repo: str, target_repo: str, issue: dict, token: str):\n owner, name = target_repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues\"\n data = {\n \"title\": f\"[Migrated] {issue['title']}\",\n \"body\": issue.get(\"body\", \"\"),\n }\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0148", "domain": "repo_management", "prompt": "Author a defensive Python routine that Write a Python function that gets the default branch of a Gitea repo. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef get_default_branch(repo: str, token: str) -> str:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n data = json.loads(resp.read().decode())\n return data.get(\"default_branch\", \"main\")\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0155", "domain": "pr_workflow", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that posts a review comment on a Gitea pull request. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef review_comment(repo: str, pr_number: int, body: str, token: str, path: str = \"\", position: int = 0):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/reviews\"\n data = {\"body\": body, \"event\": \"COMMENT\"}\n if path:\n data[\"comments\"] = [{\"path\": path, \"position\": position, \"body\": body}]\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0008", "domain": "pr_workflow", "prompt": "Author a defensive Python routine that Write a Python function that rebases a feature branch onto the base branch before opening a PR. Include error handling.", "response": "import subprocess\n\ndef rebase_branch(feature: str, base: str = \"main\"):\n subprocess.run([\"git\", \"checkout\", feature], check=True, capture_output=True)\n subprocess.run([\"git\", \"fetch\", \"origin\", base], check=True, capture_output=True)\n subprocess.run([\"git\", \"rebase\", f\"origin/{base}\"], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0142", "domain": "repo_management", "prompt": "Using only the Python standard library, Write a Python function that adds a deploy key to a Gitea repo for CI access. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef add_deploy_key(repo: str, title: str, key: str, token: str, read_only: bool = True):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/keys\"\n data = {\"title\": title, \"key\": key, \"read_only\": read_only}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0125", "domain": "repo_management", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that syncs a fork with its upstream parent repo via Gitea API. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef sync_fork(repo: str, token: str, branch: str = \"main\"):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls\"\n data = {\"title\": \"Sync upstream\", \"head\": f\"upstream:{branch}\", \"base\": branch, \"body\": \"Automated sync\"}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0081", "domain": "pr_workflow", "prompt": "Write a Python function that requests a specific user to review a Gitea pull request. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef request_review(repo: str, pr_number: int, reviewers: list[str], token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/requested_reviewers\"\n data = {\"reviewers\": reviewers}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0032", "domain": "pr_workflow", "prompt": "Using only the Python standard library, Write a Python function that checks whether a Gitea pull request is mergeable. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef is_mergeable(repo: str, pr_number: int, token: str) -> bool:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n data = json.loads(resp.read().decode())\n return data.get(\"mergeable\", False)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0004", "domain": "gitea_api", "prompt": "Create a typed Python utility that Write a Python function that makes an authenticated GET request to the Gitea API with retries and exponential backoff. Include error handling.", "response": "import urllib.request\nimport urllib.error\nimport json\nimport time\n\ndef gitea_get_with_retries(url: str, token: str, retries: int = 3, backoff: float = 1.5):\n \"\"\"Authenticated GET with exponential backoff.\"\"\"\n for attempt in range(retries):\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n try:\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n except urllib.error.HTTPError as e:\n if 400 <= e.code < 500 and e.code != 429:\n raise\n if attempt == retries - 1:\n raise\n except urllib.error.URLError:\n if attempt == retries - 1:\n raise\n time.sleep(backoff ** attempt)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0067", "domain": "gitea_api", "prompt": "Build a reusable module function that Write a Python function that serializes a Python dict into JSON and sends it as the body of a PATCH request to Gitea. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef gitea_patch(base_url: str, path: str, token: str, data: dict):\n \"\"\"Serialize dict to JSON and PATCH.\"\"\"\n url = f\"{base_url.rstrip('/')}/api/v1{path}\"\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0210", "domain": "gitea_api", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that implements a circuit breaker for Gitea API requests after 3 consecutive failures. Add timeout and connection cleanup.", "response": "class CircuitBreaker:\n def __init__(self, threshold: int = 3):\n self.failures = 0\n self.threshold = threshold\n self.open = False\n\n def call(self, fn, *args, **kwargs):\n if self.open:\n raise RuntimeError(\"Circuit breaker is OPEN\")\n try:\n result = fn(*args, **kwargs)\n self.failures = 0\n return result\n except Exception:\n self.failures += 1\n if self.failures >= self.threshold:\n self.open = True\n raise\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0099", "domain": "issue_automation", "prompt": "Draft a minimal but complete solution that Write a Python function that finds issues created by a specific user in a Gitea repo. Log all failures for observability.", "response": "def find_issues_by_author(issues: list[dict], username: str) -> list[dict]:\n return [i for i in issues if i.get(\"user\", {}).get(\"login\") == username]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0192", "domain": "pr_workflow", "prompt": "Using only the Python standard library, Write a Python function that triggers a CI pipeline by pushing an empty commit on a PR branch. Optimize for minimal external dependencies.", "response": "import subprocess\n\ndef trigger_ci(repo_url: str, branch: str):\n subprocess.run(\n [\"git\", \"commit\", \"--allow-empty\", \"-m\", \"ci: trigger pipeline\"],\n check=True, capture_output=True,\n )\n subprocess.run([\"git\", \"push\", repo_url, branch], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0050", "domain": "repo_management", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that syncs a fork with its upstream parent repo via Gitea API. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef sync_fork(repo: str, token: str, branch: str = \"main\"):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls\"\n data = {\"title\": \"Sync upstream\", \"head\": f\"upstream:{branch}\", \"base\": branch, \"body\": \"Automated sync\"}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0182", "domain": "gitea_api", "prompt": "Using only the Python standard library, Write a Python function that uses urllib (no external deps) to POST JSON data to the Gitea API. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef gitea_post_json(base_url: str, path: str, token: str, data: dict):\n \"\"\"POST JSON to Gitea API using only stdlib.\"\"\"\n url = f\"{base_url.rstrip('/')}/api/v1{path}\"\n body = json.dumps(data).encode(\"utf-8\")\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n req.add_header(\"Accept\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n raw = resp.read().decode()\n return json.loads(raw) if raw.strip() else {}\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0101", "domain": "pr_workflow", "prompt": "Write a Python function that creates a pull request on Gitea via API. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef create_pull_request(repo: str, title: str, head: str, base: str, body: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls\"\n data = {\"title\": title, \"head\": head, \"base\": base, \"body\": body}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0199", "domain": "pr_workflow", "prompt": "Draft a minimal but complete solution that Write a Python function that fetches the commit history of a PR branch. Optimize for minimal external dependencies.", "response": "import subprocess\n\ndef get_pr_commits(branch: str, base: str = \"main\") -> list[str]:\n result = subprocess.run(\n [\"git\", \"log\", f\"origin/{base}..{branch}\", \"--pretty=format:%H %s\"],\n capture_output=True, text=True, check=True,\n )\n return result.stdout.strip().split(\"\n\") if result.stdout.strip() else []\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0007", "domain": "gitea_api", "prompt": "Build a reusable module function that Write a Python function that uses urllib (no external deps) to POST JSON data to the Gitea API. Include error handling.", "response": "import urllib.request\nimport json\n\ndef gitea_post_json(base_url: str, path: str, token: str, data: dict):\n \"\"\"POST JSON to Gitea API using only stdlib.\"\"\"\n url = f\"{base_url.rstrip('/')}/api/v1{path}\"\n body = json.dumps(data).encode(\"utf-8\")\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n req.add_header(\"Accept\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n raw = resp.read().decode()\n return json.loads(raw) if raw.strip() else {}\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0165", "domain": "gitea_api", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that caches Gitea API responses for 60 seconds to avoid redundant requests. Include docstrings and type hints.", "response": "import time\nimport json\n\nclass TimedCache:\n def __init__(self, ttl: int = 60):\n self.ttl = ttl\n self.store = {}\n\n def get(self, key: str, fetch_fn):\n now = time.time()\n if key in self.store:\n value, expiry = self.store[key]\n if now < expiry:\n return value\n value = fetch_fn()\n self.store[key] = (value, now + self.ttl)\n return value\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0148", "domain": "issue_automation", "prompt": "Author a defensive Python routine that Write a Python function that removes a milestone from a Gitea issue. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef remove_milestone(repo: str, issue_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{issue_number}\"\n data = {\"milestone\": 0}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0089", "domain": "pr_workflow", "prompt": "Draft a minimal but complete solution that Write a Python function that approves a Gitea pull request via API. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef approve_pr(repo: str, pr_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/reviews\"\n data = {\"body\": \"LGTM\", \"event\": \"APPROVE\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0072", "domain": "repo_management", "prompt": "Using only the Python standard library, Write a Python function that sets a repo topic (tag) via the Gitea API. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef set_repo_topic(repo: str, topic: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/topics\"\n data = {\"topics\": [topic]}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PUT\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0217", "domain": "pr_workflow", "prompt": "Build a reusable module function that Write a Python function that triggers a CI pipeline by pushing an empty commit on a PR branch. Add timeout and connection cleanup.", "response": "import subprocess\n\ndef trigger_ci(repo_url: str, branch: str):\n subprocess.run(\n [\"git\", \"commit\", \"--allow-empty\", \"-m\", \"ci: trigger pipeline\"],\n check=True, capture_output=True,\n )\n subprocess.run([\"git\", \"push\", repo_url, branch], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0232", "domain": "issue_automation", "prompt": "Using only the Python standard library, Write a Python function that labels a batch of Gitea issues with the same label. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef batch_label_issues(repo: str, numbers: list[int], label_id: int, token: str):\n owner, name = repo.split(\"/\")\n for num in numbers:\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{num}/labels\"\n data = {\"labels\": [label_id]}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30):\n pass\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0198", "domain": "gitea_api", "prompt": "Author a defensive Python routine that Write a Python function that builds a Gitea API search query for issues across all repos in an organization. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport urllib.parse\n\ndef search_issues_url(org: str, query: str, state: str = \"open\") -> str:\n \"\"\"Build cross-repo issue search URL.\"\"\"\n params = urllib.parse.urlencode({\n \"q\": query,\n \"state\": state,\n \"type\": \"issues\",\n })\n return f\"/repos/search?{params}\"\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0198", "domain": "issue_automation", "prompt": "Author a defensive Python routine that Write a Python function that removes a milestone from a Gitea issue. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef remove_milestone(repo: str, issue_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{issue_number}\"\n data = {\"milestone\": 0}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0042", "domain": "issue_automation", "prompt": "Using only the Python standard library, Write a Python function that generates a markdown summary report of open issues for a repo. Add retry logic with exponential backoff.", "response": "def generate_issue_report(repo: str, issues: list[dict]) -> str:\n lines = [f\"# Issue Report for {repo}\", \"\"]\n for i in issues:\n lines.append(f\"- #{i['number']} [{i['state']}] {i['title']}\")\n return \"\n\".join(lines)\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0176", "domain": "gitea_api", "prompt": "Design a concise Python snippet that Write a Python function that pings a Gitea instance to check if it is alive. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport urllib.error\nimport json\n\ndef ping_gitea(base_url: str) -> bool:\n \"\"\"Check if Gitea is responding.\"\"\"\n try:\n req = urllib.request.Request(f\"{base_url}/api/v1/version\")\n with urllib.request.urlopen(req, timeout=5) as resp:\n return resp.status == 200\n except Exception:\n return False\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0156", "domain": "pr_workflow", "prompt": "Design a concise Python snippet that Write a Python function that requests a specific user to review a Gitea pull request. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef request_review(repo: str, pr_number: int, reviewers: list[str], token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/requested_reviewers\"\n data = {\"reviewers\": reviewers}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0075", "domain": "pr_workflow", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that cherry-picks a commit from one branch to another via Gitea API. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef cherry_pick_commit(repo: str, commit_sha: str, target_branch: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/git/commits\"\n data = {\"message\": f\"cherry-pick {commit_sha}\", \"parents\": [target_branch], \"tree\": commit_sha}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0057", "domain": "pr_workflow", "prompt": "Build a reusable module function that Write a Python function that checks whether a Gitea pull request is mergeable. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef is_mergeable(repo: str, pr_number: int, token: str) -> bool:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n data = json.loads(resp.read().decode())\n return data.get(\"mergeable\", False)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0222", "domain": "repo_management", "prompt": "Using only the Python standard library, Write a Python function that sets a repo topic (tag) via the Gitea API. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef set_repo_topic(repo: str, topic: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/topics\"\n data = {\"topics\": [topic]}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PUT\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0012", "domain": "pr_workflow", "prompt": "Using only the Python standard library, Write a Python function that detects destructive deletions in a PR (any file losing >50% of lines). Include error handling.", "response": "def detect_destructive(files: list[dict], threshold: float = 0.5) -> list[str]:\n flagged = []\n for f in files:\n if f.get(\"status\") == \"modified\" and f.get(\"deletions\", 0) > 0:\n total = f.get(\"additions\", 0) + f.get(\"deletions\", 0)\n if total > 0 and f[\"deletions\"] / total > threshold:\n flagged.append(f[\"filename\"])\n return flagged\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0247", "domain": "issue_automation", "prompt": "Build a reusable module function that Write a Python function that sets a milestone on a Gitea issue. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef set_milestone(repo: str, issue_number: int, milestone_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{issue_number}\"\n data = {\"milestone\": milestone_id}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0192", "domain": "issue_automation", "prompt": "Using only the Python standard library, Write a Python function that generates a markdown summary report of open issues for a repo. Optimize for minimal external dependencies.", "response": "def generate_issue_report(repo: str, issues: list[dict]) -> str:\n lines = [f\"# Issue Report for {repo}\", \"\"]\n for i in issues:\n lines.append(f\"- #{i['number']} [{i['state']}] {i['title']}\")\n return \"\n\".join(lines)\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0137", "domain": "repo_management", "prompt": "Build a reusable module function that Write a Python function that deletes a webhook from a Gitea repo by its ID. Handle empty responses gracefully.", "response": "import urllib.request\n\ndef delete_webhook(repo: str, hook_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/hooks/{hook_id}\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0156", "domain": "issue_automation", "prompt": "Design a concise Python snippet that Write a Python function that checks whether a Gitea issue already has a bot comment to avoid duplicate comments. Include docstrings and type hints.", "response": "def has_bot_comment(comments: list[dict], bot_marker: str = \"🤖\") -> bool:\n return any(bot_marker in c.get(\"body\", \"\") for c in comments)\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0212", "domain": "repo_management", "prompt": "Using only the Python standard library, Write a Python function that deletes a webhook from a Gitea repo by its ID. Add timeout and connection cleanup.", "response": "import urllib.request\n\ndef delete_webhook(repo: str, hook_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/hooks/{hook_id}\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0180", "domain": "gitea_api", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that handles HTTP 401, 403, 404, and 500 errors from the Gitea API gracefully. Optimize for minimal external dependencies.", "response": "import urllib.error\n\nclass GiteaError(Exception):\n def __init__(self, status: int, message: str):\n self.status = status\n super().__init__(f\"Gitea {status}: {message}\")\n\ndef handle_gitea_error(e: urllib.error.HTTPError) -> None:\n \"\"\"Map HTTP errors to typed exceptions.\"\"\"\n body = e.read().decode(errors=\"replace\") if e.fp else \"\"\n if e.code == 401:\n raise GiteaError(401, f\"Unauthorized. Check your token. {body}\")\n if e.code == 403:\n raise GiteaError(403, f\"Forbidden. {body}\")\n if e.code == 404:\n raise GiteaError(404, f\"Not found. {body}\")\n if e.code >= 500:\n raise GiteaError(e.code, f\"Server error. {body}\")\n raise GiteaError(e.code, body)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0028", "domain": "issue_automation", "prompt": "Author a defensive Python routine that Write a Python function that posts a comment on a Gitea issue via API. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef comment_on_issue(repo: str, number: int, body: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/comments\"\n data = {\"body\": body}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0228", "domain": "issue_automation", "prompt": "Author a defensive Python routine that Write a Python function that posts a comment on a Gitea issue via API. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef comment_on_issue(repo: str, number: int, body: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/comments\"\n data = {\"body\": body}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0088", "domain": "gitea_api", "prompt": "Author a defensive Python routine that Write a Python function that converts a repo string 'owner/name' into a Gitea API path '/repos/owner/name'. Log all failures for observability.", "response": "def repo_path(repo: str) -> str:\n \"\"\"Convert 'owner/name' to '/repos/owner/name'.\"\"\"\n if \"/\" not in repo:\n raise ValueError(\"Repo must be 'owner/name'\")\n return f\"/repos/{repo}\"\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0020", "domain": "pr_workflow", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that generates a release notes draft from merged PRs since the last tag. Include error handling.", "response": "def generate_release_notes(merged_prs: list[dict], tag: str) -> str:\n lines = [f\"## Release {tag}\", \"\"]\n for pr in merged_prs:\n lines.append(f\"- #{pr['number']} {pr['title']}\")\n return \"\n\".join(lines)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0162", "domain": "pr_workflow", "prompt": "Using only the Python standard library, Write a Python function that detects destructive deletions in a PR (any file losing >50% of lines). Include docstrings and type hints.", "response": "def detect_destructive(files: list[dict], threshold: float = 0.5) -> list[str]:\n flagged = []\n for f in files:\n if f.get(\"status\") == \"modified\" and f.get(\"deletions\", 0) > 0:\n total = f.get(\"additions\", 0) + f.get(\"deletions\", 0)\n if total > 0 and f[\"deletions\"] / total > threshold:\n flagged.append(f[\"filename\"])\n return flagged\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0104", "domain": "pr_workflow", "prompt": "Create a typed Python utility that Write a Python function that merges a Gitea pull request with retry logic for merge conflicts. Validate inputs before making API calls.", "response": "import urllib.request\nimport urllib.error\nimport json\nimport time\n\ndef merge_pr(repo: str, number: int, token: str, method: str = \"squash\", retries: int = 3):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{number}/merge\"\n data = {\"Do\": method}\n for attempt in range(retries):\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n try:\n with urllib.request.urlopen(req, timeout=30) as resp:\n return True\n except urllib.error.HTTPError as e:\n if e.code == 405 and attempt < retries - 1:\n time.sleep(5)\n continue\n raise\n return False\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0219", "domain": "issue_automation", "prompt": "Draft a minimal but complete solution that Write a Python function that unlocks a previously locked Gitea issue. Add timeout and connection cleanup.", "response": "import urllib.request\n\ndef unlock_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/lock\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0146", "domain": "repo_management", "prompt": "Design a concise Python snippet that Write a Python function that transfers a Gitea repo from one owner to another. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef transfer_repo(repo: str, new_owner: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/transfer\"\n data = {\"new_owner\": new_owner}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0203", "domain": "gitea_api", "prompt": "Write a robust, production-ready function that Write a Python function that builds a Gitea API URL with query parameters for pagination. Add timeout and connection cleanup.", "response": "import urllib.parse\n\ndef build_api_url(base_url: str, path: str, params: dict | None = None) -> str:\n \"\"\"Build a Gitea API URL with optional query params.\"\"\"\n url = f\"{base_url.rstrip('/')}/api/v1{path}\"\n if params:\n clean = {k: v for k, v in params.items() if v is not None}\n url += \"?\" + urllib.parse.urlencode(clean)\n return url\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0141", "domain": "issue_automation", "prompt": "Write a Python function that migrates issues from one Gitea repo to another by creating copies. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef migrate_issue(source_repo: str, target_repo: str, issue: dict, token: str):\n owner, name = target_repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues\"\n data = {\n \"title\": f\"[Migrated] {issue['title']}\",\n \"body\": issue.get(\"body\", \"\"),\n }\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0144", "domain": "gitea_api", "prompt": "Create a typed Python utility that Write a Python function that compares two Gitea API base URLs and normalizes them by stripping trailing slashes. Handle empty responses gracefully.", "response": "def normalize_base_url(url: str) -> str:\n \"\"\"Strip trailing slashes and ensure no duplicate slashes.\"\"\"\n return url.rstrip(\"/\")\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0126", "domain": "gitea_api", "prompt": "Design a concise Python snippet that Write a Python function that pings a Gitea instance to check if it is alive. Handle empty responses gracefully.", "response": "import urllib.request\nimport urllib.error\nimport json\n\ndef ping_gitea(base_url: str) -> bool:\n \"\"\"Check if Gitea is responding.\"\"\"\n try:\n req = urllib.request.Request(f\"{base_url}/api/v1/version\")\n with urllib.request.urlopen(req, timeout=5) as resp:\n return resp.status == 200\n except Exception:\n return False\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0067", "domain": "issue_automation", "prompt": "Build a reusable module function that Write a Python function that generates a markdown summary report of open issues for a repo. Return typed dataclasses where appropriate.", "response": "def generate_issue_report(repo: str, issues: list[dict]) -> str:\n lines = [f\"# Issue Report for {repo}\", \"\"]\n for i in issues:\n lines.append(f\"- #{i['number']} [{i['state']}] {i['title']}\")\n return \"\n\".join(lines)\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0085", "domain": "gitea_api", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that implements a circuit breaker for Gitea API requests after 3 consecutive failures. Log all failures for observability.", "response": "class CircuitBreaker:\n def __init__(self, threshold: int = 3):\n self.failures = 0\n self.threshold = threshold\n self.open = False\n\n def call(self, fn, *args, **kwargs):\n if self.open:\n raise RuntimeError(\"Circuit breaker is OPEN\")\n try:\n result = fn(*args, **kwargs)\n self.failures = 0\n return result\n except Exception:\n self.failures += 1\n if self.failures >= self.threshold:\n self.open = True\n raise\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0043", "domain": "issue_automation", "prompt": "Write a robust, production-ready function that Write a Python function that locks a Gitea issue to prevent further comments. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef lock_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/lock\"\n req = urllib.request.Request(url, data=json.dumps({}).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0197", "domain": "gitea_api", "prompt": "Build a reusable module function that Write a Python function that parses a Gitea API error response and extracts the human-readable message. Optimize for minimal external dependencies.", "response": "import json\nimport urllib.error\n\ndef parse_error_body(e: urllib.error.HTTPError) -> str:\n \"\"\"Extract human-readable message from Gitea error response.\"\"\"\n try:\n body = json.loads(e.read().decode())\n return body.get(\"message\", str(e))\n except Exception:\n return str(e)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0224", "domain": "gitea_api", "prompt": "Create a typed Python utility that Write a Python function that attaches a custom User-Agent header to all Gitea API requests. Add timeout and connection cleanup.", "response": "import urllib.request\n\ndef request_with_user_agent(url: str, token: str, agent: str = \"timmy-bot/1.0\"):\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"User-Agent\", agent)\n return req\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0237", "domain": "repo_management", "prompt": "Build a reusable module function that Write a Python function that deletes a webhook from a Gitea repo by its ID. Surface clear exception messages on failure.", "response": "import urllib.request\n\ndef delete_webhook(repo: str, hook_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/hooks/{hook_id}\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0227", "domain": "issue_automation", "prompt": "Build a reusable module function that Write a Python function that filters Gitea issues by label name. Surface clear exception messages on failure.", "response": "def filter_by_label(issues: list[dict], label: str) -> list[dict]:\n return [i for i in issues if any(l.get(\"name\") == label for l in i.get(\"labels\", []))]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0038", "domain": "issue_automation", "prompt": "Author a defensive Python routine that Write a Python function that fetches the full timeline (comments) of a Gitea issue. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef get_issue_timeline(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/comments\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0133", "domain": "issue_automation", "prompt": "Write a robust, production-ready function that Write a Python function that searches Gitea issues across an organization by keyword. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef search_issues(org: str, keyword: str, token: str):\n url = f\"https://forge.example.com/api/v1/repos/search?q={keyword}&uid=0&limit=50\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0112", "domain": "gitea_api", "prompt": "Using only the Python standard library, Write a Python function that validates a Gitea API token by calling the /user endpoint. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef validate_token(base_url: str, token: str) -> bool:\n \"\"\"Verify a token by calling the /user endpoint.\"\"\"\n req = urllib.request.Request(f\"{base_url}/api/v1/user\")\n req.add_header(\"Authorization\", f\"token {token}\")\n try:\n with urllib.request.urlopen(req, timeout=10) as resp:\n data = json.loads(resp.read().decode())\n return \"login\" in data\n except urllib.error.HTTPError as e:\n if e.code == 401:\n return False\n raise\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0085", "domain": "repo_management", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that performs a sparse checkout of a single directory from a Gitea repo. Log all failures for observability.", "response": "import subprocess\nfrom pathlib import Path\n\ndef sparse_checkout(repo_url: str, dest: str, directory: str):\n \"\"\"Sparse checkout a single directory.\"\"\"\n Path(dest).mkdir(parents=True, exist_ok=True)\n subprocess.run([\"git\", \"init\", dest], check=True, capture_output=True)\n subprocess.run([\"git\", \"-C\", dest, \"remote\", \"add\", \"origin\", repo_url], check=True, capture_output=True)\n subprocess.run([\"git\", \"-C\", dest, \"config\", \"core.sparseCheckout\", \"true\"], check=True, capture_output=True)\n sparse_file = Path(dest) / \".git\" / \"info\" / \"sparse-checkout\"\n sparse_file.write_text(directory + \"\\n\")\n subprocess.run([\"git\", \"-C\", dest, \"pull\", \"origin\", \"main\"], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0138", "domain": "gitea_api", "prompt": "Author a defensive Python routine that Write a Python function that converts a repo string 'owner/name' into a Gitea API path '/repos/owner/name'. Handle empty responses gracefully.", "response": "def repo_path(repo: str) -> str:\n \"\"\"Convert 'owner/name' to '/repos/owner/name'.\"\"\"\n if \"/\" not in repo:\n raise ValueError(\"Repo must be 'owner/name'\")\n return f\"/repos/{repo}\"\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0128", "domain": "issue_automation", "prompt": "Author a defensive Python routine that Write a Python function that posts a comment on a Gitea issue via API. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef comment_on_issue(repo: str, number: int, body: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/comments\"\n data = {\"body\": body}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0191", "domain": "pr_workflow", "prompt": "Write a Python function that gets the diff of a Gitea pull request as raw text. Optimize for minimal external dependencies.", "response": "import urllib.request\n\ndef get_pr_diff(repo: str, pr_number: int, token: str) -> str:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}.diff\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.read().decode()\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0163", "domain": "repo_management", "prompt": "Write a robust, production-ready function that Write a Python function that checks whether a branch exists in a remote Gitea repo without cloning. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef branch_exists(repo: str, branch: str, token: str) -> bool:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branches/{branch}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n try:\n with urllib.request.urlopen(req, timeout=10) as resp:\n return resp.status == 200\n except urllib.error.HTTPError as e:\n if e.code == 404:\n return False\n raise\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0116", "domain": "gitea_api", "prompt": "Design a concise Python snippet that Write a Python function that implements rate-limit awareness by reading the X-RateLimit-Remaining header. Validate inputs before making API calls.", "response": "import urllib.request\n\ndef check_rate_limit(resp: urllib.request.addinfourl) -> int:\n \"\"\"Read X-RateLimit-Remaining from response headers.\"\"\"\n remaining = resp.headers.get(\"X-RateLimit-Remaining\")\n return int(remaining) if remaining else -1\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0204", "domain": "pr_workflow", "prompt": "Create a typed Python utility that Write a Python function that merges a Gitea pull request with retry logic for merge conflicts. Add timeout and connection cleanup.", "response": "import urllib.request\nimport urllib.error\nimport json\nimport time\n\ndef merge_pr(repo: str, number: int, token: str, method: str = \"squash\", retries: int = 3):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{number}/merge\"\n data = {\"Do\": method}\n for attempt in range(retries):\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n try:\n with urllib.request.urlopen(req, timeout=30) as resp:\n return True\n except urllib.error.HTTPError as e:\n if e.code == 405 and attempt < retries - 1:\n time.sleep(5)\n continue\n raise\n return False\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0170", "domain": "issue_automation", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that subscribes a user to notifications on a Gitea issue. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef subscribe_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/subscriptions\"\n req = urllib.request.Request(url, data=json.dumps({}).encode(), method=\"PUT\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0225", "domain": "repo_management", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that syncs a fork with its upstream parent repo via Gitea API. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef sync_fork(repo: str, token: str, branch: str = \"main\"):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls\"\n data = {\"title\": \"Sync upstream\", \"head\": f\"upstream:{branch}\", \"base\": branch, \"body\": \"Automated sync\"}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0219", "domain": "repo_management", "prompt": "Draft a minimal but complete solution that Write a Python function that archives a Gitea repo (read-only) via API. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef archive_repo(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"archived\": True}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0025", "domain": "gitea_api", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that closes idle Gitea API connections after 30 seconds to prevent socket exhaustion. Include error handling.", "response": "import urllib.request\nimport socket\n\nclass TimeoutHTTPHandler(urllib.request.HTTPHandler):\n def __init__(self, timeout: int = 30):\n self.timeout = timeout\n super().__init__()\n\n def http_open(self, req):\n return self.do_open(lambda host, port: http.client.HTTPConnection(host, port, timeout=self.timeout), req)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0206", "domain": "gitea_api", "prompt": "Design a concise Python snippet that Write a Python function that iterates through all pages of a paginated Gitea API endpoint. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef paginate_all(url_template: str, token: str, params: dict, limit: int = 50):\n \"\"\"Iterate all pages of a paginated Gitea endpoint.\"\"\"\n page = 1\n while True:\n params[\"page\"] = page\n params[\"limit\"] = limit\n req = urllib.request.Request(url_template + \"?\" + urllib.parse.urlencode(params))\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n batch = json.loads(resp.read().decode())\n if not batch:\n break\n yield from batch\n if len(batch) < limit:\n break\n page += 1\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0157", "domain": "gitea_api", "prompt": "Build a reusable module function that Write a Python function that uses urllib (no external deps) to POST JSON data to the Gitea API. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef gitea_post_json(base_url: str, path: str, token: str, data: dict):\n \"\"\"POST JSON to Gitea API using only stdlib.\"\"\"\n url = f\"{base_url.rstrip('/')}/api/v1{path}\"\n body = json.dumps(data).encode(\"utf-8\")\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n req.add_header(\"Accept\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n raw = resp.read().decode()\n return json.loads(raw) if raw.strip() else {}\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0123", "domain": "issue_automation", "prompt": "Write a robust, production-ready function that Write a Python function that removes a milestone from a Gitea issue. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef remove_milestone(repo: str, issue_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{issue_number}\"\n data = {\"milestone\": 0}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0235", "domain": "gitea_api", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that implements a circuit breaker for Gitea API requests after 3 consecutive failures. Surface clear exception messages on failure.", "response": "class CircuitBreaker:\n def __init__(self, threshold: int = 3):\n self.failures = 0\n self.threshold = threshold\n self.open = False\n\n def call(self, fn, *args, **kwargs):\n if self.open:\n raise RuntimeError(\"Circuit breaker is OPEN\")\n try:\n result = fn(*args, **kwargs)\n self.failures = 0\n return result\n except Exception:\n self.failures += 1\n if self.failures >= self.threshold:\n self.open = True\n raise\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0161", "domain": "repo_management", "prompt": "Write a Python function that updates a repo's description and website via the Gitea API. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef update_repo_description(repo: str, description: str, website: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"description\": description, \"website\": website}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0169", "domain": "gitea_api", "prompt": "Draft a minimal but complete solution that Write a Python function that compares two Gitea API base URLs and normalizes them by stripping trailing slashes. Include docstrings and type hints.", "response": "def normalize_base_url(url: str) -> str:\n \"\"\"Strip trailing slashes and ensure no duplicate slashes.\"\"\"\n return url.rstrip(\"/\")\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0231", "domain": "pr_workflow", "prompt": "Write a Python function that requests a specific user to review a Gitea pull request. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef request_review(repo: str, pr_number: int, reviewers: list[str], token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/requested_reviewers\"\n data = {\"reviewers\": reviewers}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0063", "domain": "repo_management", "prompt": "Write a robust, production-ready function that Write a Python function that checks whether a branch exists in a remote Gitea repo without cloning. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef branch_exists(repo: str, branch: str, token: str) -> bool:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branches/{branch}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n try:\n with urllib.request.urlopen(req, timeout=10) as resp:\n return resp.status == 200\n except urllib.error.HTTPError as e:\n if e.code == 404:\n return False\n raise\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0092", "domain": "repo_management", "prompt": "Using only the Python standard library, Write a Python function that adds a deploy key to a Gitea repo for CI access. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef add_deploy_key(repo: str, title: str, key: str, token: str, read_only: bool = True):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/keys\"\n data = {\"title\": title, \"key\": key, \"read_only\": read_only}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0010", "domain": "pr_workflow", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that lists the files changed in a Gitea pull request. Include error handling.", "response": "import urllib.request\nimport json\n\ndef list_pr_files(repo: str, pr_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/files\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0170", "domain": "pr_workflow", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that generates a release notes draft from merged PRs since the last tag. Include docstrings and type hints.", "response": "def generate_release_notes(merged_prs: list[dict], tag: str) -> str:\n lines = [f\"## Release {tag}\", \"\"]\n for pr in merged_prs:\n lines.append(f\"- #{pr['number']} {pr['title']}\")\n return \"\n\".join(lines)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0071", "domain": "pr_workflow", "prompt": "Write a Python function that adds a label to a Gitea pull request. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef add_pr_label(repo: str, pr_number: int, label_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/labels\"\n data = {\"labels\": [label_id]}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0194", "domain": "gitea_api", "prompt": "Create a typed Python utility that Write a Python function that compares two Gitea API base URLs and normalizes them by stripping trailing slashes. Optimize for minimal external dependencies.", "response": "def normalize_base_url(url: str) -> str:\n \"\"\"Strip trailing slashes and ensure no duplicate slashes.\"\"\"\n return url.rstrip(\"/\")\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0064", "domain": "gitea_api", "prompt": "Create a typed Python utility that Write a Python function that measures the latency of a Gitea API call and raises a warning if it exceeds 2 seconds. Return typed dataclasses where appropriate.", "response": "import time\nimport urllib.request\n\ndef timed_request(req: urllib.request.Request, threshold: float = 2.0):\n \"\"\"Execute request and warn if latency exceeds threshold.\"\"\"\n start = time.time()\n with urllib.request.urlopen(req, timeout=30) as resp:\n body = resp.read().decode()\n elapsed = time.time() - start\n if elapsed > threshold:\n print(f\"WARNING: Request took {elapsed:.2f}s\")\n return body\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0037", "domain": "gitea_api", "prompt": "Build a reusable module function that Write a Python function that validates a Gitea API token by calling the /user endpoint. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef validate_token(base_url: str, token: str) -> bool:\n \"\"\"Verify a token by calling the /user endpoint.\"\"\"\n req = urllib.request.Request(f\"{base_url}/api/v1/user\")\n req.add_header(\"Authorization\", f\"token {token}\")\n try:\n with urllib.request.urlopen(req, timeout=10) as resp:\n data = json.loads(resp.read().decode())\n return \"login\" in data\n except urllib.error.HTTPError as e:\n if e.code == 401:\n return False\n raise\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0003", "domain": "gitea_api", "prompt": "Write a robust, production-ready function that Write a Python function that builds a Gitea API URL with query parameters for pagination. Include error handling.", "response": "import urllib.parse\n\ndef build_api_url(base_url: str, path: str, params: dict | None = None) -> str:\n \"\"\"Build a Gitea API URL with optional query params.\"\"\"\n url = f\"{base_url.rstrip('/')}/api/v1{path}\"\n if params:\n clean = {k: v for k, v in params.items() if v is not None}\n url += \"?\" + urllib.parse.urlencode(clean)\n return url\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0127", "domain": "issue_automation", "prompt": "Build a reusable module function that Write a Python function that filters Gitea issues by label name. Handle empty responses gracefully.", "response": "def filter_by_label(issues: list[dict], label: str) -> list[dict]:\n return [i for i in issues if any(l.get(\"name\") == label for l in i.get(\"labels\", []))]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0178", "domain": "issue_automation", "prompt": "Author a defensive Python routine that Write a Python function that posts a comment on a Gitea issue via API. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef comment_on_issue(repo: str, number: int, body: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/comments\"\n data = {\"body\": body}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0119", "domain": "pr_workflow", "prompt": "Draft a minimal but complete solution that Write a Python function that auto-squashes all commits on a PR branch before merging. Validate inputs before making API calls.", "response": "import subprocess\n\ndef autosquash_branch(branch: str, base: str = \"main\"):\n subprocess.run([\"git\", \"checkout\", branch], check=True, capture_output=True)\n subprocess.run([\"git\", \"reset\", f\"origin/{base}\"], check=True, capture_output=True)\n subprocess.run([\"git\", \"add\", \"-A\"], check=True, capture_output=True)\n subprocess.run([\"git\", \"commit\", \"-m\", f\"feat: squash {branch}\"], check=True, capture_output=True)\n subprocess.run([\"git\", \"push\", \"--force-with-lease\", \"origin\", branch], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0002", "domain": "pr_workflow", "prompt": "Using only the Python standard library, Write a Python function that checks if an open pull request already exists for a given issue (by scanning title/body/branch). Include error handling.", "response": "def issue_has_open_pr(prs: list[dict], issue_number: int) -> bool:\n num_str = str(issue_number)\n for pr in prs:\n combined = f\"{pr.get('title','')} {pr.get('body','')} {pr.get('head',{}).get('ref','')}\"\n if num_str in combined:\n return True\n return False\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0249", "domain": "gitea_api", "prompt": "Draft a minimal but complete solution that Write a Python function that attaches a custom User-Agent header to all Gitea API requests. Surface clear exception messages on failure.", "response": "import urllib.request\n\ndef request_with_user_agent(url: str, token: str, agent: str = \"timmy-bot/1.0\"):\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"User-Agent\", agent)\n return req\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0132", "domain": "issue_automation", "prompt": "Using only the Python standard library, Write a Python function that labels a batch of Gitea issues with the same label. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef batch_label_issues(repo: str, numbers: list[int], label_id: int, token: str):\n owner, name = repo.split(\"/\")\n for num in numbers:\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{num}/labels\"\n data = {\"labels\": [label_id]}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30):\n pass\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0015", "domain": "issue_automation", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that auto-triangles Gitea issues by running a classifier on the title and body. Include error handling.", "response": "import random\n\ndef triage_issue(title: str, body: str) -> str:\n \"\"\"Simple rule-based triage classifier.\"\"\"\n text = (title + \" \" + body).lower()\n if any(w in text for w in [\"bug\", \"crash\", \"error\", \"fix\"]):\n return \"bug\"\n if any(w in text for w in [\"feature\", \"add\", \"implement\", \"support\"]):\n return \"feature\"\n if any(w in text for w in [\"docs\", \"documentation\", \"readme\"]):\n return \"documentation\"\n return \"ops\"\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0126", "domain": "repo_management", "prompt": "Design a concise Python snippet that Write a Python function that creates a new Gitea repo under an organization via API. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef create_repo(org: str, name: str, token: str, description: str = \"\", private: bool = False):\n url = f\"https://forge.example.com/api/v1/orgs/{org}/repos\"\n data = {\"name\": name, \"description\": description, \"private\": private}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0011", "domain": "pr_workflow", "prompt": "Write a Python function that calculates the net line change (additions - deletions) across all files in a PR. Include error handling.", "response": "def net_line_change(files: list[dict]) -> int:\n return sum(f.get(\"additions\", 0) - f.get(\"deletions\", 0) for f in files)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0227", "domain": "repo_management", "prompt": "Build a reusable module function that Write a Python function that lists all repos in a Gitea organization with pagination. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef list_org_repos(org: str, token: str, limit: int = 50, page: int = 1):\n url = f\"https://forge.example.com/api/v1/orgs/{org}/repos?limit={limit}&page={page}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0143", "domain": "repo_management", "prompt": "Write a robust, production-ready function that Write a Python function that enables issue tracking on a Gitea repo via API. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef enable_issues(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"has_issues\": True}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0205", "domain": "pr_workflow", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that posts a review comment on a Gitea pull request. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef review_comment(repo: str, pr_number: int, body: str, token: str, path: str = \"\", position: int = 0):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/reviews\"\n data = {\"body\": body, \"event\": \"COMMENT\"}\n if path:\n data[\"comments\"] = [{\"path\": path, \"position\": position, \"body\": body}]\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0177", "domain": "issue_automation", "prompt": "Build a reusable module function that Write a Python function that filters Gitea issues by label name. Optimize for minimal external dependencies.", "response": "def filter_by_label(issues: list[dict], label: str) -> list[dict]:\n return [i for i in issues if any(l.get(\"name\") == label for l in i.get(\"labels\", []))]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0104", "domain": "issue_automation", "prompt": "Create a typed Python utility that Write a Python function that closes a Gitea issue via API. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef close_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"state\": \"closed\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0045", "domain": "pr_workflow", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that generates a release notes draft from merged PRs since the last tag. Add retry logic with exponential backoff.", "response": "def generate_release_notes(merged_prs: list[dict], tag: str) -> str:\n lines = [f\"## Release {tag}\", \"\"]\n for pr in merged_prs:\n lines.append(f\"- #{pr['number']} {pr['title']}\")\n return \"\n\".join(lines)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0097", "domain": "pr_workflow", "prompt": "Build a reusable module function that Write a Python function that removes a label from a Gitea pull request. Log all failures for observability.", "response": "import urllib.request\n\ndef remove_pr_label(repo: str, pr_number: int, label_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/labels/{label_id}\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0180", "domain": "repo_management", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that protects a branch in Gitea by requiring PR reviews before merge. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef protect_branch(repo: str, branch: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branch_protections\"\n data = {\"branch_name\": branch, \"enable_push\": False, \"enable_push_whitelist\": False}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0235", "domain": "issue_automation", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that finds all unassigned open issues in a Gitea repo. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef find_unassigned_issues(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues?state=open&type=issues&limit=100\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n issues = json.loads(resp.read().decode())\n return [i for i in issues if not i.get(\"assignee\") and not i.get(\"pull_request\")]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0229", "domain": "pr_workflow", "prompt": "Draft a minimal but complete solution that Write a Python function that merges a Gitea pull request with retry logic for merge conflicts. Surface clear exception messages on failure.", "response": "import urllib.request\nimport urllib.error\nimport json\nimport time\n\ndef merge_pr(repo: str, number: int, token: str, method: str = \"squash\", retries: int = 3):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{number}/merge\"\n data = {\"Do\": method}\n for attempt in range(retries):\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n try:\n with urllib.request.urlopen(req, timeout=30) as resp:\n return True\n except urllib.error.HTTPError as e:\n if e.code == 405 and attempt < retries - 1:\n time.sleep(5)\n continue\n raise\n return False\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0046", "domain": "repo_management", "prompt": "Design a concise Python snippet that Write a Python function that transfers a Gitea repo from one owner to another. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef transfer_repo(repo: str, new_owner: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/transfer\"\n data = {\"new_owner\": new_owner}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0197", "domain": "pr_workflow", "prompt": "Build a reusable module function that Write a Python function that removes a label from a Gitea pull request. Optimize for minimal external dependencies.", "response": "import urllib.request\n\ndef remove_pr_label(repo: str, pr_number: int, label_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/labels/{label_id}\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0190", "domain": "gitea_api", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that caches Gitea API responses for 60 seconds to avoid redundant requests. Optimize for minimal external dependencies.", "response": "import time\nimport json\n\nclass TimedCache:\n def __init__(self, ttl: int = 60):\n self.ttl = ttl\n self.store = {}\n\n def get(self, key: str, fetch_fn):\n now = time.time()\n if key in self.store:\n value, expiry = self.store[key]\n if now < expiry:\n return value\n value = fetch_fn()\n self.store[key] = (value, now + self.ttl)\n return value\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0029", "domain": "issue_automation", "prompt": "Draft a minimal but complete solution that Write a Python function that closes a Gitea issue via API. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef close_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"state\": \"closed\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0040", "domain": "repo_management", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that sets branch protection rules: no force-push, require status checks. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef set_strict_protection(repo: str, branch: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branch_protections\"\n data = {\n \"branch_name\": branch,\n \"enable_push\": False,\n \"enable_status_check\": True,\n \"status_check_contexts\": [\"ci/tests\"],\n }\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0060", "domain": "repo_management", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that performs a sparse checkout of a single directory from a Gitea repo. Return typed dataclasses where appropriate.", "response": "import subprocess\nfrom pathlib import Path\n\ndef sparse_checkout(repo_url: str, dest: str, directory: str):\n \"\"\"Sparse checkout a single directory.\"\"\"\n Path(dest).mkdir(parents=True, exist_ok=True)\n subprocess.run([\"git\", \"init\", dest], check=True, capture_output=True)\n subprocess.run([\"git\", \"-C\", dest, \"remote\", \"add\", \"origin\", repo_url], check=True, capture_output=True)\n subprocess.run([\"git\", \"-C\", dest, \"config\", \"core.sparseCheckout\", \"true\"], check=True, capture_output=True)\n sparse_file = Path(dest) / \".git\" / \"info\" / \"sparse-checkout\"\n sparse_file.write_text(directory + \"\\n\")\n subprocess.run([\"git\", \"-C\", dest, \"pull\", \"origin\", \"main\"], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0029", "domain": "repo_management", "prompt": "Draft a minimal but complete solution that Write a Python function that lists all branches in a Gitea repo. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef list_branches(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branches\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0086", "domain": "gitea_api", "prompt": "Design a concise Python snippet that Write a Python function that logs Gitea API requests and responses for debugging. Log all failures for observability.", "response": "import logging\nimport urllib.request\n\nlogger = logging.getLogger(\"gitea\")\n\ndef logged_request(req: urllib.request.Request):\n \"\"\"Execute a request and log the exchange.\"\"\"\n logger.debug(\"%s %s\", req.get_method(), req.full_url)\n with urllib.request.urlopen(req, timeout=30) as resp:\n body = resp.read().decode()\n logger.debug(\"Response %d: %s\", resp.status, body[:500])\n return body\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0071", "domain": "repo_management", "prompt": "Write a Python function that transfers a Gitea repo from one owner to another. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef transfer_repo(repo: str, new_owner: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/transfer\"\n data = {\"new_owner\": new_owner}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0012", "domain": "repo_management", "prompt": "Using only the Python standard library, Write a Python function that deletes a webhook from a Gitea repo by its ID. Include error handling.", "response": "import urllib.request\n\ndef delete_webhook(repo: str, hook_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/hooks/{hook_id}\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0144", "domain": "issue_automation", "prompt": "Create a typed Python utility that Write a Python function that unlocks a previously locked Gitea issue. Handle empty responses gracefully.", "response": "import urllib.request\n\ndef unlock_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/lock\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0168", "domain": "issue_automation", "prompt": "Author a defensive Python routine that Write a Python function that locks a Gitea issue to prevent further comments. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef lock_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/lock\"\n req = urllib.request.Request(url, data=json.dumps({}).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0090", "domain": "gitea_api", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that caches Gitea API responses for 60 seconds to avoid redundant requests. Log all failures for observability.", "response": "import time\nimport json\n\nclass TimedCache:\n def __init__(self, ttl: int = 60):\n self.ttl = ttl\n self.store = {}\n\n def get(self, key: str, fetch_fn):\n now = time.time()\n if key in self.store:\n value, expiry = self.store[key]\n if now < expiry:\n return value\n value = fetch_fn()\n self.store[key] = (value, now + self.ttl)\n return value\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0177", "domain": "gitea_api", "prompt": "Build a reusable module function that Write a Python function that reads a Gitea API token from standard local paths and returns it. Optimize for minimal external dependencies.", "response": "from pathlib import Path\n\ndef read_gitea_token() -> str:\n \"\"\"Read token from standard locations.\"\"\"\n for path in [\n Path.home() / \".hermes\" / \"gitea_token\",\n Path.home() / \".config\" / \"gitea\" / \"token\",\n ]:\n if path.exists():\n return path.read_text().strip()\n raise FileNotFoundError(\"No Gitea token found\")\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0091", "domain": "pr_workflow", "prompt": "Write a Python function that gets the diff of a Gitea pull request as raw text. Log all failures for observability.", "response": "import urllib.request\n\ndef get_pr_diff(repo: str, pr_number: int, token: str) -> str:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}.diff\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.read().decode()\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0115", "domain": "repo_management", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that sets branch protection rules: no force-push, require status checks. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef set_strict_protection(repo: str, branch: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branch_protections\"\n data = {\n \"branch_name\": branch,\n \"enable_push\": False,\n \"enable_status_check\": True,\n \"status_check_contexts\": [\"ci/tests\"],\n }\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0087", "domain": "issue_automation", "prompt": "Build a reusable module function that Write a Python function that reopens a closed Gitea issue via API. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef reopen_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"state\": \"open\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0211", "domain": "pr_workflow", "prompt": "Write a Python function that calculates the net line change (additions - deletions) across all files in a PR. Add timeout and connection cleanup.", "response": "def net_line_change(files: list[dict]) -> int:\n return sum(f.get(\"additions\", 0) - f.get(\"deletions\", 0) for f in files)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0057", "domain": "gitea_api", "prompt": "Build a reusable module function that Write a Python function that uses urllib (no external deps) to POST JSON data to the Gitea API. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef gitea_post_json(base_url: str, path: str, token: str, data: dict):\n \"\"\"POST JSON to Gitea API using only stdlib.\"\"\"\n url = f\"{base_url.rstrip('/')}/api/v1{path}\"\n body = json.dumps(data).encode(\"utf-8\")\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n req.add_header(\"Accept\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n raw = resp.read().decode()\n return json.loads(raw) if raw.strip() else {}\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0107", "domain": "gitea_api", "prompt": "Build a reusable module function that Write a Python function that uses urllib (no external deps) to POST JSON data to the Gitea API. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef gitea_post_json(base_url: str, path: str, token: str, data: dict):\n \"\"\"POST JSON to Gitea API using only stdlib.\"\"\"\n url = f\"{base_url.rstrip('/')}/api/v1{path}\"\n body = json.dumps(data).encode(\"utf-8\")\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n req.add_header(\"Accept\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n raw = resp.read().decode()\n return json.loads(raw) if raw.strip() else {}\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0226", "domain": "gitea_api", "prompt": "Design a concise Python snippet that Write a Python function that pings a Gitea instance to check if it is alive. Surface clear exception messages on failure.", "response": "import urllib.request\nimport urllib.error\nimport json\n\ndef ping_gitea(base_url: str) -> bool:\n \"\"\"Check if Gitea is responding.\"\"\"\n try:\n req = urllib.request.Request(f\"{base_url}/api/v1/version\")\n with urllib.request.urlopen(req, timeout=5) as resp:\n return resp.status == 200\n except Exception:\n return False\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0075", "domain": "gitea_api", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that closes idle Gitea API connections after 30 seconds to prevent socket exhaustion. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport socket\n\nclass TimeoutHTTPHandler(urllib.request.HTTPHandler):\n def __init__(self, timeout: int = 30):\n self.timeout = timeout\n super().__init__()\n\n def http_open(self, req):\n return self.do_open(lambda host, port: http.client.HTTPConnection(host, port, timeout=self.timeout), req)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0092", "domain": "gitea_api", "prompt": "Using only the Python standard library, Write a Python function that serializes a Python dict into JSON and sends it as the body of a PATCH request to Gitea. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef gitea_patch(base_url: str, path: str, token: str, data: dict):\n \"\"\"Serialize dict to JSON and PATCH.\"\"\"\n url = f\"{base_url.rstrip('/')}/api/v1{path}\"\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0202", "domain": "repo_management", "prompt": "Using only the Python standard library, Write a Python function that lists all repos in a Gitea organization with pagination. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef list_org_repos(org: str, token: str, limit: int = 50, page: int = 1):\n url = f\"https://forge.example.com/api/v1/orgs/{org}/repos?limit={limit}&page={page}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0220", "domain": "gitea_api", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that creates a reusable urllib Request object with authentication for repeated Gitea API calls. Add timeout and connection cleanup.", "response": "import urllib.request\n\nclass AuthenticatedRequest:\n def __init__(self, base_url: str, token: str):\n self.base_url = base_url.rstrip(\"/\")\n self.token = token\n\n def build(self, path: str, method: str = \"GET\", data: bytes | None = None):\n url = f\"{self.base_url}/api/v1{path}\"\n req = urllib.request.Request(url, data=data, method=method)\n req.add_header(\"Authorization\", f\"token {self.token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n return req\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0248", "domain": "pr_workflow", "prompt": "Author a defensive Python routine that Write a Python function that blocks merging if a PR does not have at least one approved review. Surface clear exception messages on failure.", "response": "def require_approval(pr: dict, reviews: list[dict]) -> bool:\n if pr.get(\"state\") != \"open\":\n return False\n approvals = [r for r in reviews if r.get(\"state\") == \"APPROVED\"]\n return len(approvals) >= 1\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0055", "domain": "issue_automation", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that assigns a Gitea issue to a specific user. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef assign_issue(repo: str, number: int, assignees: list[str], token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"assignees\": assignees}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0022", "domain": "gitea_api", "prompt": "Using only the Python standard library, Write a Python function that parses a Gitea API error response and extracts the human-readable message. Include error handling.", "response": "import json\nimport urllib.error\n\ndef parse_error_body(e: urllib.error.HTTPError) -> str:\n \"\"\"Extract human-readable message from Gitea error response.\"\"\"\n try:\n body = json.loads(e.read().decode())\n return body.get(\"message\", str(e))\n except Exception:\n return str(e)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0082", "domain": "gitea_api", "prompt": "Using only the Python standard library, Write a Python function that uses urllib (no external deps) to POST JSON data to the Gitea API. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef gitea_post_json(base_url: str, path: str, token: str, data: dict):\n \"\"\"POST JSON to Gitea API using only stdlib.\"\"\"\n url = f\"{base_url.rstrip('/')}/api/v1{path}\"\n body = json.dumps(data).encode(\"utf-8\")\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n req.add_header(\"Accept\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n raw = resp.read().decode()\n return json.loads(raw) if raw.strip() else {}\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0240", "domain": "pr_workflow", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that dismisses a review on a Gitea pull request. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef dismiss_review(repo: str, pr_number: int, review_id: int, token: str, message: str = \"\"):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/reviews/{review_id}/dismissals\"\n data = {\"message\": message or \"Dismissed\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0153", "domain": "pr_workflow", "prompt": "Write a robust, production-ready function that Write a Python function that lists all open pull requests for a Gitea repo. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef list_open_prs(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls?state=open&limit=100\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0245", "domain": "pr_workflow", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that generates a release notes draft from merged PRs since the last tag. Surface clear exception messages on failure.", "response": "def generate_release_notes(merged_prs: list[dict], tag: str) -> str:\n lines = [f\"## Release {tag}\", \"\"]\n for pr in merged_prs:\n lines.append(f\"- #{pr['number']} {pr['title']}\")\n return \"\n\".join(lines)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0090", "domain": "repo_management", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that sets branch protection rules: no force-push, require status checks. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef set_strict_protection(repo: str, branch: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branch_protections\"\n data = {\n \"branch_name\": branch,\n \"enable_push\": False,\n \"enable_status_check\": True,\n \"status_check_contexts\": [\"ci/tests\"],\n }\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0182", "domain": "issue_automation", "prompt": "Using only the Python standard library, Write a Python function that labels a batch of Gitea issues with the same label. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef batch_label_issues(repo: str, numbers: list[int], label_id: int, token: str):\n owner, name = repo.split(\"/\")\n for num in numbers:\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{num}/labels\"\n data = {\"labels\": [label_id]}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30):\n pass\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0218", "domain": "repo_management", "prompt": "Author a defensive Python routine that Write a Python function that enables issue tracking on a Gitea repo via API. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef enable_issues(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"has_issues\": True}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0030", "domain": "repo_management", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that protects a branch in Gitea by requiring PR reviews before merge. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef protect_branch(repo: str, branch: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branch_protections\"\n data = {\"branch_name\": branch, \"enable_push\": False, \"enable_push_whitelist\": False}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0137", "domain": "issue_automation", "prompt": "Build a reusable module function that Write a Python function that reopens a closed Gitea issue via API. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef reopen_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"state\": \"open\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0048", "domain": "gitea_api", "prompt": "Author a defensive Python routine that Write a Python function that builds a Gitea API search query for issues across all repos in an organization. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport urllib.parse\n\ndef search_issues_url(org: str, query: str, state: str = \"open\") -> str:\n \"\"\"Build cross-repo issue search URL.\"\"\"\n params = urllib.parse.urlencode({\n \"q\": query,\n \"state\": state,\n \"type\": \"issues\",\n })\n return f\"/repos/search?{params}\"\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0040", "domain": "gitea_api", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that caches Gitea API responses for 60 seconds to avoid redundant requests. Add retry logic with exponential backoff.", "response": "import time\nimport json\n\nclass TimedCache:\n def __init__(self, ttl: int = 60):\n self.ttl = ttl\n self.store = {}\n\n def get(self, key: str, fetch_fn):\n now = time.time()\n if key in self.store:\n value, expiry = self.store[key]\n if now < expiry:\n return value\n value = fetch_fn()\n self.store[key] = (value, now + self.ttl)\n return value\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0106", "domain": "pr_workflow", "prompt": "Design a concise Python snippet that Write a Python function that requests a specific user to review a Gitea pull request. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef request_review(repo: str, pr_number: int, reviewers: list[str], token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/requested_reviewers\"\n data = {\"reviewers\": reviewers}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0230", "domain": "pr_workflow", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that posts a review comment on a Gitea pull request. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef review_comment(repo: str, pr_number: int, body: str, token: str, path: str = \"\", position: int = 0):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/reviews\"\n data = {\"body\": body, \"event\": \"COMMENT\"}\n if path:\n data[\"comments\"] = [{\"path\": path, \"position\": position, \"body\": body}]\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0022", "domain": "pr_workflow", "prompt": "Using only the Python standard library, Write a Python function that removes a label from a Gitea pull request. Include error handling.", "response": "import urllib.request\n\ndef remove_pr_label(repo: str, pr_number: int, label_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/labels/{label_id}\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0084", "domain": "gitea_api", "prompt": "Create a typed Python utility that Write a Python function that sets proper request headers (Authorization, Content-Type, Accept) for Gitea API calls. Log all failures for observability.", "response": "def build_gitea_request(url: str, token: str, method: str = \"GET\", data: bytes | None = None):\n \"\"\"Build a request with standard headers.\"\"\"\n req = urllib.request.Request(url, data=data, method=method)\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n req.add_header(\"Accept\", \"application/json\")\n return req\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0234", "domain": "pr_workflow", "prompt": "Create a typed Python utility that Write a Python function that updates the description of an existing Gitea pull request. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef update_pr_description(repo: str, pr_number: int, new_body: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}\"\n data = {\"body\": new_body}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0117", "domain": "pr_workflow", "prompt": "Build a reusable module function that Write a Python function that triggers a CI pipeline by pushing an empty commit on a PR branch. Validate inputs before making API calls.", "response": "import subprocess\n\ndef trigger_ci(repo_url: str, branch: str):\n subprocess.run(\n [\"git\", \"commit\", \"--allow-empty\", \"-m\", \"ci: trigger pipeline\"],\n check=True, capture_output=True,\n )\n subprocess.run([\"git\", \"push\", repo_url, branch], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0233", "domain": "pr_workflow", "prompt": "Write a robust, production-ready function that Write a Python function that rebases a feature branch onto the base branch before opening a PR. Surface clear exception messages on failure.", "response": "import subprocess\n\ndef rebase_branch(feature: str, base: str = \"main\"):\n subprocess.run([\"git\", \"checkout\", feature], check=True, capture_output=True)\n subprocess.run([\"git\", \"fetch\", \"origin\", base], check=True, capture_output=True)\n subprocess.run([\"git\", \"rebase\", f\"origin/{base}\"], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0240", "domain": "issue_automation", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that auto-triangles Gitea issues by running a classifier on the title and body. Surface clear exception messages on failure.", "response": "import random\n\ndef triage_issue(title: str, body: str) -> str:\n \"\"\"Simple rule-based triage classifier.\"\"\"\n text = (title + \" \" + body).lower()\n if any(w in text for w in [\"bug\", \"crash\", \"error\", \"fix\"]):\n return \"bug\"\n if any(w in text for w in [\"feature\", \"add\", \"implement\", \"support\"]):\n return \"feature\"\n if any(w in text for w in [\"docs\", \"documentation\", \"readme\"]):\n return \"documentation\"\n return \"ops\"\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0178", "domain": "repo_management", "prompt": "Author a defensive Python routine that Write a Python function that sets a webhook on a Gitea repo to trigger on push events. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef set_push_webhook(repo: str, token: str, webhook_url: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/hooks\"\n data = {\n \"type\": \"gitea\",\n \"config\": {\"url\": webhook_url, \"content_type\": \"json\"},\n \"events\": [\"push\"],\n \"active\": True,\n }\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0013", "domain": "issue_automation", "prompt": "Write a robust, production-ready function that Write a Python function that fetches the full timeline (comments) of a Gitea issue. Include error handling.", "response": "import urllib.request\nimport json\n\ndef get_issue_timeline(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/comments\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0117", "domain": "repo_management", "prompt": "Build a reusable module function that Write a Python function that adds a deploy key to a Gitea repo for CI access. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef add_deploy_key(repo: str, title: str, key: str, token: str, read_only: bool = True):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/keys\"\n data = {\"title\": title, \"key\": key, \"read_only\": read_only}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0166", "domain": "repo_management", "prompt": "Design a concise Python snippet that Write a Python function that lists all collaborators on a Gitea repo. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef list_collaborators(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/collaborators\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0013", "domain": "gitea_api", "prompt": "Write a robust, production-ready function that Write a Python function that converts a repo string 'owner/name' into a Gitea API path '/repos/owner/name'. Include error handling.", "response": "def repo_path(repo: str) -> str:\n \"\"\"Convert 'owner/name' to '/repos/owner/name'.\"\"\"\n if \"/\" not in repo:\n raise ValueError(\"Repo must be 'owner/name'\")\n return f\"/repos/{repo}\"\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0215", "domain": "issue_automation", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that auto-triangles Gitea issues by running a classifier on the title and body. Add timeout and connection cleanup.", "response": "import random\n\ndef triage_issue(title: str, body: str) -> str:\n \"\"\"Simple rule-based triage classifier.\"\"\"\n text = (title + \" \" + body).lower()\n if any(w in text for w in [\"bug\", \"crash\", \"error\", \"fix\"]):\n return \"bug\"\n if any(w in text for w in [\"feature\", \"add\", \"implement\", \"support\"]):\n return \"feature\"\n if any(w in text for w in [\"docs\", \"documentation\", \"readme\"]):\n return \"documentation\"\n return \"ops\"\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0064", "domain": "repo_management", "prompt": "Create a typed Python utility that Write a Python function that forks a Gitea repo into another organization via API. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef fork_repo(repo: str, org: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/forks\"\n data = {\"organization\": org}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0047", "domain": "pr_workflow", "prompt": "Build a reusable module function that Write a Python function that removes a label from a Gitea pull request. Add retry logic with exponential backoff.", "response": "import urllib.request\n\ndef remove_pr_label(repo: str, pr_number: int, label_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/labels/{label_id}\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0109", "domain": "issue_automation", "prompt": "Draft a minimal but complete solution that Write a Python function that calculates the age of a Gitea issue in days from its created_at timestamp. Validate inputs before making API calls.", "response": "from datetime import datetime, timezone\n\ndef issue_age_days(created_at: str) -> int:\n \"\"\"Calculate age of an issue in days.\"\"\"\n fmt = \"%Y-%m-%dT%H:%M:%SZ\"\n created = datetime.strptime(created_at, fmt).replace(tzinfo=timezone.utc)\n return (datetime.now(timezone.utc) - created).days\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0249", "domain": "repo_management", "prompt": "Draft a minimal but complete solution that Write a Python function that renames a branch in a Gitea repo via API. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef rename_branch(repo: str, old: str, new: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branches/{old}\"\n data = {\"name\": new}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0068", "domain": "repo_management", "prompt": "Author a defensive Python routine that Write a Python function that enables issue tracking on a Gitea repo via API. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef enable_issues(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"has_issues\": True}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0250", "domain": "issue_automation", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that updates the title of a Gitea issue via API. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef update_issue_title(repo: str, number: int, new_title: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"title\": new_title}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0215", "domain": "pr_workflow", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that dismisses a review on a Gitea pull request. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef dismiss_review(repo: str, pr_number: int, review_id: int, token: str, message: str = \"\"):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/reviews/{review_id}/dismissals\"\n data = {\"message\": message or \"Dismissed\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0142", "domain": "pr_workflow", "prompt": "Using only the Python standard library, Write a Python function that triggers a CI pipeline by pushing an empty commit on a PR branch. Handle empty responses gracefully.", "response": "import subprocess\n\ndef trigger_ci(repo_url: str, branch: str):\n subprocess.run(\n [\"git\", \"commit\", \"--allow-empty\", \"-m\", \"ci: trigger pipeline\"],\n check=True, capture_output=True,\n )\n subprocess.run([\"git\", \"push\", repo_url, branch], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0092", "domain": "issue_automation", "prompt": "Using only the Python standard library, Write a Python function that generates a markdown summary report of open issues for a repo. Log all failures for observability.", "response": "def generate_issue_report(repo: str, issues: list[dict]) -> str:\n lines = [f\"# Issue Report for {repo}\", \"\"]\n for i in issues:\n lines.append(f\"- #{i['number']} [{i['state']}] {i['title']}\")\n return \"\n\".join(lines)\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0139", "domain": "issue_automation", "prompt": "Draft a minimal but complete solution that Write a Python function that detects stale issues (no activity for 30 days) in a Gitea repo. Handle empty responses gracefully.", "response": "from datetime import datetime, timezone\n\ndef find_stale_issues(issues: list[dict], days: int = 30) -> list[dict]:\n now = datetime.now(timezone.utc)\n stale = []\n for i in issues:\n updated = datetime.fromisoformat(i[\"updated_at\"].replace(\"Z\", \"+00:00\"))\n if (now - updated).days > days:\n stale.append(i)\n return stale\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0151", "domain": "pr_workflow", "prompt": "Write a Python function that creates a pull request on Gitea via API. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef create_pull_request(repo: str, title: str, head: str, base: str, body: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls\"\n data = {\"title\": title, \"head\": head, \"base\": base, \"body\": body}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0053", "domain": "issue_automation", "prompt": "Write a robust, production-ready function that Write a Python function that posts a comment on a Gitea issue via API. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef comment_on_issue(repo: str, number: int, body: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/comments\"\n data = {\"body\": body}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0233", "domain": "repo_management", "prompt": "Write a robust, production-ready function that Write a Python function that creates a milestone in a Gitea repo with a due date. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\nfrom datetime import datetime, timezone\n\ndef create_milestone(repo: str, title: str, due_date: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/milestones\"\n data = {\"title\": title, \"due_on\": due_date}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0187", "domain": "gitea_api", "prompt": "Build a reusable module function that Write a Python function that validates a Gitea API token by calling the /user endpoint. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef validate_token(base_url: str, token: str) -> bool:\n \"\"\"Verify a token by calling the /user endpoint.\"\"\"\n req = urllib.request.Request(f\"{base_url}/api/v1/user\")\n req.add_header(\"Authorization\", f\"token {token}\")\n try:\n with urllib.request.urlopen(req, timeout=10) as resp:\n data = json.loads(resp.read().decode())\n return \"login\" in data\n except urllib.error.HTTPError as e:\n if e.code == 401:\n return False\n raise\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0097", "domain": "issue_automation", "prompt": "Build a reusable module function that Write a Python function that sets a milestone on a Gitea issue. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef set_milestone(repo: str, issue_number: int, milestone_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{issue_number}\"\n data = {\"milestone\": milestone_id}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0095", "domain": "pr_workflow", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that generates a release notes draft from merged PRs since the last tag. Log all failures for observability.", "response": "def generate_release_notes(merged_prs: list[dict], tag: str) -> str:\n lines = [f\"## Release {tag}\", \"\"]\n for pr in merged_prs:\n lines.append(f\"- #{pr['number']} {pr['title']}\")\n return \"\n\".join(lines)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0053", "domain": "gitea_api", "prompt": "Write a robust, production-ready function that Write a Python function that builds a Gitea API URL with query parameters for pagination. Return typed dataclasses where appropriate.", "response": "import urllib.parse\n\ndef build_api_url(base_url: str, path: str, params: dict | None = None) -> str:\n \"\"\"Build a Gitea API URL with optional query params.\"\"\"\n url = f\"{base_url.rstrip('/')}/api/v1{path}\"\n if params:\n clean = {k: v for k, v in params.items() if v is not None}\n url += \"?\" + urllib.parse.urlencode(clean)\n return url\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0217", "domain": "issue_automation", "prompt": "Build a reusable module function that Write a Python function that generates a markdown summary report of open issues for a repo. Add timeout and connection cleanup.", "response": "def generate_issue_report(repo: str, issues: list[dict]) -> str:\n lines = [f\"# Issue Report for {repo}\", \"\"]\n for i in issues:\n lines.append(f\"- #{i['number']} [{i['state']}] {i['title']}\")\n return \"\n\".join(lines)\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0066", "domain": "repo_management", "prompt": "Design a concise Python snippet that Write a Python function that lists all collaborators on a Gitea repo. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef list_collaborators(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/collaborators\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0150", "domain": "pr_workflow", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that cherry-picks a commit from one branch to another via Gitea API. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef cherry_pick_commit(repo: str, commit_sha: str, target_branch: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/git/commits\"\n data = {\"message\": f\"cherry-pick {commit_sha}\", \"parents\": [target_branch], \"tree\": commit_sha}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0024", "domain": "repo_management", "prompt": "Create a typed Python utility that Write a Python function that renames a branch in a Gitea repo via API. Include error handling.", "response": "import urllib.request\nimport json\n\ndef rename_branch(repo: str, old: str, new: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branches/{old}\"\n data = {\"name\": new}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0108", "domain": "pr_workflow", "prompt": "Author a defensive Python routine that Write a Python function that rebases a feature branch onto the base branch before opening a PR. Validate inputs before making API calls.", "response": "import subprocess\n\ndef rebase_branch(feature: str, base: str = \"main\"):\n subprocess.run([\"git\", \"checkout\", feature], check=True, capture_output=True)\n subprocess.run([\"git\", \"fetch\", \"origin\", base], check=True, capture_output=True)\n subprocess.run([\"git\", \"rebase\", f\"origin/{base}\"], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0195", "domain": "issue_automation", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that subscribes a user to notifications on a Gitea issue. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef subscribe_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/subscriptions\"\n req = urllib.request.Request(url, data=json.dumps({}).encode(), method=\"PUT\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0161", "domain": "issue_automation", "prompt": "Write a Python function that counts open issues per label in a Gitea repo. Include docstrings and type hints.", "response": "from collections import Counter\n\ndef count_issues_per_label(issues: list[dict]) -> Counter:\n counts = Counter()\n for i in issues:\n for label in i.get(\"labels\", []):\n counts[label.get(\"name\", \"unknown\")] += 1\n return counts\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0102", "domain": "issue_automation", "prompt": "Using only the Python standard library, Write a Python function that filters Gitea issues by label name. Validate inputs before making API calls.", "response": "def filter_by_label(issues: list[dict], label: str) -> list[dict]:\n return [i for i in issues if any(l.get(\"name\") == label for l in i.get(\"labels\", []))]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0114", "domain": "pr_workflow", "prompt": "Create a typed Python utility that Write a Python function that approves a Gitea pull request via API. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef approve_pr(repo: str, pr_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/reviews\"\n data = {\"body\": \"LGTM\", \"event\": \"APPROVE\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0105", "domain": "issue_automation", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that assigns a Gitea issue to a specific user. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef assign_issue(repo: str, number: int, assignees: list[str], token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"assignees\": assignees}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0236", "domain": "gitea_api", "prompt": "Design a concise Python snippet that Write a Python function that logs Gitea API requests and responses for debugging. Surface clear exception messages on failure.", "response": "import logging\nimport urllib.request\n\nlogger = logging.getLogger(\"gitea\")\n\ndef logged_request(req: urllib.request.Request):\n \"\"\"Execute a request and log the exchange.\"\"\"\n logger.debug(\"%s %s\", req.get_method(), req.full_url)\n with urllib.request.urlopen(req, timeout=30) as resp:\n body = resp.read().decode()\n logger.debug(\"Response %d: %s\", resp.status, body[:500])\n return body\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0099", "domain": "repo_management", "prompt": "Draft a minimal but complete solution that Write a Python function that renames a branch in a Gitea repo via API. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef rename_branch(repo: str, old: str, new: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branches/{old}\"\n data = {\"name\": new}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0136", "domain": "repo_management", "prompt": "Design a concise Python snippet that Write a Python function that updates a repo's description and website via the Gitea API. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef update_repo_description(repo: str, description: str, website: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"description\": description, \"website\": website}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0015", "domain": "gitea_api", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that caches Gitea API responses for 60 seconds to avoid redundant requests. Include error handling.", "response": "import time\nimport json\n\nclass TimedCache:\n def __init__(self, ttl: int = 60):\n self.ttl = ttl\n self.store = {}\n\n def get(self, key: str, fetch_fn):\n now = time.time()\n if key in self.store:\n value, expiry = self.store[key]\n if now < expiry:\n return value\n value = fetch_fn()\n self.store[key] = (value, now + self.ttl)\n return value\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0236", "domain": "issue_automation", "prompt": "Design a concise Python snippet that Write a Python function that counts open issues per label in a Gitea repo. Surface clear exception messages on failure.", "response": "from collections import Counter\n\ndef count_issues_per_label(issues: list[dict]) -> Counter:\n counts = Counter()\n for i in issues:\n for label in i.get(\"labels\", []):\n counts[label.get(\"name\", \"unknown\")] += 1\n return counts\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0030", "domain": "issue_automation", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that assigns a Gitea issue to a specific user. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef assign_issue(repo: str, number: int, assignees: list[str], token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"assignees\": assignees}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0002", "domain": "issue_automation", "prompt": "Using only the Python standard library, Write a Python function that filters Gitea issues by label name. Include error handling.", "response": "def filter_by_label(issues: list[dict], label: str) -> list[dict]:\n return [i for i in issues if any(l.get(\"name\") == label for l in i.get(\"labels\", []))]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0027", "domain": "gitea_api", "prompt": "Build a reusable module function that Write a Python function that reads a Gitea API token from standard local paths and returns it. Add retry logic with exponential backoff.", "response": "from pathlib import Path\n\ndef read_gitea_token() -> str:\n \"\"\"Read token from standard locations.\"\"\"\n for path in [\n Path.home() / \".hermes\" / \"gitea_token\",\n Path.home() / \".config\" / \"gitea\" / \"token\",\n ]:\n if path.exists():\n return path.read_text().strip()\n raise FileNotFoundError(\"No Gitea token found\")\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0160", "domain": "repo_management", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that performs a sparse checkout of a single directory from a Gitea repo. Include docstrings and type hints.", "response": "import subprocess\nfrom pathlib import Path\n\ndef sparse_checkout(repo_url: str, dest: str, directory: str):\n \"\"\"Sparse checkout a single directory.\"\"\"\n Path(dest).mkdir(parents=True, exist_ok=True)\n subprocess.run([\"git\", \"init\", dest], check=True, capture_output=True)\n subprocess.run([\"git\", \"-C\", dest, \"remote\", \"add\", \"origin\", repo_url], check=True, capture_output=True)\n subprocess.run([\"git\", \"-C\", dest, \"config\", \"core.sparseCheckout\", \"true\"], check=True, capture_output=True)\n sparse_file = Path(dest) / \".git\" / \"info\" / \"sparse-checkout\"\n sparse_file.write_text(directory + \"\\n\")\n subprocess.run([\"git\", \"-C\", dest, \"pull\", \"origin\", \"main\"], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0077", "domain": "pr_workflow", "prompt": "Build a reusable module function that Write a Python function that checks if an open pull request already exists for a given issue (by scanning title/body/branch). Log all failures for observability.", "response": "def issue_has_open_pr(prs: list[dict], issue_number: int) -> bool:\n num_str = str(issue_number)\n for pr in prs:\n combined = f\"{pr.get('title','')} {pr.get('body','')} {pr.get('head',{}).get('ref','')}\"\n if num_str in combined:\n return True\n return False\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0168", "domain": "repo_management", "prompt": "Author a defensive Python routine that Write a Python function that enables issue tracking on a Gitea repo via API. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef enable_issues(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"has_issues\": True}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0016", "domain": "repo_management", "prompt": "Design a concise Python snippet that Write a Python function that lists all collaborators on a Gitea repo. Include error handling.", "response": "import urllib.request\nimport json\n\ndef list_collaborators(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/collaborators\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0023", "domain": "issue_automation", "prompt": "Write a robust, production-ready function that Write a Python function that removes a milestone from a Gitea issue. Include error handling.", "response": "import urllib.request\nimport json\n\ndef remove_milestone(repo: str, issue_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{issue_number}\"\n data = {\"milestone\": 0}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0087", "domain": "gitea_api", "prompt": "Build a reusable module function that Write a Python function that validates a Gitea API token by calling the /user endpoint. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef validate_token(base_url: str, token: str) -> bool:\n \"\"\"Verify a token by calling the /user endpoint.\"\"\"\n req = urllib.request.Request(f\"{base_url}/api/v1/user\")\n req.add_header(\"Authorization\", f\"token {token}\")\n try:\n with urllib.request.urlopen(req, timeout=10) as resp:\n data = json.loads(resp.read().decode())\n return \"login\" in data\n except urllib.error.HTTPError as e:\n if e.code == 401:\n return False\n raise\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0236", "domain": "pr_workflow", "prompt": "Design a concise Python snippet that Write a Python function that calculates the net line change (additions - deletions) across all files in a PR. Surface clear exception messages on failure.", "response": "def net_line_change(files: list[dict]) -> int:\n return sum(f.get(\"additions\", 0) - f.get(\"deletions\", 0) for f in files)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0226", "domain": "repo_management", "prompt": "Design a concise Python snippet that Write a Python function that creates a new Gitea repo under an organization via API. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef create_repo(org: str, name: str, token: str, description: str = \"\", private: bool = False):\n url = f\"https://forge.example.com/api/v1/orgs/{org}/repos\"\n data = {\"name\": name, \"description\": description, \"private\": private}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0192", "domain": "gitea_api", "prompt": "Using only the Python standard library, Write a Python function that serializes a Python dict into JSON and sends it as the body of a PATCH request to Gitea. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef gitea_patch(base_url: str, path: str, token: str, data: dict):\n \"\"\"Serialize dict to JSON and PATCH.\"\"\"\n url = f\"{base_url.rstrip('/')}/api/v1{path}\"\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0237", "domain": "gitea_api", "prompt": "Build a reusable module function that Write a Python function that validates a Gitea API token by calling the /user endpoint. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef validate_token(base_url: str, token: str) -> bool:\n \"\"\"Verify a token by calling the /user endpoint.\"\"\"\n req = urllib.request.Request(f\"{base_url}/api/v1/user\")\n req.add_header(\"Authorization\", f\"token {token}\")\n try:\n with urllib.request.urlopen(req, timeout=10) as resp:\n data = json.loads(resp.read().decode())\n return \"login\" in data\n except urllib.error.HTTPError as e:\n if e.code == 401:\n return False\n raise\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0222", "domain": "gitea_api", "prompt": "Using only the Python standard library, Write a Python function that parses a Gitea API error response and extracts the human-readable message. Add timeout and connection cleanup.", "response": "import json\nimport urllib.error\n\ndef parse_error_body(e: urllib.error.HTTPError) -> str:\n \"\"\"Extract human-readable message from Gitea error response.\"\"\"\n try:\n body = json.loads(e.read().decode())\n return body.get(\"message\", str(e))\n except Exception:\n return str(e)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0243", "domain": "pr_workflow", "prompt": "Write a robust, production-ready function that Write a Python function that checks if a PR branch is behind the base branch and needs rebasing. Surface clear exception messages on failure.", "response": "import subprocess\n\ndef is_behind(base: str, feature: str) -> bool:\n result = subprocess.run(\n [\"git\", \"merge-base\", f\"origin/{base}\", feature],\n capture_output=True, text=True, check=True,\n )\n merge_base = result.stdout.strip()\n result2 = subprocess.run(\n [\"git\", \"rev-parse\", f\"origin/{base}\"],\n capture_output=True, text=True, check=True,\n )\n return merge_base != result2.stdout.strip()\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0218", "domain": "issue_automation", "prompt": "Author a defensive Python routine that Write a Python function that locks a Gitea issue to prevent further comments. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef lock_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/lock\"\n req = urllib.request.Request(url, data=json.dumps({}).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0162", "domain": "gitea_api", "prompt": "Using only the Python standard library, Write a Python function that validates a Gitea API token by calling the /user endpoint. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef validate_token(base_url: str, token: str) -> bool:\n \"\"\"Verify a token by calling the /user endpoint.\"\"\"\n req = urllib.request.Request(f\"{base_url}/api/v1/user\")\n req.add_header(\"Authorization\", f\"token {token}\")\n try:\n with urllib.request.urlopen(req, timeout=10) as resp:\n data = json.loads(resp.read().decode())\n return \"login\" in data\n except urllib.error.HTTPError as e:\n if e.code == 401:\n return False\n raise\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0130", "domain": "issue_automation", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that assigns a Gitea issue to a specific user. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef assign_issue(repo: str, number: int, assignees: list[str], token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"assignees\": assignees}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0234", "domain": "gitea_api", "prompt": "Create a typed Python utility that Write a Python function that sets proper request headers (Authorization, Content-Type, Accept) for Gitea API calls. Surface clear exception messages on failure.", "response": "def build_gitea_request(url: str, token: str, method: str = \"GET\", data: bytes | None = None):\n \"\"\"Build a request with standard headers.\"\"\"\n req = urllib.request.Request(url, data=data, method=method)\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n req.add_header(\"Accept\", \"application/json\")\n return req\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0131", "domain": "issue_automation", "prompt": "Write a Python function that checks whether a Gitea issue already has a bot comment to avoid duplicate comments. Handle empty responses gracefully.", "response": "def has_bot_comment(comments: list[dict], bot_marker: str = \"🤖\") -> bool:\n return any(bot_marker in c.get(\"body\", \"\") for c in comments)\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0154", "domain": "issue_automation", "prompt": "Create a typed Python utility that Write a Python function that closes a Gitea issue via API. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef close_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"state\": \"closed\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0112", "domain": "issue_automation", "prompt": "Using only the Python standard library, Write a Python function that reopens a closed Gitea issue via API. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef reopen_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"state\": \"open\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0035", "domain": "gitea_api", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that implements a circuit breaker for Gitea API requests after 3 consecutive failures. Add retry logic with exponential backoff.", "response": "class CircuitBreaker:\n def __init__(self, threshold: int = 3):\n self.failures = 0\n self.threshold = threshold\n self.open = False\n\n def call(self, fn, *args, **kwargs):\n if self.open:\n raise RuntimeError(\"Circuit breaker is OPEN\")\n try:\n result = fn(*args, **kwargs)\n self.failures = 0\n return result\n except Exception:\n self.failures += 1\n if self.failures >= self.threshold:\n self.open = True\n raise\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0093", "domain": "pr_workflow", "prompt": "Write a robust, production-ready function that Write a Python function that checks if a PR branch is behind the base branch and needs rebasing. Log all failures for observability.", "response": "import subprocess\n\ndef is_behind(base: str, feature: str) -> bool:\n result = subprocess.run(\n [\"git\", \"merge-base\", f\"origin/{base}\", feature],\n capture_output=True, text=True, check=True,\n )\n merge_base = result.stdout.strip()\n result2 = subprocess.run(\n [\"git\", \"rev-parse\", f\"origin/{base}\"],\n capture_output=True, text=True, check=True,\n )\n return merge_base != result2.stdout.strip()\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0121", "domain": "gitea_api", "prompt": "Write a Python function that retries only on 5xx and 429 errors, but fails immediately on 4xx (except 429). Validate inputs before making API calls.", "response": "import urllib.request\nimport urllib.error\nimport time\n\ndef smart_retry(req: urllib.request.Request, retries: int = 3):\n \"\"\"Retry on 5xx and 429; fail fast on other 4xx.\"\"\"\n for attempt in range(retries):\n try:\n return urllib.request.urlopen(req, timeout=30)\n except urllib.error.HTTPError as e:\n if e.code == 429 or e.code >= 500:\n if attempt == retries - 1:\n raise\n time.sleep(2 ** attempt)\n else:\n raise\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0039", "domain": "pr_workflow", "prompt": "Draft a minimal but complete solution that Write a Python function that approves a Gitea pull request via API. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef approve_pr(repo: str, pr_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/reviews\"\n data = {\"body\": \"LGTM\", \"event\": \"APPROVE\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0214", "domain": "pr_workflow", "prompt": "Create a typed Python utility that Write a Python function that approves a Gitea pull request via API. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef approve_pr(repo: str, pr_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/reviews\"\n data = {\"body\": \"LGTM\", \"event\": \"APPROVE\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0131", "domain": "gitea_api", "prompt": "Write a Python function that iterates through all pages of a paginated Gitea API endpoint. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef paginate_all(url_template: str, token: str, params: dict, limit: int = 50):\n \"\"\"Iterate all pages of a paginated Gitea endpoint.\"\"\"\n page = 1\n while True:\n params[\"page\"] = page\n params[\"limit\"] = limit\n req = urllib.request.Request(url_template + \"?\" + urllib.parse.urlencode(params))\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n batch = json.loads(resp.read().decode())\n if not batch:\n break\n yield from batch\n if len(batch) < limit:\n break\n page += 1\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0228", "domain": "gitea_api", "prompt": "Author a defensive Python routine that Write a Python function that builds a Gitea API URL with query parameters for pagination. Surface clear exception messages on failure.", "response": "import urllib.parse\n\ndef build_api_url(base_url: str, path: str, params: dict | None = None) -> str:\n \"\"\"Build a Gitea API URL with optional query params.\"\"\"\n url = f\"{base_url.rstrip('/')}/api/v1{path}\"\n if params:\n clean = {k: v for k, v in params.items() if v is not None}\n url += \"?\" + urllib.parse.urlencode(clean)\n return url\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0103", "domain": "repo_management", "prompt": "Write a robust, production-ready function that Write a Python function that sets a webhook on a Gitea repo to trigger on push events. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef set_push_webhook(repo: str, token: str, webhook_url: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/hooks\"\n data = {\n \"type\": \"gitea\",\n \"config\": {\"url\": webhook_url, \"content_type\": \"json\"},\n \"events\": [\"push\"],\n \"active\": True,\n }\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0154", "domain": "pr_workflow", "prompt": "Create a typed Python utility that Write a Python function that merges a Gitea pull request with retry logic for merge conflicts. Include docstrings and type hints.", "response": "import urllib.request\nimport urllib.error\nimport json\nimport time\n\ndef merge_pr(repo: str, number: int, token: str, method: str = \"squash\", retries: int = 3):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{number}/merge\"\n data = {\"Do\": method}\n for attempt in range(retries):\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n try:\n with urllib.request.urlopen(req, timeout=30) as resp:\n return True\n except urllib.error.HTTPError as e:\n if e.code == 405 and attempt < retries - 1:\n time.sleep(5)\n continue\n raise\n return False\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0185", "domain": "repo_management", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that performs a sparse checkout of a single directory from a Gitea repo. Optimize for minimal external dependencies.", "response": "import subprocess\nfrom pathlib import Path\n\ndef sparse_checkout(repo_url: str, dest: str, directory: str):\n \"\"\"Sparse checkout a single directory.\"\"\"\n Path(dest).mkdir(parents=True, exist_ok=True)\n subprocess.run([\"git\", \"init\", dest], check=True, capture_output=True)\n subprocess.run([\"git\", \"-C\", dest, \"remote\", \"add\", \"origin\", repo_url], check=True, capture_output=True)\n subprocess.run([\"git\", \"-C\", dest, \"config\", \"core.sparseCheckout\", \"true\"], check=True, capture_output=True)\n sparse_file = Path(dest) / \".git\" / \"info\" / \"sparse-checkout\"\n sparse_file.write_text(directory + \"\\n\")\n subprocess.run([\"git\", \"-C\", dest, \"pull\", \"origin\", \"main\"], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0019", "domain": "repo_management", "prompt": "Draft a minimal but complete solution that Write a Python function that archives a Gitea repo (read-only) via API. Include error handling.", "response": "import urllib.request\nimport json\n\ndef archive_repo(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"archived\": True}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0229", "domain": "issue_automation", "prompt": "Draft a minimal but complete solution that Write a Python function that closes a Gitea issue via API. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef close_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"state\": \"closed\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0248", "domain": "gitea_api", "prompt": "Author a defensive Python routine that Write a Python function that builds a Gitea API search query for issues across all repos in an organization. Surface clear exception messages on failure.", "response": "import urllib.request\nimport urllib.parse\n\ndef search_issues_url(org: str, query: str, state: str = \"open\") -> str:\n \"\"\"Build cross-repo issue search URL.\"\"\"\n params = urllib.parse.urlencode({\n \"q\": query,\n \"state\": state,\n \"type\": \"issues\",\n })\n return f\"/repos/search?{params}\"\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0116", "domain": "repo_management", "prompt": "Design a concise Python snippet that Write a Python function that lists all collaborators on a Gitea repo. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef list_collaborators(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/collaborators\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0117", "domain": "issue_automation", "prompt": "Build a reusable module function that Write a Python function that generates a markdown summary report of open issues for a repo. Validate inputs before making API calls.", "response": "def generate_issue_report(repo: str, issues: list[dict]) -> str:\n lines = [f\"# Issue Report for {repo}\", \"\"]\n for i in issues:\n lines.append(f\"- #{i['number']} [{i['state']}] {i['title']}\")\n return \"\n\".join(lines)\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0076", "domain": "issue_automation", "prompt": "Design a concise Python snippet that Write a Python function that fetches open issues from a Gitea repo and filters out pull requests. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef fetch_open_issues(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues?state=open&type=issues&limit=100\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return [i for i in json.loads(resp.read().decode()) if not i.get(\"pull_request\")]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0232", "domain": "pr_workflow", "prompt": "Using only the Python standard library, Write a Python function that checks whether a Gitea pull request is mergeable. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef is_mergeable(repo: str, pr_number: int, token: str) -> bool:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n data = json.loads(resp.read().decode())\n return data.get(\"mergeable\", False)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0183", "domain": "repo_management", "prompt": "Write a robust, production-ready function that Write a Python function that creates a milestone in a Gitea repo with a due date. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\nfrom datetime import datetime, timezone\n\ndef create_milestone(repo: str, title: str, due_date: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/milestones\"\n data = {\"title\": title, \"due_on\": due_date}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0049", "domain": "gitea_api", "prompt": "Draft a minimal but complete solution that Write a Python function that attaches a custom User-Agent header to all Gitea API requests. Add retry logic with exponential backoff.", "response": "import urllib.request\n\ndef request_with_user_agent(url: str, token: str, agent: str = \"timmy-bot/1.0\"):\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"User-Agent\", agent)\n return req\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0129", "domain": "pr_workflow", "prompt": "Draft a minimal but complete solution that Write a Python function that merges a Gitea pull request with retry logic for merge conflicts. Handle empty responses gracefully.", "response": "import urllib.request\nimport urllib.error\nimport json\nimport time\n\ndef merge_pr(repo: str, number: int, token: str, method: str = \"squash\", retries: int = 3):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{number}/merge\"\n data = {\"Do\": method}\n for attempt in range(retries):\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n try:\n with urllib.request.urlopen(req, timeout=30) as resp:\n return True\n except urllib.error.HTTPError as e:\n if e.code == 405 and attempt < retries - 1:\n time.sleep(5)\n continue\n raise\n return False\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0226", "domain": "pr_workflow", "prompt": "Design a concise Python snippet that Write a Python function that creates a pull request on Gitea via API. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef create_pull_request(repo: str, title: str, head: str, base: str, body: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls\"\n data = {\"title\": title, \"head\": head, \"base\": base, \"body\": body}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0118", "domain": "repo_management", "prompt": "Author a defensive Python routine that Write a Python function that enables issue tracking on a Gitea repo via API. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef enable_issues(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"has_issues\": True}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0036", "domain": "repo_management", "prompt": "Design a concise Python snippet that Write a Python function that updates a repo's description and website via the Gitea API. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef update_repo_description(repo: str, description: str, website: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"description\": description, \"website\": website}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0238", "domain": "pr_workflow", "prompt": "Author a defensive Python routine that Write a Python function that closes a pull request without merging it. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef close_pr(repo: str, pr_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}\"\n data = {\"state\": \"closed\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0158", "domain": "gitea_api", "prompt": "Author a defensive Python routine that Write a Python function that wraps the Gitea API in a typed dataclass response (Issue, PR, Comment). Include docstrings and type hints.", "response": "from dataclasses import dataclass\nfrom typing import Any\n\n@dataclass\nclass Issue:\n number: int\n title: str\n state: str\n\n @classmethod\n def from_dict(cls, d: dict) -> \"Issue\":\n return cls(\n number=d.get(\"number\", 0),\n title=d.get(\"title\", \"\"),\n state=d.get(\"state\", \"\"),\n )\n\ndef parse_issues(raw: list[dict]) -> list[Issue]:\n \"\"\"Convert raw API response into typed Issue objects.\"\"\"\n return [Issue.from_dict(i) for i in raw]\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0069", "domain": "repo_management", "prompt": "Draft a minimal but complete solution that Write a Python function that archives a Gitea repo (read-only) via API. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef archive_repo(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"archived\": True}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0217", "domain": "gitea_api", "prompt": "Build a reusable module function that Write a Python function that serializes a Python dict into JSON and sends it as the body of a PATCH request to Gitea. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef gitea_patch(base_url: str, path: str, token: str, data: dict):\n \"\"\"Serialize dict to JSON and PATCH.\"\"\"\n url = f\"{base_url.rstrip('/')}/api/v1{path}\"\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0107", "domain": "repo_management", "prompt": "Build a reusable module function that Write a Python function that lists all labels in a Gitea repo. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef list_labels(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/labels\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0185", "domain": "gitea_api", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that implements a circuit breaker for Gitea API requests after 3 consecutive failures. Optimize for minimal external dependencies.", "response": "class CircuitBreaker:\n def __init__(self, threshold: int = 3):\n self.failures = 0\n self.threshold = threshold\n self.open = False\n\n def call(self, fn, *args, **kwargs):\n if self.open:\n raise RuntimeError(\"Circuit breaker is OPEN\")\n try:\n result = fn(*args, **kwargs)\n self.failures = 0\n return result\n except Exception:\n self.failures += 1\n if self.failures >= self.threshold:\n self.open = True\n raise\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0186", "domain": "repo_management", "prompt": "Design a concise Python snippet that Write a Python function that updates a repo's description and website via the Gitea API. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef update_repo_description(repo: str, description: str, website: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"description\": description, \"website\": website}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0192", "domain": "repo_management", "prompt": "Using only the Python standard library, Write a Python function that adds a deploy key to a Gitea repo for CI access. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef add_deploy_key(repo: str, title: str, key: str, token: str, read_only: bool = True):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/keys\"\n data = {\"title\": title, \"key\": key, \"read_only\": read_only}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0028", "domain": "pr_workflow", "prompt": "Author a defensive Python routine that Write a Python function that lists all open pull requests for a Gitea repo. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef list_open_prs(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls?state=open&limit=100\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0202", "domain": "pr_workflow", "prompt": "Using only the Python standard library, Write a Python function that checks if an open pull request already exists for a given issue (by scanning title/body/branch). Add timeout and connection cleanup.", "response": "def issue_has_open_pr(prs: list[dict], issue_number: int) -> bool:\n num_str = str(issue_number)\n for pr in prs:\n combined = f\"{pr.get('title','')} {pr.get('body','')} {pr.get('head',{}).get('ref','')}\"\n if num_str in combined:\n return True\n return False\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0205", "domain": "issue_automation", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that assigns a Gitea issue to a specific user. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef assign_issue(repo: str, number: int, assignees: list[str], token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"assignees\": assignees}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0200", "domain": "gitea_api", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that closes idle Gitea API connections after 30 seconds to prevent socket exhaustion. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport socket\n\nclass TimeoutHTTPHandler(urllib.request.HTTPHandler):\n def __init__(self, timeout: int = 30):\n self.timeout = timeout\n super().__init__()\n\n def http_open(self, req):\n return self.do_open(lambda host, port: http.client.HTTPConnection(host, port, timeout=self.timeout), req)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0229", "domain": "gitea_api", "prompt": "Draft a minimal but complete solution that Write a Python function that makes an authenticated GET request to the Gitea API with retries and exponential backoff. Surface clear exception messages on failure.", "response": "import urllib.request\nimport urllib.error\nimport json\nimport time\n\ndef gitea_get_with_retries(url: str, token: str, retries: int = 3, backoff: float = 1.5):\n \"\"\"Authenticated GET with exponential backoff.\"\"\"\n for attempt in range(retries):\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n try:\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n except urllib.error.HTTPError as e:\n if 400 <= e.code < 500 and e.code != 429:\n raise\n if attempt == retries - 1:\n raise\n except urllib.error.URLError:\n if attempt == retries - 1:\n raise\n time.sleep(backoff ** attempt)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0225", "domain": "issue_automation", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that updates the title of a Gitea issue via API. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef update_issue_title(repo: str, number: int, new_title: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"title\": new_title}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0090", "domain": "issue_automation", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that auto-triangles Gitea issues by running a classifier on the title and body. Log all failures for observability.", "response": "import random\n\ndef triage_issue(title: str, body: str) -> str:\n \"\"\"Simple rule-based triage classifier.\"\"\"\n text = (title + \" \" + body).lower()\n if any(w in text for w in [\"bug\", \"crash\", \"error\", \"fix\"]):\n return \"bug\"\n if any(w in text for w in [\"feature\", \"add\", \"implement\", \"support\"]):\n return \"feature\"\n if any(w in text for w in [\"docs\", \"documentation\", \"readme\"]):\n return \"documentation\"\n return \"ops\"\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0207", "domain": "repo_management", "prompt": "Build a reusable module function that Write a Python function that lists all labels in a Gitea repo. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef list_labels(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/labels\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0167", "domain": "repo_management", "prompt": "Build a reusable module function that Write a Python function that adds a deploy key to a Gitea repo for CI access. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef add_deploy_key(repo: str, title: str, key: str, token: str, read_only: bool = True):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/keys\"\n data = {\"title\": title, \"key\": key, \"read_only\": read_only}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0074", "domain": "gitea_api", "prompt": "Create a typed Python utility that Write a Python function that attaches a custom User-Agent header to all Gitea API requests. Return typed dataclasses where appropriate.", "response": "import urllib.request\n\ndef request_with_user_agent(url: str, token: str, agent: str = \"timmy-bot/1.0\"):\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"User-Agent\", agent)\n return req\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0203", "domain": "pr_workflow", "prompt": "Write a robust, production-ready function that Write a Python function that lists all open pull requests for a Gitea repo. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef list_open_prs(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls?state=open&limit=100\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0122", "domain": "gitea_api", "prompt": "Using only the Python standard library, Write a Python function that parses a Gitea API error response and extracts the human-readable message. Validate inputs before making API calls.", "response": "import json\nimport urllib.error\n\ndef parse_error_body(e: urllib.error.HTTPError) -> str:\n \"\"\"Extract human-readable message from Gitea error response.\"\"\"\n try:\n body = json.loads(e.read().decode())\n return body.get(\"message\", str(e))\n except Exception:\n return str(e)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0070", "domain": "repo_management", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that un-archives a Gitea repo via API. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef unarchive_repo(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"archived\": False}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0160", "domain": "pr_workflow", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that lists the files changed in a Gitea pull request. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef list_pr_files(repo: str, pr_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/files\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0011", "domain": "issue_automation", "prompt": "Write a Python function that counts open issues per label in a Gitea repo. Include error handling.", "response": "from collections import Counter\n\ndef count_issues_per_label(issues: list[dict]) -> Counter:\n counts = Counter()\n for i in issues:\n for label in i.get(\"labels\", []):\n counts[label.get(\"name\", \"unknown\")] += 1\n return counts\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0094", "domain": "pr_workflow", "prompt": "Create a typed Python utility that Write a Python function that auto-squashes all commits on a PR branch before merging. Log all failures for observability.", "response": "import subprocess\n\ndef autosquash_branch(branch: str, base: str = \"main\"):\n subprocess.run([\"git\", \"checkout\", branch], check=True, capture_output=True)\n subprocess.run([\"git\", \"reset\", f\"origin/{base}\"], check=True, capture_output=True)\n subprocess.run([\"git\", \"add\", \"-A\"], check=True, capture_output=True)\n subprocess.run([\"git\", \"commit\", \"-m\", f\"feat: squash {branch}\"], check=True, capture_output=True)\n subprocess.run([\"git\", \"push\", \"--force-with-lease\", \"origin\", branch], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0080", "domain": "gitea_api", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that handles HTTP 401, 403, 404, and 500 errors from the Gitea API gracefully. Log all failures for observability.", "response": "import urllib.error\n\nclass GiteaError(Exception):\n def __init__(self, status: int, message: str):\n self.status = status\n super().__init__(f\"Gitea {status}: {message}\")\n\ndef handle_gitea_error(e: urllib.error.HTTPError) -> None:\n \"\"\"Map HTTP errors to typed exceptions.\"\"\"\n body = e.read().decode(errors=\"replace\") if e.fp else \"\"\n if e.code == 401:\n raise GiteaError(401, f\"Unauthorized. Check your token. {body}\")\n if e.code == 403:\n raise GiteaError(403, f\"Forbidden. {body}\")\n if e.code == 404:\n raise GiteaError(404, f\"Not found. {body}\")\n if e.code >= 500:\n raise GiteaError(e.code, f\"Server error. {body}\")\n raise GiteaError(e.code, body)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0221", "domain": "gitea_api", "prompt": "Write a Python function that retries only on 5xx and 429 errors, but fails immediately on 4xx (except 429). Add timeout and connection cleanup.", "response": "import urllib.request\nimport urllib.error\nimport time\n\ndef smart_retry(req: urllib.request.Request, retries: int = 3):\n \"\"\"Retry on 5xx and 429; fail fast on other 4xx.\"\"\"\n for attempt in range(retries):\n try:\n return urllib.request.urlopen(req, timeout=30)\n except urllib.error.HTTPError as e:\n if e.code == 429 or e.code >= 500:\n if attempt == retries - 1:\n raise\n time.sleep(2 ** attempt)\n else:\n raise\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0145", "domain": "issue_automation", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that subscribes a user to notifications on a Gitea issue. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef subscribe_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/subscriptions\"\n req = urllib.request.Request(url, data=json.dumps({}).encode(), method=\"PUT\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0227", "domain": "gitea_api", "prompt": "Build a reusable module function that Write a Python function that reads a Gitea API token from standard local paths and returns it. Surface clear exception messages on failure.", "response": "from pathlib import Path\n\ndef read_gitea_token() -> str:\n \"\"\"Read token from standard locations.\"\"\"\n for path in [\n Path.home() / \".hermes\" / \"gitea_token\",\n Path.home() / \".config\" / \"gitea\" / \"token\",\n ]:\n if path.exists():\n return path.read_text().strip()\n raise FileNotFoundError(\"No Gitea token found\")\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0185", "domain": "pr_workflow", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that lists the files changed in a Gitea pull request. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef list_pr_files(repo: str, pr_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/files\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0059", "domain": "issue_automation", "prompt": "Draft a minimal but complete solution that Write a Python function that calculates the age of a Gitea issue in days from its created_at timestamp. Return typed dataclasses where appropriate.", "response": "from datetime import datetime, timezone\n\ndef issue_age_days(created_at: str) -> int:\n \"\"\"Calculate age of an issue in days.\"\"\"\n fmt = \"%Y-%m-%dT%H:%M:%SZ\"\n created = datetime.strptime(created_at, fmt).replace(tzinfo=timezone.utc)\n return (datetime.now(timezone.utc) - created).days\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0174", "domain": "issue_automation", "prompt": "Create a typed Python utility that Write a Python function that finds issues created by a specific user in a Gitea repo. Include docstrings and type hints.", "response": "def find_issues_by_author(issues: list[dict], username: str) -> list[dict]:\n return [i for i in issues if i.get(\"user\", {}).get(\"login\") == username]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0084", "domain": "pr_workflow", "prompt": "Create a typed Python utility that Write a Python function that updates the description of an existing Gitea pull request. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef update_pr_description(repo: str, pr_number: int, new_body: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}\"\n data = {\"body\": new_body}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0164", "domain": "pr_workflow", "prompt": "Create a typed Python utility that Write a Python function that approves a Gitea pull request via API. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef approve_pr(repo: str, pr_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/reviews\"\n data = {\"body\": \"LGTM\", \"event\": \"APPROVE\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0159", "domain": "gitea_api", "prompt": "Draft a minimal but complete solution that Write a Python function that sets proper request headers (Authorization, Content-Type, Accept) for Gitea API calls. Include docstrings and type hints.", "response": "def build_gitea_request(url: str, token: str, method: str = \"GET\", data: bytes | None = None):\n \"\"\"Build a request with standard headers.\"\"\"\n req = urllib.request.Request(url, data=data, method=method)\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n req.add_header(\"Accept\", \"application/json\")\n return req\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0044", "domain": "repo_management", "prompt": "Create a typed Python utility that Write a Python function that archives a Gitea repo (read-only) via API. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef archive_repo(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"archived\": True}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0011", "domain": "gitea_api", "prompt": "Write a Python function that logs Gitea API requests and responses for debugging. Include error handling.", "response": "import logging\nimport urllib.request\n\nlogger = logging.getLogger(\"gitea\")\n\ndef logged_request(req: urllib.request.Request):\n \"\"\"Execute a request and log the exchange.\"\"\"\n logger.debug(\"%s %s\", req.get_method(), req.full_url)\n with urllib.request.urlopen(req, timeout=30) as resp:\n body = resp.read().decode()\n logger.debug(\"Response %d: %s\", resp.status, body[:500])\n return body\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0113", "domain": "pr_workflow", "prompt": "Write a robust, production-ready function that Write a Python function that closes a pull request without merging it. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef close_pr(repo: str, pr_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}\"\n data = {\"state\": \"closed\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0017", "domain": "issue_automation", "prompt": "Build a reusable module function that Write a Python function that generates a markdown summary report of open issues for a repo. Include error handling.", "response": "def generate_issue_report(repo: str, issues: list[dict]) -> str:\n lines = [f\"# Issue Report for {repo}\", \"\"]\n for i in issues:\n lines.append(f\"- #{i['number']} [{i['state']}] {i['title']}\")\n return \"\n\".join(lines)\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0138", "domain": "pr_workflow", "prompt": "Author a defensive Python routine that Write a Python function that closes a pull request without merging it. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef close_pr(repo: str, pr_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}\"\n data = {\"state\": \"closed\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0212", "domain": "pr_workflow", "prompt": "Using only the Python standard library, Write a Python function that detects destructive deletions in a PR (any file losing >50% of lines). Add timeout and connection cleanup.", "response": "def detect_destructive(files: list[dict], threshold: float = 0.5) -> list[str]:\n flagged = []\n for f in files:\n if f.get(\"status\") == \"modified\" and f.get(\"deletions\", 0) > 0:\n total = f.get(\"additions\", 0) + f.get(\"deletions\", 0)\n if total > 0 and f[\"deletions\"] / total > threshold:\n flagged.append(f[\"filename\"])\n return flagged\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0204", "domain": "repo_management", "prompt": "Create a typed Python utility that Write a Python function that lists all branches in a Gitea repo. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef list_branches(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branches\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0243", "domain": "repo_management", "prompt": "Write a robust, production-ready function that Write a Python function that enables issue tracking on a Gitea repo via API. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef enable_issues(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"has_issues\": True}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0002", "domain": "repo_management", "prompt": "Using only the Python standard library, Write a Python function that lists all repos in a Gitea organization with pagination. Include error handling.", "response": "import urllib.request\nimport json\n\ndef list_org_repos(org: str, token: str, limit: int = 50, page: int = 1):\n url = f\"https://forge.example.com/api/v1/orgs/{org}/repos?limit={limit}&page={page}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0069", "domain": "pr_workflow", "prompt": "Draft a minimal but complete solution that Write a Python function that auto-squashes all commits on a PR branch before merging. Return typed dataclasses where appropriate.", "response": "import subprocess\n\ndef autosquash_branch(branch: str, base: str = \"main\"):\n subprocess.run([\"git\", \"checkout\", branch], check=True, capture_output=True)\n subprocess.run([\"git\", \"reset\", f\"origin/{base}\"], check=True, capture_output=True)\n subprocess.run([\"git\", \"add\", \"-A\"], check=True, capture_output=True)\n subprocess.run([\"git\", \"commit\", \"-m\", f\"feat: squash {branch}\"], check=True, capture_output=True)\n subprocess.run([\"git\", \"push\", \"--force-with-lease\", \"origin\", branch], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0118", "domain": "issue_automation", "prompt": "Author a defensive Python routine that Write a Python function that locks a Gitea issue to prevent further comments. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef lock_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/lock\"\n req = urllib.request.Request(url, data=json.dumps({}).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0159", "domain": "issue_automation", "prompt": "Draft a minimal but complete solution that Write a Python function that calculates the age of a Gitea issue in days from its created_at timestamp. Include docstrings and type hints.", "response": "from datetime import datetime, timezone\n\ndef issue_age_days(created_at: str) -> int:\n \"\"\"Calculate age of an issue in days.\"\"\"\n fmt = \"%Y-%m-%dT%H:%M:%SZ\"\n created = datetime.strptime(created_at, fmt).replace(tzinfo=timezone.utc)\n return (datetime.now(timezone.utc) - created).days\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0246", "domain": "pr_workflow", "prompt": "Design a concise Python snippet that Write a Python function that adds a label to a Gitea pull request. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef add_pr_label(repo: str, pr_number: int, label_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/labels\"\n data = {\"labels\": [label_id]}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0113", "domain": "repo_management", "prompt": "Write a robust, production-ready function that Write a Python function that checks whether a branch exists in a remote Gitea repo without cloning. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef branch_exists(repo: str, branch: str, token: str) -> bool:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branches/{branch}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n try:\n with urllib.request.urlopen(req, timeout=10) as resp:\n return resp.status == 200\n except urllib.error.HTTPError as e:\n if e.code == 404:\n return False\n raise\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0020", "domain": "issue_automation", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that subscribes a user to notifications on a Gitea issue. Include error handling.", "response": "import urllib.request\nimport json\n\ndef subscribe_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/subscriptions\"\n req = urllib.request.Request(url, data=json.dumps({}).encode(), method=\"PUT\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0171", "domain": "issue_automation", "prompt": "Write a Python function that unsubscribes a user from notifications on a Gitea issue. Include docstrings and type hints.", "response": "import urllib.request\n\ndef unsubscribe_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/subscriptions\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0047", "domain": "gitea_api", "prompt": "Build a reusable module function that Write a Python function that parses a Gitea API error response and extracts the human-readable message. Add retry logic with exponential backoff.", "response": "import json\nimport urllib.error\n\ndef parse_error_body(e: urllib.error.HTTPError) -> str:\n \"\"\"Extract human-readable message from Gitea error response.\"\"\"\n try:\n body = json.loads(e.read().decode())\n return body.get(\"message\", str(e))\n except Exception:\n return str(e)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0056", "domain": "issue_automation", "prompt": "Design a concise Python snippet that Write a Python function that checks whether a Gitea issue already has a bot comment to avoid duplicate comments. Return typed dataclasses where appropriate.", "response": "def has_bot_comment(comments: list[dict], bot_marker: str = \"🤖\") -> bool:\n return any(bot_marker in c.get(\"body\", \"\") for c in comments)\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0149", "domain": "pr_workflow", "prompt": "Draft a minimal but complete solution that Write a Python function that fetches the commit history of a PR branch. Handle empty responses gracefully.", "response": "import subprocess\n\ndef get_pr_commits(branch: str, base: str = \"main\") -> list[str]:\n result = subprocess.run(\n [\"git\", \"log\", f\"origin/{base}..{branch}\", \"--pretty=format:%H %s\"],\n capture_output=True, text=True, check=True,\n )\n return result.stdout.strip().split(\"\n\") if result.stdout.strip() else []\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0139", "domain": "pr_workflow", "prompt": "Draft a minimal but complete solution that Write a Python function that approves a Gitea pull request via API. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef approve_pr(repo: str, pr_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/reviews\"\n data = {\"body\": \"LGTM\", \"event\": \"APPROVE\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0055", "domain": "repo_management", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that protects a branch in Gitea by requiring PR reviews before merge. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef protect_branch(repo: str, branch: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branch_protections\"\n data = {\"branch_name\": branch, \"enable_push\": False, \"enable_push_whitelist\": False}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0005", "domain": "pr_workflow", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that posts a review comment on a Gitea pull request. Include error handling.", "response": "import urllib.request\nimport json\n\ndef review_comment(repo: str, pr_number: int, body: str, token: str, path: str = \"\", position: int = 0):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/reviews\"\n data = {\"body\": body, \"event\": \"COMMENT\"}\n if path:\n data[\"comments\"] = [{\"path\": path, \"position\": position, \"body\": body}]\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0212", "domain": "issue_automation", "prompt": "Using only the Python standard library, Write a Python function that reopens a closed Gitea issue via API. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef reopen_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"state\": \"open\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0005", "domain": "repo_management", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that protects a branch in Gitea by requiring PR reviews before merge. Include error handling.", "response": "import urllib.request\nimport json\n\ndef protect_branch(repo: str, branch: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branch_protections\"\n data = {\"branch_name\": branch, \"enable_push\": False, \"enable_push_whitelist\": False}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0110", "domain": "repo_management", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that performs a sparse checkout of a single directory from a Gitea repo. Validate inputs before making API calls.", "response": "import subprocess\nfrom pathlib import Path\n\ndef sparse_checkout(repo_url: str, dest: str, directory: str):\n \"\"\"Sparse checkout a single directory.\"\"\"\n Path(dest).mkdir(parents=True, exist_ok=True)\n subprocess.run([\"git\", \"init\", dest], check=True, capture_output=True)\n subprocess.run([\"git\", \"-C\", dest, \"remote\", \"add\", \"origin\", repo_url], check=True, capture_output=True)\n subprocess.run([\"git\", \"-C\", dest, \"config\", \"core.sparseCheckout\", \"true\"], check=True, capture_output=True)\n sparse_file = Path(dest) / \".git\" / \"info\" / \"sparse-checkout\"\n sparse_file.write_text(directory + \"\\n\")\n subprocess.run([\"git\", \"-C\", dest, \"pull\", \"origin\", \"main\"], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0084", "domain": "repo_management", "prompt": "Create a typed Python utility that Write a Python function that clones a Gitea repo with --depth 1 for a shallow clone. Log all failures for observability.", "response": "import subprocess\n\ndef shallow_clone(repo_url: str, dest: str, branch: str = \"main\"):\n \"\"\"Clone with --depth 1 to save time and space.\"\"\"\n subprocess.run(\n [\"git\", \"clone\", \"--depth\", \"1\", \"--branch\", branch, repo_url, dest],\n check=True,\n capture_output=True,\n )\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0038", "domain": "gitea_api", "prompt": "Author a defensive Python routine that Write a Python function that converts a repo string 'owner/name' into a Gitea API path '/repos/owner/name'. Add retry logic with exponential backoff.", "response": "def repo_path(repo: str) -> str:\n \"\"\"Convert 'owner/name' to '/repos/owner/name'.\"\"\"\n if \"/\" not in repo:\n raise ValueError(\"Repo must be 'owner/name'\")\n return f\"/repos/{repo}\"\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0050", "domain": "pr_workflow", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that cherry-picks a commit from one branch to another via Gitea API. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef cherry_pick_commit(repo: str, commit_sha: str, target_branch: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/git/commits\"\n data = {\"message\": f\"cherry-pick {commit_sha}\", \"parents\": [target_branch], \"tree\": commit_sha}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0083", "domain": "gitea_api", "prompt": "Write a robust, production-ready function that Write a Python function that wraps the Gitea API in a typed dataclass response (Issue, PR, Comment). Log all failures for observability.", "response": "from dataclasses import dataclass\nfrom typing import Any\n\n@dataclass\nclass Issue:\n number: int\n title: str\n state: str\n\n @classmethod\n def from_dict(cls, d: dict) -> \"Issue\":\n return cls(\n number=d.get(\"number\", 0),\n title=d.get(\"title\", \"\"),\n state=d.get(\"state\", \"\"),\n )\n\ndef parse_issues(raw: list[dict]) -> list[Issue]:\n \"\"\"Convert raw API response into typed Issue objects.\"\"\"\n return [Issue.from_dict(i) for i in raw]\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0186", "domain": "issue_automation", "prompt": "Design a concise Python snippet that Write a Python function that counts open issues per label in a Gitea repo. Optimize for minimal external dependencies.", "response": "from collections import Counter\n\ndef count_issues_per_label(issues: list[dict]) -> Counter:\n counts = Counter()\n for i in issues:\n for label in i.get(\"labels\", []):\n counts[label.get(\"name\", \"unknown\")] += 1\n return counts\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0051", "domain": "issue_automation", "prompt": "Write a Python function that fetches open issues from a Gitea repo and filters out pull requests. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef fetch_open_issues(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues?state=open&type=issues&limit=100\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return [i for i in json.loads(resp.read().decode()) if not i.get(\"pull_request\")]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0235", "domain": "repo_management", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that performs a sparse checkout of a single directory from a Gitea repo. Surface clear exception messages on failure.", "response": "import subprocess\nfrom pathlib import Path\n\ndef sparse_checkout(repo_url: str, dest: str, directory: str):\n \"\"\"Sparse checkout a single directory.\"\"\"\n Path(dest).mkdir(parents=True, exist_ok=True)\n subprocess.run([\"git\", \"init\", dest], check=True, capture_output=True)\n subprocess.run([\"git\", \"-C\", dest, \"remote\", \"add\", \"origin\", repo_url], check=True, capture_output=True)\n subprocess.run([\"git\", \"-C\", dest, \"config\", \"core.sparseCheckout\", \"true\"], check=True, capture_output=True)\n sparse_file = Path(dest) / \".git\" / \"info\" / \"sparse-checkout\"\n sparse_file.write_text(directory + \"\\n\")\n subprocess.run([\"git\", \"-C\", dest, \"pull\", \"origin\", \"main\"], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0140", "domain": "issue_automation", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that auto-triangles Gitea issues by running a classifier on the title and body. Handle empty responses gracefully.", "response": "import random\n\ndef triage_issue(title: str, body: str) -> str:\n \"\"\"Simple rule-based triage classifier.\"\"\"\n text = (title + \" \" + body).lower()\n if any(w in text for w in [\"bug\", \"crash\", \"error\", \"fix\"]):\n return \"bug\"\n if any(w in text for w in [\"feature\", \"add\", \"implement\", \"support\"]):\n return \"feature\"\n if any(w in text for w in [\"docs\", \"documentation\", \"readme\"]):\n return \"documentation\"\n return \"ops\"\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0018", "domain": "issue_automation", "prompt": "Author a defensive Python routine that Write a Python function that locks a Gitea issue to prevent further comments. Include error handling.", "response": "import urllib.request\nimport json\n\ndef lock_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/lock\"\n req = urllib.request.Request(url, data=json.dumps({}).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0048", "domain": "repo_management", "prompt": "Author a defensive Python routine that Write a Python function that gets the default branch of a Gitea repo. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef get_default_branch(repo: str, token: str) -> str:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n data = json.loads(resp.read().decode())\n return data.get(\"default_branch\", \"main\")\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0235", "domain": "pr_workflow", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that lists the files changed in a Gitea pull request. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef list_pr_files(repo: str, pr_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/files\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0070", "domain": "pr_workflow", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that generates a release notes draft from merged PRs since the last tag. Return typed dataclasses where appropriate.", "response": "def generate_release_notes(merged_prs: list[dict], tag: str) -> str:\n lines = [f\"## Release {tag}\", \"\"]\n for pr in merged_prs:\n lines.append(f\"- #{pr['number']} {pr['title']}\")\n return \"\n\".join(lines)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0123", "domain": "pr_workflow", "prompt": "Write a robust, production-ready function that Write a Python function that blocks merging if a PR does not have at least one approved review. Validate inputs before making API calls.", "response": "def require_approval(pr: dict, reviews: list[dict]) -> bool:\n if pr.get(\"state\") != \"open\":\n return False\n approvals = [r for r in reviews if r.get(\"state\") == \"APPROVED\"]\n return len(approvals) >= 1\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0111", "domain": "repo_management", "prompt": "Write a Python function that updates a repo's description and website via the Gitea API. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef update_repo_description(repo: str, description: str, website: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"description\": description, \"website\": website}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0103", "domain": "gitea_api", "prompt": "Write a robust, production-ready function that Write a Python function that builds a Gitea API URL with query parameters for pagination. Validate inputs before making API calls.", "response": "import urllib.parse\n\ndef build_api_url(base_url: str, path: str, params: dict | None = None) -> str:\n \"\"\"Build a Gitea API URL with optional query params.\"\"\"\n url = f\"{base_url.rstrip('/')}/api/v1{path}\"\n if params:\n clean = {k: v for k, v in params.items() if v is not None}\n url += \"?\" + urllib.parse.urlencode(clean)\n return url\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0022", "domain": "issue_automation", "prompt": "Using only the Python standard library, Write a Python function that sets a milestone on a Gitea issue. Include error handling.", "response": "import urllib.request\nimport json\n\ndef set_milestone(repo: str, issue_number: int, milestone_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{issue_number}\"\n data = {\"milestone\": milestone_id}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0153", "domain": "issue_automation", "prompt": "Write a robust, production-ready function that Write a Python function that posts a comment on a Gitea issue via API. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef comment_on_issue(repo: str, number: int, body: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/comments\"\n data = {\"body\": body}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0219", "domain": "gitea_api", "prompt": "Draft a minimal but complete solution that Write a Python function that compares two Gitea API base URLs and normalizes them by stripping trailing slashes. Add timeout and connection cleanup.", "response": "def normalize_base_url(url: str) -> str:\n \"\"\"Strip trailing slashes and ensure no duplicate slashes.\"\"\"\n return url.rstrip(\"/\")\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0191", "domain": "repo_management", "prompt": "Write a Python function that lists all collaborators on a Gitea repo. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef list_collaborators(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/collaborators\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0101", "domain": "gitea_api", "prompt": "Write a Python function that pings a Gitea instance to check if it is alive. Validate inputs before making API calls.", "response": "import urllib.request\nimport urllib.error\nimport json\n\ndef ping_gitea(base_url: str) -> bool:\n \"\"\"Check if Gitea is responding.\"\"\"\n try:\n req = urllib.request.Request(f\"{base_url}/api/v1/version\")\n with urllib.request.urlopen(req, timeout=5) as resp:\n return resp.status == 200\n except Exception:\n return False\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0098", "domain": "gitea_api", "prompt": "Author a defensive Python routine that Write a Python function that builds a Gitea API search query for issues across all repos in an organization. Log all failures for observability.", "response": "import urllib.request\nimport urllib.parse\n\ndef search_issues_url(org: str, query: str, state: str = \"open\") -> str:\n \"\"\"Build cross-repo issue search URL.\"\"\"\n params = urllib.parse.urlencode({\n \"q\": query,\n \"state\": state,\n \"type\": \"issues\",\n })\n return f\"/repos/search?{params}\"\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0211", "domain": "repo_management", "prompt": "Write a Python function that updates a repo's description and website via the Gitea API. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef update_repo_description(repo: str, description: str, website: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"description\": description, \"website\": website}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0225", "domain": "gitea_api", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that closes idle Gitea API connections after 30 seconds to prevent socket exhaustion. Add timeout and connection cleanup.", "response": "import urllib.request\nimport socket\n\nclass TimeoutHTTPHandler(urllib.request.HTTPHandler):\n def __init__(self, timeout: int = 30):\n self.timeout = timeout\n super().__init__()\n\n def http_open(self, req):\n return self.do_open(lambda host, port: http.client.HTTPConnection(host, port, timeout=self.timeout), req)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0028", "domain": "gitea_api", "prompt": "Author a defensive Python routine that Write a Python function that builds a Gitea API URL with query parameters for pagination. Add retry logic with exponential backoff.", "response": "import urllib.parse\n\ndef build_api_url(base_url: str, path: str, params: dict | None = None) -> str:\n \"\"\"Build a Gitea API URL with optional query params.\"\"\"\n url = f\"{base_url.rstrip('/')}/api/v1{path}\"\n if params:\n clean = {k: v for k, v in params.items() if v is not None}\n url += \"?\" + urllib.parse.urlencode(clean)\n return url\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0110", "domain": "pr_workflow", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that lists the files changed in a Gitea pull request. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef list_pr_files(repo: str, pr_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/files\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0114", "domain": "issue_automation", "prompt": "Create a typed Python utility that Write a Python function that detects stale issues (no activity for 30 days) in a Gitea repo. Validate inputs before making API calls.", "response": "from datetime import datetime, timezone\n\ndef find_stale_issues(issues: list[dict], days: int = 30) -> list[dict]:\n now = datetime.now(timezone.utc)\n stale = []\n for i in issues:\n updated = datetime.fromisoformat(i[\"updated_at\"].replace(\"Z\", \"+00:00\"))\n if (now - updated).days > days:\n stale.append(i)\n return stale\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0184", "domain": "pr_workflow", "prompt": "Create a typed Python utility that Write a Python function that updates the description of an existing Gitea pull request. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef update_pr_description(repo: str, pr_number: int, new_body: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}\"\n data = {\"body\": new_body}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0095", "domain": "repo_management", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that un-archives a Gitea repo via API. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef unarchive_repo(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"archived\": False}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0003", "domain": "pr_workflow", "prompt": "Write a robust, production-ready function that Write a Python function that lists all open pull requests for a Gitea repo. Include error handling.", "response": "import urllib.request\nimport json\n\ndef list_open_prs(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls?state=open&limit=100\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0197", "domain": "repo_management", "prompt": "Build a reusable module function that Write a Python function that sets a repo topic (tag) via the Gitea API. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef set_repo_topic(repo: str, topic: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/topics\"\n data = {\"topics\": [topic]}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PUT\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0061", "domain": "gitea_api", "prompt": "Write a Python function that logs Gitea API requests and responses for debugging. Return typed dataclasses where appropriate.", "response": "import logging\nimport urllib.request\n\nlogger = logging.getLogger(\"gitea\")\n\ndef logged_request(req: urllib.request.Request):\n \"\"\"Execute a request and log the exchange.\"\"\"\n logger.debug(\"%s %s\", req.get_method(), req.full_url)\n with urllib.request.urlopen(req, timeout=30) as resp:\n body = resp.read().decode()\n logger.debug(\"Response %d: %s\", resp.status, body[:500])\n return body\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0130", "domain": "pr_workflow", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that posts a review comment on a Gitea pull request. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef review_comment(repo: str, pr_number: int, body: str, token: str, path: str = \"\", position: int = 0):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/reviews\"\n data = {\"body\": body, \"event\": \"COMMENT\"}\n if path:\n data[\"comments\"] = [{\"path\": path, \"position\": position, \"body\": body}]\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0201", "domain": "issue_automation", "prompt": "Write a Python function that fetches open issues from a Gitea repo and filters out pull requests. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef fetch_open_issues(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues?state=open&type=issues&limit=100\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return [i for i in json.loads(resp.read().decode()) if not i.get(\"pull_request\")]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0166", "domain": "issue_automation", "prompt": "Design a concise Python snippet that Write a Python function that migrates issues from one Gitea repo to another by creating copies. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef migrate_issue(source_repo: str, target_repo: str, issue: dict, token: str):\n owner, name = target_repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues\"\n data = {\n \"title\": f\"[Migrated] {issue['title']}\",\n \"body\": issue.get(\"body\", \"\"),\n }\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0108", "domain": "gitea_api", "prompt": "Author a defensive Python routine that Write a Python function that wraps the Gitea API in a typed dataclass response (Issue, PR, Comment). Validate inputs before making API calls.", "response": "from dataclasses import dataclass\nfrom typing import Any\n\n@dataclass\nclass Issue:\n number: int\n title: str\n state: str\n\n @classmethod\n def from_dict(cls, d: dict) -> \"Issue\":\n return cls(\n number=d.get(\"number\", 0),\n title=d.get(\"title\", \"\"),\n state=d.get(\"state\", \"\"),\n )\n\ndef parse_issues(raw: list[dict]) -> list[Issue]:\n \"\"\"Convert raw API response into typed Issue objects.\"\"\"\n return [Issue.from_dict(i) for i in raw]\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0215", "domain": "gitea_api", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that caches Gitea API responses for 60 seconds to avoid redundant requests. Add timeout and connection cleanup.", "response": "import time\nimport json\n\nclass TimedCache:\n def __init__(self, ttl: int = 60):\n self.ttl = ttl\n self.store = {}\n\n def get(self, key: str, fetch_fn):\n now = time.time()\n if key in self.store:\n value, expiry = self.store[key]\n if now < expiry:\n return value\n value = fetch_fn()\n self.store[key] = (value, now + self.ttl)\n return value\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0030", "domain": "pr_workflow", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that posts a review comment on a Gitea pull request. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef review_comment(repo: str, pr_number: int, body: str, token: str, path: str = \"\", position: int = 0):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/reviews\"\n data = {\"body\": body, \"event\": \"COMMENT\"}\n if path:\n data[\"comments\"] = [{\"path\": path, \"position\": position, \"body\": body}]\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0034", "domain": "gitea_api", "prompt": "Create a typed Python utility that Write a Python function that sets proper request headers (Authorization, Content-Type, Accept) for Gitea API calls. Add retry logic with exponential backoff.", "response": "def build_gitea_request(url: str, token: str, method: str = \"GET\", data: bytes | None = None):\n \"\"\"Build a request with standard headers.\"\"\"\n req = urllib.request.Request(url, data=data, method=method)\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n req.add_header(\"Accept\", \"application/json\")\n return req\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0190", "domain": "issue_automation", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that auto-triangles Gitea issues by running a classifier on the title and body. Optimize for minimal external dependencies.", "response": "import random\n\ndef triage_issue(title: str, body: str) -> str:\n \"\"\"Simple rule-based triage classifier.\"\"\"\n text = (title + \" \" + body).lower()\n if any(w in text for w in [\"bug\", \"crash\", \"error\", \"fix\"]):\n return \"bug\"\n if any(w in text for w in [\"feature\", \"add\", \"implement\", \"support\"]):\n return \"feature\"\n if any(w in text for w in [\"docs\", \"documentation\", \"readme\"]):\n return \"documentation\"\n return \"ops\"\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0238", "domain": "gitea_api", "prompt": "Author a defensive Python routine that Write a Python function that converts a repo string 'owner/name' into a Gitea API path '/repos/owner/name'. Surface clear exception messages on failure.", "response": "def repo_path(repo: str) -> str:\n \"\"\"Convert 'owner/name' to '/repos/owner/name'.\"\"\"\n if \"/\" not in repo:\n raise ValueError(\"Repo must be 'owner/name'\")\n return f\"/repos/{repo}\"\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0052", "domain": "repo_management", "prompt": "Using only the Python standard library, Write a Python function that lists all repos in a Gitea organization with pagination. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef list_org_repos(org: str, token: str, limit: int = 50, page: int = 1):\n url = f\"https://forge.example.com/api/v1/orgs/{org}/repos?limit={limit}&page={page}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0164", "domain": "issue_automation", "prompt": "Create a typed Python utility that Write a Python function that detects stale issues (no activity for 30 days) in a Gitea repo. Include docstrings and type hints.", "response": "from datetime import datetime, timezone\n\ndef find_stale_issues(issues: list[dict], days: int = 30) -> list[dict]:\n now = datetime.now(timezone.utc)\n stale = []\n for i in issues:\n updated = datetime.fromisoformat(i[\"updated_at\"].replace(\"Z\", \"+00:00\"))\n if (now - updated).days > days:\n stale.append(i)\n return stale\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0193", "domain": "gitea_api", "prompt": "Write a robust, production-ready function that Write a Python function that safely reads the response body from a Gitea API call even when the server returns an empty body. Optimize for minimal external dependencies.", "response": "import urllib.request\n\ndef safe_read_response(resp: urllib.request.addinfourl) -> dict:\n \"\"\"Return parsed JSON or empty dict if body is empty.\"\"\"\n raw = resp.read().decode()\n if not raw.strip():\n return {}\n import json\n return json.loads(raw)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0166", "domain": "gitea_api", "prompt": "Design a concise Python snippet that Write a Python function that implements rate-limit awareness by reading the X-RateLimit-Remaining header. Include docstrings and type hints.", "response": "import urllib.request\n\ndef check_rate_limit(resp: urllib.request.addinfourl) -> int:\n \"\"\"Read X-RateLimit-Remaining from response headers.\"\"\"\n remaining = resp.headers.get(\"X-RateLimit-Remaining\")\n return int(remaining) if remaining else -1\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0230", "domain": "gitea_api", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that handles HTTP 401, 403, 404, and 500 errors from the Gitea API gracefully. Surface clear exception messages on failure.", "response": "import urllib.error\n\nclass GiteaError(Exception):\n def __init__(self, status: int, message: str):\n self.status = status\n super().__init__(f\"Gitea {status}: {message}\")\n\ndef handle_gitea_error(e: urllib.error.HTTPError) -> None:\n \"\"\"Map HTTP errors to typed exceptions.\"\"\"\n body = e.read().decode(errors=\"replace\") if e.fp else \"\"\n if e.code == 401:\n raise GiteaError(401, f\"Unauthorized. Check your token. {body}\")\n if e.code == 403:\n raise GiteaError(403, f\"Forbidden. {body}\")\n if e.code == 404:\n raise GiteaError(404, f\"Not found. {body}\")\n if e.code >= 500:\n raise GiteaError(e.code, f\"Server error. {body}\")\n raise GiteaError(e.code, body)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0223", "domain": "pr_workflow", "prompt": "Write a robust, production-ready function that Write a Python function that blocks merging if a PR does not have at least one approved review. Add timeout and connection cleanup.", "response": "def require_approval(pr: dict, reviews: list[dict]) -> bool:\n if pr.get(\"state\") != \"open\":\n return False\n approvals = [r for r in reviews if r.get(\"state\") == \"APPROVED\"]\n return len(approvals) >= 1\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0220", "domain": "issue_automation", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that subscribes a user to notifications on a Gitea issue. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef subscribe_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/subscriptions\"\n req = urllib.request.Request(url, data=json.dumps({}).encode(), method=\"PUT\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0250", "domain": "pr_workflow", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that cherry-picks a commit from one branch to another via Gitea API. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef cherry_pick_commit(repo: str, commit_sha: str, target_branch: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/git/commits\"\n data = {\"message\": f\"cherry-pick {commit_sha}\", \"parents\": [target_branch], \"tree\": commit_sha}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0060", "domain": "pr_workflow", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that lists the files changed in a Gitea pull request. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef list_pr_files(repo: str, pr_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/files\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0214", "domain": "issue_automation", "prompt": "Create a typed Python utility that Write a Python function that detects stale issues (no activity for 30 days) in a Gitea repo. Add timeout and connection cleanup.", "response": "from datetime import datetime, timezone\n\ndef find_stale_issues(issues: list[dict], days: int = 30) -> list[dict]:\n now = datetime.now(timezone.utc)\n stale = []\n for i in issues:\n updated = datetime.fromisoformat(i[\"updated_at\"].replace(\"Z\", \"+00:00\"))\n if (now - updated).days > days:\n stale.append(i)\n return stale\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0152", "domain": "repo_management", "prompt": "Using only the Python standard library, Write a Python function that lists all repos in a Gitea organization with pagination. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef list_org_repos(org: str, token: str, limit: int = 50, page: int = 1):\n url = f\"https://forge.example.com/api/v1/orgs/{org}/repos?limit={limit}&page={page}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0022", "domain": "repo_management", "prompt": "Using only the Python standard library, Write a Python function that sets a repo topic (tag) via the Gitea API. Include error handling.", "response": "import urllib.request\nimport json\n\ndef set_repo_topic(repo: str, topic: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/topics\"\n data = {\"topics\": [topic]}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PUT\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0025", "domain": "issue_automation", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that updates the title of a Gitea issue via API. Include error handling.", "response": "import urllib.request\nimport json\n\ndef update_issue_title(repo: str, number: int, new_title: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"title\": new_title}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0221", "domain": "issue_automation", "prompt": "Write a Python function that unsubscribes a user from notifications on a Gitea issue. Add timeout and connection cleanup.", "response": "import urllib.request\n\ndef unsubscribe_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/subscriptions\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0201", "domain": "repo_management", "prompt": "Write a Python function that creates a new Gitea repo under an organization via API. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef create_repo(org: str, name: str, token: str, description: str = \"\", private: bool = False):\n url = f\"https://forge.example.com/api/v1/orgs/{org}/repos\"\n data = {\"name\": name, \"description\": description, \"private\": private}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0237", "domain": "pr_workflow", "prompt": "Build a reusable module function that Write a Python function that detects destructive deletions in a PR (any file losing >50% of lines). Surface clear exception messages on failure.", "response": "def detect_destructive(files: list[dict], threshold: float = 0.5) -> list[str]:\n flagged = []\n for f in files:\n if f.get(\"status\") == \"modified\" and f.get(\"deletions\", 0) > 0:\n total = f.get(\"additions\", 0) + f.get(\"deletions\", 0)\n if total > 0 and f[\"deletions\"] / total > threshold:\n flagged.append(f[\"filename\"])\n return flagged\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0134", "domain": "gitea_api", "prompt": "Create a typed Python utility that Write a Python function that sets proper request headers (Authorization, Content-Type, Accept) for Gitea API calls. Handle empty responses gracefully.", "response": "def build_gitea_request(url: str, token: str, method: str = \"GET\", data: bytes | None = None):\n \"\"\"Build a request with standard headers.\"\"\"\n req = urllib.request.Request(url, data=data, method=method)\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n req.add_header(\"Accept\", \"application/json\")\n return req\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0168", "domain": "pr_workflow", "prompt": "Author a defensive Python routine that Write a Python function that checks if a PR branch is behind the base branch and needs rebasing. Include docstrings and type hints.", "response": "import subprocess\n\ndef is_behind(base: str, feature: str) -> bool:\n result = subprocess.run(\n [\"git\", \"merge-base\", f\"origin/{base}\", feature],\n capture_output=True, text=True, check=True,\n )\n merge_base = result.stdout.strip()\n result2 = subprocess.run(\n [\"git\", \"rev-parse\", f\"origin/{base}\"],\n capture_output=True, text=True, check=True,\n )\n return merge_base != result2.stdout.strip()\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0114", "domain": "repo_management", "prompt": "Create a typed Python utility that Write a Python function that forks a Gitea repo into another organization via API. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef fork_repo(repo: str, org: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/forks\"\n data = {\"organization\": org}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0213", "domain": "issue_automation", "prompt": "Write a robust, production-ready function that Write a Python function that fetches the full timeline (comments) of a Gitea issue. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef get_issue_timeline(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/comments\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0062", "domain": "repo_management", "prompt": "Using only the Python standard library, Write a Python function that deletes a webhook from a Gitea repo by its ID. Return typed dataclasses where appropriate.", "response": "import urllib.request\n\ndef delete_webhook(repo: str, hook_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/hooks/{hook_id}\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0097", "domain": "repo_management", "prompt": "Build a reusable module function that Write a Python function that sets a repo topic (tag) via the Gitea API. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef set_repo_topic(repo: str, topic: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/topics\"\n data = {\"topics\": [topic]}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PUT\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0042", "domain": "repo_management", "prompt": "Using only the Python standard library, Write a Python function that adds a deploy key to a Gitea repo for CI access. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef add_deploy_key(repo: str, title: str, key: str, token: str, read_only: bool = True):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/keys\"\n data = {\"title\": title, \"key\": key, \"read_only\": read_only}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0060", "domain": "issue_automation", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that finds all unassigned open issues in a Gitea repo. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef find_unassigned_issues(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues?state=open&type=issues&limit=100\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n issues = json.loads(resp.read().decode())\n return [i for i in issues if not i.get(\"assignee\") and not i.get(\"pull_request\")]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0008", "domain": "repo_management", "prompt": "Author a defensive Python routine that Write a Python function that creates a milestone in a Gitea repo with a due date. Include error handling.", "response": "import urllib.request\nimport json\nfrom datetime import datetime, timezone\n\ndef create_milestone(repo: str, title: str, due_date: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/milestones\"\n data = {\"title\": title, \"due_on\": due_date}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0096", "domain": "gitea_api", "prompt": "Design a concise Python snippet that Write a Python function that retries only on 5xx and 429 errors, but fails immediately on 4xx (except 429). Log all failures for observability.", "response": "import urllib.request\nimport urllib.error\nimport time\n\ndef smart_retry(req: urllib.request.Request, retries: int = 3):\n \"\"\"Retry on 5xx and 429; fail fast on other 4xx.\"\"\"\n for attempt in range(retries):\n try:\n return urllib.request.urlopen(req, timeout=30)\n except urllib.error.HTTPError as e:\n if e.code == 429 or e.code >= 500:\n if attempt == retries - 1:\n raise\n time.sleep(2 ** attempt)\n else:\n raise\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0123", "domain": "repo_management", "prompt": "Write a robust, production-ready function that Write a Python function that gets the default branch of a Gitea repo. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef get_default_branch(repo: str, token: str) -> str:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n data = json.loads(resp.read().decode())\n return data.get(\"default_branch\", \"main\")\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0243", "domain": "gitea_api", "prompt": "Write a robust, production-ready function that Write a Python function that safely reads the response body from a Gitea API call even when the server returns an empty body. Surface clear exception messages on failure.", "response": "import urllib.request\n\ndef safe_read_response(resp: urllib.request.addinfourl) -> dict:\n \"\"\"Return parsed JSON or empty dict if body is empty.\"\"\"\n raw = resp.read().decode()\n if not raw.strip():\n return {}\n import json\n return json.loads(raw)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0240", "domain": "gitea_api", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that caches Gitea API responses for 60 seconds to avoid redundant requests. Surface clear exception messages on failure.", "response": "import time\nimport json\n\nclass TimedCache:\n def __init__(self, ttl: int = 60):\n self.ttl = ttl\n self.store = {}\n\n def get(self, key: str, fetch_fn):\n now = time.time()\n if key in self.store:\n value, expiry = self.store[key]\n if now < expiry:\n return value\n value = fetch_fn()\n self.store[key] = (value, now + self.ttl)\n return value\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0043", "domain": "gitea_api", "prompt": "Write a robust, production-ready function that Write a Python function that safely reads the response body from a Gitea API call even when the server returns an empty body. Add retry logic with exponential backoff.", "response": "import urllib.request\n\ndef safe_read_response(resp: urllib.request.addinfourl) -> dict:\n \"\"\"Return parsed JSON or empty dict if body is empty.\"\"\"\n raw = resp.read().decode()\n if not raw.strip():\n return {}\n import json\n return json.loads(raw)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0159", "domain": "pr_workflow", "prompt": "Draft a minimal but complete solution that Write a Python function that updates the description of an existing Gitea pull request. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef update_pr_description(repo: str, pr_number: int, new_body: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}\"\n data = {\"body\": new_body}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0088", "domain": "repo_management", "prompt": "Author a defensive Python routine that Write a Python function that checks whether a branch exists in a remote Gitea repo without cloning. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef branch_exists(repo: str, branch: str, token: str) -> bool:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branches/{branch}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n try:\n with urllib.request.urlopen(req, timeout=10) as resp:\n return resp.status == 200\n except urllib.error.HTTPError as e:\n if e.code == 404:\n return False\n raise\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0183", "domain": "issue_automation", "prompt": "Write a robust, production-ready function that Write a Python function that searches Gitea issues across an organization by keyword. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef search_issues(org: str, keyword: str, token: str):\n url = f\"https://forge.example.com/api/v1/repos/search?q={keyword}&uid=0&limit=50\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0009", "domain": "gitea_api", "prompt": "Draft a minimal but complete solution that Write a Python function that sets proper request headers (Authorization, Content-Type, Accept) for Gitea API calls. Include error handling.", "response": "def build_gitea_request(url: str, token: str, method: str = \"GET\", data: bytes | None = None):\n \"\"\"Build a request with standard headers.\"\"\"\n req = urllib.request.Request(url, data=data, method=method)\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n req.add_header(\"Accept\", \"application/json\")\n return req\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0009", "domain": "pr_workflow", "prompt": "Draft a minimal but complete solution that Write a Python function that updates the description of an existing Gitea pull request. Include error handling.", "response": "import urllib.request\nimport json\n\ndef update_pr_description(repo: str, pr_number: int, new_body: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}\"\n data = {\"body\": new_body}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0070", "domain": "gitea_api", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that creates a reusable urllib Request object with authentication for repeated Gitea API calls. Return typed dataclasses where appropriate.", "response": "import urllib.request\n\nclass AuthenticatedRequest:\n def __init__(self, base_url: str, token: str):\n self.base_url = base_url.rstrip(\"/\")\n self.token = token\n\n def build(self, path: str, method: str = \"GET\", data: bytes | None = None):\n url = f\"{self.base_url}/api/v1{path}\"\n req = urllib.request.Request(url, data=data, method=method)\n req.add_header(\"Authorization\", f\"token {self.token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n return req\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0161", "domain": "gitea_api", "prompt": "Write a Python function that logs Gitea API requests and responses for debugging. Include docstrings and type hints.", "response": "import logging\nimport urllib.request\n\nlogger = logging.getLogger(\"gitea\")\n\ndef logged_request(req: urllib.request.Request):\n \"\"\"Execute a request and log the exchange.\"\"\"\n logger.debug(\"%s %s\", req.get_method(), req.full_url)\n with urllib.request.urlopen(req, timeout=30) as resp:\n body = resp.read().decode()\n logger.debug(\"Response %d: %s\", resp.status, body[:500])\n return body\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0180", "domain": "pr_workflow", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that posts a review comment on a Gitea pull request. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef review_comment(repo: str, pr_number: int, body: str, token: str, path: str = \"\", position: int = 0):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/reviews\"\n data = {\"body\": body, \"event\": \"COMMENT\"}\n if path:\n data[\"comments\"] = [{\"path\": path, \"position\": position, \"body\": body}]\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0007", "domain": "pr_workflow", "prompt": "Build a reusable module function that Write a Python function that checks whether a Gitea pull request is mergeable. Include error handling.", "response": "import urllib.request\nimport json\n\ndef is_mergeable(repo: str, pr_number: int, token: str) -> bool:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n data = json.loads(resp.read().decode())\n return data.get(\"mergeable\", False)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0082", "domain": "issue_automation", "prompt": "Using only the Python standard library, Write a Python function that labels a batch of Gitea issues with the same label. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef batch_label_issues(repo: str, numbers: list[int], label_id: int, token: str):\n owner, name = repo.split(\"/\")\n for num in numbers:\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{num}/labels\"\n data = {\"labels\": [label_id]}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30):\n pass\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0095", "domain": "gitea_api", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that creates a reusable urllib Request object with authentication for repeated Gitea API calls. Log all failures for observability.", "response": "import urllib.request\n\nclass AuthenticatedRequest:\n def __init__(self, base_url: str, token: str):\n self.base_url = base_url.rstrip(\"/\")\n self.token = token\n\n def build(self, path: str, method: str = \"GET\", data: bytes | None = None):\n url = f\"{self.base_url}/api/v1{path}\"\n req = urllib.request.Request(url, data=data, method=method)\n req.add_header(\"Authorization\", f\"token {self.token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n return req\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0157", "domain": "pr_workflow", "prompt": "Build a reusable module function that Write a Python function that checks whether a Gitea pull request is mergeable. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef is_mergeable(repo: str, pr_number: int, token: str) -> bool:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n data = json.loads(resp.read().decode())\n return data.get(\"mergeable\", False)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0058", "domain": "pr_workflow", "prompt": "Author a defensive Python routine that Write a Python function that rebases a feature branch onto the base branch before opening a PR. Return typed dataclasses where appropriate.", "response": "import subprocess\n\ndef rebase_branch(feature: str, base: str = \"main\"):\n subprocess.run([\"git\", \"checkout\", feature], check=True, capture_output=True)\n subprocess.run([\"git\", \"fetch\", \"origin\", base], check=True, capture_output=True)\n subprocess.run([\"git\", \"rebase\", f\"origin/{base}\"], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0021", "domain": "issue_automation", "prompt": "Write a Python function that unsubscribes a user from notifications on a Gitea issue. Include error handling.", "response": "import urllib.request\n\ndef unsubscribe_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/subscriptions\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0156", "domain": "repo_management", "prompt": "Design a concise Python snippet that Write a Python function that creates a custom label in a Gitea repo with a specific color. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef create_label(repo: str, name: str, color: str, token: str):\n owner, repo_name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{repo_name}/labels\"\n data = {\"name\": name, \"color\": color}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0010", "domain": "gitea_api", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that implements a circuit breaker for Gitea API requests after 3 consecutive failures. Include error handling.", "response": "class CircuitBreaker:\n def __init__(self, threshold: int = 3):\n self.failures = 0\n self.threshold = threshold\n self.open = False\n\n def call(self, fn, *args, **kwargs):\n if self.open:\n raise RuntimeError(\"Circuit breaker is OPEN\")\n try:\n result = fn(*args, **kwargs)\n self.failures = 0\n return result\n except Exception:\n self.failures += 1\n if self.failures >= self.threshold:\n self.open = True\n raise\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0038", "domain": "pr_workflow", "prompt": "Author a defensive Python routine that Write a Python function that closes a pull request without merging it. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef close_pr(repo: str, pr_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}\"\n data = {\"state\": \"closed\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0105", "domain": "pr_workflow", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that posts a review comment on a Gitea pull request. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef review_comment(repo: str, pr_number: int, body: str, token: str, path: str = \"\", position: int = 0):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/reviews\"\n data = {\"body\": body, \"event\": \"COMMENT\"}\n if path:\n data[\"comments\"] = [{\"path\": path, \"position\": position, \"body\": body}]\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0131", "domain": "pr_workflow", "prompt": "Write a Python function that requests a specific user to review a Gitea pull request. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef request_review(repo: str, pr_number: int, reviewers: list[str], token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/requested_reviewers\"\n data = {\"reviewers\": reviewers}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0096", "domain": "issue_automation", "prompt": "Design a concise Python snippet that Write a Python function that unsubscribes a user from notifications on a Gitea issue. Log all failures for observability.", "response": "import urllib.request\n\ndef unsubscribe_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/subscriptions\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0210", "domain": "repo_management", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that performs a sparse checkout of a single directory from a Gitea repo. Add timeout and connection cleanup.", "response": "import subprocess\nfrom pathlib import Path\n\ndef sparse_checkout(repo_url: str, dest: str, directory: str):\n \"\"\"Sparse checkout a single directory.\"\"\"\n Path(dest).mkdir(parents=True, exist_ok=True)\n subprocess.run([\"git\", \"init\", dest], check=True, capture_output=True)\n subprocess.run([\"git\", \"-C\", dest, \"remote\", \"add\", \"origin\", repo_url], check=True, capture_output=True)\n subprocess.run([\"git\", \"-C\", dest, \"config\", \"core.sparseCheckout\", \"true\"], check=True, capture_output=True)\n sparse_file = Path(dest) / \".git\" / \"info\" / \"sparse-checkout\"\n sparse_file.write_text(directory + \"\\n\")\n subprocess.run([\"git\", \"-C\", dest, \"pull\", \"origin\", \"main\"], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0135", "domain": "gitea_api", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that implements a circuit breaker for Gitea API requests after 3 consecutive failures. Handle empty responses gracefully.", "response": "class CircuitBreaker:\n def __init__(self, threshold: int = 3):\n self.failures = 0\n self.threshold = threshold\n self.open = False\n\n def call(self, fn, *args, **kwargs):\n if self.open:\n raise RuntimeError(\"Circuit breaker is OPEN\")\n try:\n result = fn(*args, **kwargs)\n self.failures = 0\n return result\n except Exception:\n self.failures += 1\n if self.failures >= self.threshold:\n self.open = True\n raise\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0044", "domain": "pr_workflow", "prompt": "Create a typed Python utility that Write a Python function that auto-squashes all commits on a PR branch before merging. Add retry logic with exponential backoff.", "response": "import subprocess\n\ndef autosquash_branch(branch: str, base: str = \"main\"):\n subprocess.run([\"git\", \"checkout\", branch], check=True, capture_output=True)\n subprocess.run([\"git\", \"reset\", f\"origin/{base}\"], check=True, capture_output=True)\n subprocess.run([\"git\", \"add\", \"-A\"], check=True, capture_output=True)\n subprocess.run([\"git\", \"commit\", \"-m\", f\"feat: squash {branch}\"], check=True, capture_output=True)\n subprocess.run([\"git\", \"push\", \"--force-with-lease\", \"origin\", branch], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0032", "domain": "gitea_api", "prompt": "Using only the Python standard library, Write a Python function that uses urllib (no external deps) to POST JSON data to the Gitea API. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef gitea_post_json(base_url: str, path: str, token: str, data: dict):\n \"\"\"POST JSON to Gitea API using only stdlib.\"\"\"\n url = f\"{base_url.rstrip('/')}/api/v1{path}\"\n body = json.dumps(data).encode(\"utf-8\")\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n req.add_header(\"Accept\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n raw = resp.read().decode()\n return json.loads(raw) if raw.strip() else {}\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0100", "domain": "gitea_api", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that closes idle Gitea API connections after 30 seconds to prevent socket exhaustion. Log all failures for observability.", "response": "import urllib.request\nimport socket\n\nclass TimeoutHTTPHandler(urllib.request.HTTPHandler):\n def __init__(self, timeout: int = 30):\n self.timeout = timeout\n super().__init__()\n\n def http_open(self, req):\n return self.do_open(lambda host, port: http.client.HTTPConnection(host, port, timeout=self.timeout), req)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0046", "domain": "pr_workflow", "prompt": "Design a concise Python snippet that Write a Python function that adds a label to a Gitea pull request. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef add_pr_label(repo: str, pr_number: int, label_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/labels\"\n data = {\"labels\": [label_id]}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0001", "domain": "issue_automation", "prompt": "Write a Python function that fetches open issues from a Gitea repo and filters out pull requests. Include error handling.", "response": "import urllib.request\nimport json\n\ndef fetch_open_issues(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues?state=open&type=issues&limit=100\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return [i for i in json.loads(resp.read().decode()) if not i.get(\"pull_request\")]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0034", "domain": "repo_management", "prompt": "Create a typed Python utility that Write a Python function that clones a Gitea repo with --depth 1 for a shallow clone. Add retry logic with exponential backoff.", "response": "import subprocess\n\ndef shallow_clone(repo_url: str, dest: str, branch: str = \"main\"):\n \"\"\"Clone with --depth 1 to save time and space.\"\"\"\n subprocess.run(\n [\"git\", \"clone\", \"--depth\", \"1\", \"--branch\", branch, repo_url, dest],\n check=True,\n capture_output=True,\n )\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0063", "domain": "issue_automation", "prompt": "Write a robust, production-ready function that Write a Python function that fetches the full timeline (comments) of a Gitea issue. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef get_issue_timeline(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/comments\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0130", "domain": "repo_management", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that protects a branch in Gitea by requiring PR reviews before merge. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef protect_branch(repo: str, branch: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branch_protections\"\n data = {\"branch_name\": branch, \"enable_push\": False, \"enable_push_whitelist\": False}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0173", "domain": "gitea_api", "prompt": "Write a robust, production-ready function that Write a Python function that builds a Gitea API search query for issues across all repos in an organization. Include docstrings and type hints.", "response": "import urllib.request\nimport urllib.parse\n\ndef search_issues_url(org: str, query: str, state: str = \"open\") -> str:\n \"\"\"Build cross-repo issue search URL.\"\"\"\n params = urllib.parse.urlencode({\n \"q\": query,\n \"state\": state,\n \"type\": \"issues\",\n })\n return f\"/repos/search?{params}\"\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0133", "domain": "gitea_api", "prompt": "Write a robust, production-ready function that Write a Python function that wraps the Gitea API in a typed dataclass response (Issue, PR, Comment). Handle empty responses gracefully.", "response": "from dataclasses import dataclass\nfrom typing import Any\n\n@dataclass\nclass Issue:\n number: int\n title: str\n state: str\n\n @classmethod\n def from_dict(cls, d: dict) -> \"Issue\":\n return cls(\n number=d.get(\"number\", 0),\n title=d.get(\"title\", \"\"),\n state=d.get(\"state\", \"\"),\n )\n\ndef parse_issues(raw: list[dict]) -> list[Issue]:\n \"\"\"Convert raw API response into typed Issue objects.\"\"\"\n return [Issue.from_dict(i) for i in raw]\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0010", "domain": "repo_management", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that performs a sparse checkout of a single directory from a Gitea repo. Include error handling.", "response": "import subprocess\nfrom pathlib import Path\n\ndef sparse_checkout(repo_url: str, dest: str, directory: str):\n \"\"\"Sparse checkout a single directory.\"\"\"\n Path(dest).mkdir(parents=True, exist_ok=True)\n subprocess.run([\"git\", \"init\", dest], check=True, capture_output=True)\n subprocess.run([\"git\", \"-C\", dest, \"remote\", \"add\", \"origin\", repo_url], check=True, capture_output=True)\n subprocess.run([\"git\", \"-C\", dest, \"config\", \"core.sparseCheckout\", \"true\"], check=True, capture_output=True)\n sparse_file = Path(dest) / \".git\" / \"info\" / \"sparse-checkout\"\n sparse_file.write_text(directory + \"\\n\")\n subprocess.run([\"git\", \"-C\", dest, \"pull\", \"origin\", \"main\"], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0009", "domain": "issue_automation", "prompt": "Draft a minimal but complete solution that Write a Python function that calculates the age of a Gitea issue in days from its created_at timestamp. Include error handling.", "response": "from datetime import datetime, timezone\n\ndef issue_age_days(created_at: str) -> int:\n \"\"\"Calculate age of an issue in days.\"\"\"\n fmt = \"%Y-%m-%dT%H:%M:%SZ\"\n created = datetime.strptime(created_at, fmt).replace(tzinfo=timezone.utc)\n return (datetime.now(timezone.utc) - created).days\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0054", "domain": "issue_automation", "prompt": "Create a typed Python utility that Write a Python function that closes a Gitea issue via API. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef close_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"state\": \"closed\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0174", "domain": "pr_workflow", "prompt": "Create a typed Python utility that Write a Python function that fetches the commit history of a PR branch. Include docstrings and type hints.", "response": "import subprocess\n\ndef get_pr_commits(branch: str, base: str = \"main\") -> list[str]:\n result = subprocess.run(\n [\"git\", \"log\", f\"origin/{base}..{branch}\", \"--pretty=format:%H %s\"],\n capture_output=True, text=True, check=True,\n )\n return result.stdout.strip().split(\"\n\") if result.stdout.strip() else []\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0019", "domain": "gitea_api", "prompt": "Draft a minimal but complete solution that Write a Python function that compares two Gitea API base URLs and normalizes them by stripping trailing slashes. Include error handling.", "response": "def normalize_base_url(url: str) -> str:\n \"\"\"Strip trailing slashes and ensure no duplicate slashes.\"\"\"\n return url.rstrip(\"/\")\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0043", "domain": "pr_workflow", "prompt": "Write a robust, production-ready function that Write a Python function that checks if a PR branch is behind the base branch and needs rebasing. Add retry logic with exponential backoff.", "response": "import subprocess\n\ndef is_behind(base: str, feature: str) -> bool:\n result = subprocess.run(\n [\"git\", \"merge-base\", f\"origin/{base}\", feature],\n capture_output=True, text=True, check=True,\n )\n merge_base = result.stdout.strip()\n result2 = subprocess.run(\n [\"git\", \"rev-parse\", f\"origin/{base}\"],\n capture_output=True, text=True, check=True,\n )\n return merge_base != result2.stdout.strip()\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0048", "domain": "pr_workflow", "prompt": "Author a defensive Python routine that Write a Python function that blocks merging if a PR does not have at least one approved review. Add retry logic with exponential backoff.", "response": "def require_approval(pr: dict, reviews: list[dict]) -> bool:\n if pr.get(\"state\") != \"open\":\n return False\n approvals = [r for r in reviews if r.get(\"state\") == \"APPROVED\"]\n return len(approvals) >= 1\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0054", "domain": "repo_management", "prompt": "Create a typed Python utility that Write a Python function that lists all branches in a Gitea repo. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef list_branches(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branches\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0246", "domain": "gitea_api", "prompt": "Design a concise Python snippet that Write a Python function that retries only on 5xx and 429 errors, but fails immediately on 4xx (except 429). Surface clear exception messages on failure.", "response": "import urllib.request\nimport urllib.error\nimport time\n\ndef smart_retry(req: urllib.request.Request, retries: int = 3):\n \"\"\"Retry on 5xx and 429; fail fast on other 4xx.\"\"\"\n for attempt in range(retries):\n try:\n return urllib.request.urlopen(req, timeout=30)\n except urllib.error.HTTPError as e:\n if e.code == 429 or e.code >= 500:\n if attempt == retries - 1:\n raise\n time.sleep(2 ** attempt)\n else:\n raise\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0108", "domain": "repo_management", "prompt": "Author a defensive Python routine that Write a Python function that creates a milestone in a Gitea repo with a due date. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\nfrom datetime import datetime, timezone\n\ndef create_milestone(repo: str, title: str, due_date: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/milestones\"\n data = {\"title\": title, \"due_on\": due_date}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0176", "domain": "repo_management", "prompt": "Design a concise Python snippet that Write a Python function that creates a new Gitea repo under an organization via API. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef create_repo(org: str, name: str, token: str, description: str = \"\", private: bool = False):\n url = f\"https://forge.example.com/api/v1/orgs/{org}/repos\"\n data = {\"name\": name, \"description\": description, \"private\": private}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0207", "domain": "issue_automation", "prompt": "Build a reusable module function that Write a Python function that labels a batch of Gitea issues with the same label. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef batch_label_issues(repo: str, numbers: list[int], label_id: int, token: str):\n owner, name = repo.split(\"/\")\n for num in numbers:\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{num}/labels\"\n data = {\"labels\": [label_id]}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30):\n pass\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0002", "domain": "gitea_api", "prompt": "Using only the Python standard library, Write a Python function that reads a Gitea API token from standard local paths and returns it. Include error handling.", "response": "from pathlib import Path\n\ndef read_gitea_token() -> str:\n \"\"\"Read token from standard locations.\"\"\"\n for path in [\n Path.home() / \".hermes\" / \"gitea_token\",\n Path.home() / \".config\" / \"gitea\" / \"token\",\n ]:\n if path.exists():\n return path.read_text().strip()\n raise FileNotFoundError(\"No Gitea token found\")\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0004", "domain": "repo_management", "prompt": "Create a typed Python utility that Write a Python function that lists all branches in a Gitea repo. Include error handling.", "response": "import urllib.request\nimport json\n\ndef list_branches(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branches\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0081", "domain": "repo_management", "prompt": "Write a Python function that creates a custom label in a Gitea repo with a specific color. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef create_label(repo: str, name: str, color: str, token: str):\n owner, repo_name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{repo_name}/labels\"\n data = {\"name\": name, \"color\": color}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0031", "domain": "repo_management", "prompt": "Write a Python function that creates a custom label in a Gitea repo with a specific color. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef create_label(repo: str, name: str, color: str, token: str):\n owner, repo_name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{repo_name}/labels\"\n data = {\"name\": name, \"color\": color}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0223", "domain": "gitea_api", "prompt": "Write a robust, production-ready function that Write a Python function that builds a Gitea API search query for issues across all repos in an organization. Add timeout and connection cleanup.", "response": "import urllib.request\nimport urllib.parse\n\ndef search_issues_url(org: str, query: str, state: str = \"open\") -> str:\n \"\"\"Build cross-repo issue search URL.\"\"\"\n params = urllib.parse.urlencode({\n \"q\": query,\n \"state\": state,\n \"type\": \"issues\",\n })\n return f\"/repos/search?{params}\"\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0136", "domain": "issue_automation", "prompt": "Design a concise Python snippet that Write a Python function that counts open issues per label in a Gitea repo. Handle empty responses gracefully.", "response": "from collections import Counter\n\ndef count_issues_per_label(issues: list[dict]) -> Counter:\n counts = Counter()\n for i in issues:\n for label in i.get(\"labels\", []):\n counts[label.get(\"name\", \"unknown\")] += 1\n return counts\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0223", "domain": "repo_management", "prompt": "Write a robust, production-ready function that Write a Python function that gets the default branch of a Gitea repo. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef get_default_branch(repo: str, token: str) -> str:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n data = json.loads(resp.read().decode())\n return data.get(\"default_branch\", \"main\")\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0052", "domain": "issue_automation", "prompt": "Using only the Python standard library, Write a Python function that filters Gitea issues by label name. Return typed dataclasses where appropriate.", "response": "def filter_by_label(issues: list[dict], label: str) -> list[dict]:\n return [i for i in issues if any(l.get(\"name\") == label for l in i.get(\"labels\", []))]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0148", "domain": "gitea_api", "prompt": "Author a defensive Python routine that Write a Python function that builds a Gitea API search query for issues across all repos in an organization. Handle empty responses gracefully.", "response": "import urllib.request\nimport urllib.parse\n\ndef search_issues_url(org: str, query: str, state: str = \"open\") -> str:\n \"\"\"Build cross-repo issue search URL.\"\"\"\n params = urllib.parse.urlencode({\n \"q\": query,\n \"state\": state,\n \"type\": \"issues\",\n })\n return f\"/repos/search?{params}\"\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0153", "domain": "repo_management", "prompt": "Write a robust, production-ready function that Write a Python function that sets a webhook on a Gitea repo to trigger on push events. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef set_push_webhook(repo: str, token: str, webhook_url: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/hooks\"\n data = {\n \"type\": \"gitea\",\n \"config\": {\"url\": webhook_url, \"content_type\": \"json\"},\n \"events\": [\"push\"],\n \"active\": True,\n }\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0190", "domain": "repo_management", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that sets branch protection rules: no force-push, require status checks. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef set_strict_protection(repo: str, branch: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branch_protections\"\n data = {\n \"branch_name\": branch,\n \"enable_push\": False,\n \"enable_status_check\": True,\n \"status_check_contexts\": [\"ci/tests\"],\n }\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0154", "domain": "repo_management", "prompt": "Create a typed Python utility that Write a Python function that lists all branches in a Gitea repo. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef list_branches(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branches\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0148", "domain": "pr_workflow", "prompt": "Author a defensive Python routine that Write a Python function that blocks merging if a PR does not have at least one approved review. Handle empty responses gracefully.", "response": "def require_approval(pr: dict, reviews: list[dict]) -> bool:\n if pr.get(\"state\") != \"open\":\n return False\n approvals = [r for r in reviews if r.get(\"state\") == \"APPROVED\"]\n return len(approvals) >= 1\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0006", "domain": "gitea_api", "prompt": "Design a concise Python snippet that Write a Python function that iterates through all pages of a paginated Gitea API endpoint. Include error handling.", "response": "import urllib.request\nimport json\n\ndef paginate_all(url_template: str, token: str, params: dict, limit: int = 50):\n \"\"\"Iterate all pages of a paginated Gitea endpoint.\"\"\"\n page = 1\n while True:\n params[\"page\"] = page\n params[\"limit\"] = limit\n req = urllib.request.Request(url_template + \"?\" + urllib.parse.urlencode(params))\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n batch = json.loads(resp.read().decode())\n if not batch:\n break\n yield from batch\n if len(batch) < limit:\n break\n page += 1\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0023", "domain": "pr_workflow", "prompt": "Write a robust, production-ready function that Write a Python function that blocks merging if a PR does not have at least one approved review. Include error handling.", "response": "def require_approval(pr: dict, reviews: list[dict]) -> bool:\n if pr.get(\"state\") != \"open\":\n return False\n approvals = [r for r in reviews if r.get(\"state\") == \"APPROVED\"]\n return len(approvals) >= 1\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0128", "domain": "gitea_api", "prompt": "Author a defensive Python routine that Write a Python function that builds a Gitea API URL with query parameters for pagination. Handle empty responses gracefully.", "response": "import urllib.parse\n\ndef build_api_url(base_url: str, path: str, params: dict | None = None) -> str:\n \"\"\"Build a Gitea API URL with optional query params.\"\"\"\n url = f\"{base_url.rstrip('/')}/api/v1{path}\"\n if params:\n clean = {k: v for k, v in params.items() if v is not None}\n url += \"?\" + urllib.parse.urlencode(clean)\n return url\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0137", "domain": "pr_workflow", "prompt": "Build a reusable module function that Write a Python function that detects destructive deletions in a PR (any file losing >50% of lines). Handle empty responses gracefully.", "response": "def detect_destructive(files: list[dict], threshold: float = 0.5) -> list[str]:\n flagged = []\n for f in files:\n if f.get(\"status\") == \"modified\" and f.get(\"deletions\", 0) > 0:\n total = f.get(\"additions\", 0) + f.get(\"deletions\", 0)\n if total > 0 and f[\"deletions\"] / total > threshold:\n flagged.append(f[\"filename\"])\n return flagged\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0014", "domain": "repo_management", "prompt": "Create a typed Python utility that Write a Python function that forks a Gitea repo into another organization via API. Include error handling.", "response": "import urllib.request\nimport json\n\ndef fork_repo(repo: str, org: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/forks\"\n data = {\"organization\": org}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0085", "domain": "issue_automation", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that finds all unassigned open issues in a Gitea repo. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef find_unassigned_issues(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues?state=open&type=issues&limit=100\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n issues = json.loads(resp.read().decode())\n return [i for i in issues if not i.get(\"assignee\") and not i.get(\"pull_request\")]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0036", "domain": "gitea_api", "prompt": "Design a concise Python snippet that Write a Python function that logs Gitea API requests and responses for debugging. Add retry logic with exponential backoff.", "response": "import logging\nimport urllib.request\n\nlogger = logging.getLogger(\"gitea\")\n\ndef logged_request(req: urllib.request.Request):\n \"\"\"Execute a request and log the exchange.\"\"\"\n logger.debug(\"%s %s\", req.get_method(), req.full_url)\n with urllib.request.urlopen(req, timeout=30) as resp:\n body = resp.read().decode()\n logger.debug(\"Response %d: %s\", resp.status, body[:500])\n return body\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0209", "domain": "gitea_api", "prompt": "Draft a minimal but complete solution that Write a Python function that sets proper request headers (Authorization, Content-Type, Accept) for Gitea API calls. Add timeout and connection cleanup.", "response": "def build_gitea_request(url: str, token: str, method: str = \"GET\", data: bytes | None = None):\n \"\"\"Build a request with standard headers.\"\"\"\n req = urllib.request.Request(url, data=data, method=method)\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n req.add_header(\"Accept\", \"application/json\")\n return req\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0194", "domain": "issue_automation", "prompt": "Create a typed Python utility that Write a Python function that unlocks a previously locked Gitea issue. Optimize for minimal external dependencies.", "response": "import urllib.request\n\ndef unlock_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/lock\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0120", "domain": "issue_automation", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that subscribes a user to notifications on a Gitea issue. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef subscribe_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/subscriptions\"\n req = urllib.request.Request(url, data=json.dumps({}).encode(), method=\"PUT\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0028", "domain": "repo_management", "prompt": "Author a defensive Python routine that Write a Python function that sets a webhook on a Gitea repo to trigger on push events. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef set_push_webhook(repo: str, token: str, webhook_url: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/hooks\"\n data = {\n \"type\": \"gitea\",\n \"config\": {\"url\": webhook_url, \"content_type\": \"json\"},\n \"events\": [\"push\"],\n \"active\": True,\n }\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0074", "domain": "repo_management", "prompt": "Create a typed Python utility that Write a Python function that renames a branch in a Gitea repo via API. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef rename_branch(repo: str, old: str, new: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branches/{old}\"\n data = {\"name\": new}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0019", "domain": "pr_workflow", "prompt": "Draft a minimal but complete solution that Write a Python function that auto-squashes all commits on a PR branch before merging. Include error handling.", "response": "import subprocess\n\ndef autosquash_branch(branch: str, base: str = \"main\"):\n subprocess.run([\"git\", \"checkout\", branch], check=True, capture_output=True)\n subprocess.run([\"git\", \"reset\", f\"origin/{base}\"], check=True, capture_output=True)\n subprocess.run([\"git\", \"add\", \"-A\"], check=True, capture_output=True)\n subprocess.run([\"git\", \"commit\", \"-m\", f\"feat: squash {branch}\"], check=True, capture_output=True)\n subprocess.run([\"git\", \"push\", \"--force-with-lease\", \"origin\", branch], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0239", "domain": "issue_automation", "prompt": "Draft a minimal but complete solution that Write a Python function that detects stale issues (no activity for 30 days) in a Gitea repo. Surface clear exception messages on failure.", "response": "from datetime import datetime, timezone\n\ndef find_stale_issues(issues: list[dict], days: int = 30) -> list[dict]:\n now = datetime.now(timezone.utc)\n stale = []\n for i in issues:\n updated = datetime.fromisoformat(i[\"updated_at\"].replace(\"Z\", \"+00:00\"))\n if (now - updated).days > days:\n stale.append(i)\n return stale\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0189", "domain": "issue_automation", "prompt": "Draft a minimal but complete solution that Write a Python function that detects stale issues (no activity for 30 days) in a Gitea repo. Optimize for minimal external dependencies.", "response": "from datetime import datetime, timezone\n\ndef find_stale_issues(issues: list[dict], days: int = 30) -> list[dict]:\n now = datetime.now(timezone.utc)\n stale = []\n for i in issues:\n updated = datetime.fromisoformat(i[\"updated_at\"].replace(\"Z\", \"+00:00\"))\n if (now - updated).days > days:\n stale.append(i)\n return stale\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0139", "domain": "repo_management", "prompt": "Draft a minimal but complete solution that Write a Python function that forks a Gitea repo into another organization via API. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef fork_repo(repo: str, org: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/forks\"\n data = {\"organization\": org}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0169", "domain": "repo_management", "prompt": "Draft a minimal but complete solution that Write a Python function that archives a Gitea repo (read-only) via API. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef archive_repo(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"archived\": True}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0044", "domain": "issue_automation", "prompt": "Create a typed Python utility that Write a Python function that unlocks a previously locked Gitea issue. Add retry logic with exponential backoff.", "response": "import urllib.request\n\ndef unlock_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/lock\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0140", "domain": "gitea_api", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that caches Gitea API responses for 60 seconds to avoid redundant requests. Handle empty responses gracefully.", "response": "import time\nimport json\n\nclass TimedCache:\n def __init__(self, ttl: int = 60):\n self.ttl = ttl\n self.store = {}\n\n def get(self, key: str, fetch_fn):\n now = time.time()\n if key in self.store:\n value, expiry = self.store[key]\n if now < expiry:\n return value\n value = fetch_fn()\n self.store[key] = (value, now + self.ttl)\n return value\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0228", "domain": "repo_management", "prompt": "Author a defensive Python routine that Write a Python function that sets a webhook on a Gitea repo to trigger on push events. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef set_push_webhook(repo: str, token: str, webhook_url: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/hooks\"\n data = {\n \"type\": \"gitea\",\n \"config\": {\"url\": webhook_url, \"content_type\": \"json\"},\n \"events\": [\"push\"],\n \"active\": True,\n }\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0186", "domain": "gitea_api", "prompt": "Design a concise Python snippet that Write a Python function that logs Gitea API requests and responses for debugging. Optimize for minimal external dependencies.", "response": "import logging\nimport urllib.request\n\nlogger = logging.getLogger(\"gitea\")\n\ndef logged_request(req: urllib.request.Request):\n \"\"\"Execute a request and log the exchange.\"\"\"\n logger.debug(\"%s %s\", req.get_method(), req.full_url)\n with urllib.request.urlopen(req, timeout=30) as resp:\n body = resp.read().decode()\n logger.debug(\"Response %d: %s\", resp.status, body[:500])\n return body\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0206", "domain": "pr_workflow", "prompt": "Design a concise Python snippet that Write a Python function that requests a specific user to review a Gitea pull request. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef request_review(repo: str, pr_number: int, reviewers: list[str], token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/requested_reviewers\"\n data = {\"reviewers\": reviewers}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0236", "domain": "repo_management", "prompt": "Design a concise Python snippet that Write a Python function that updates a repo's description and website via the Gitea API. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef update_repo_description(repo: str, description: str, website: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"description\": description, \"website\": website}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0247", "domain": "pr_workflow", "prompt": "Build a reusable module function that Write a Python function that removes a label from a Gitea pull request. Surface clear exception messages on failure.", "response": "import urllib.request\n\ndef remove_pr_label(repo: str, pr_number: int, label_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/labels/{label_id}\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0241", "domain": "issue_automation", "prompt": "Write a Python function that migrates issues from one Gitea repo to another by creating copies. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef migrate_issue(source_repo: str, target_repo: str, issue: dict, token: str):\n owner, name = target_repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues\"\n data = {\n \"title\": f\"[Migrated] {issue['title']}\",\n \"body\": issue.get(\"body\", \"\"),\n }\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0040", "domain": "issue_automation", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that auto-triangles Gitea issues by running a classifier on the title and body. Add retry logic with exponential backoff.", "response": "import random\n\ndef triage_issue(title: str, body: str) -> str:\n \"\"\"Simple rule-based triage classifier.\"\"\"\n text = (title + \" \" + body).lower()\n if any(w in text for w in [\"bug\", \"crash\", \"error\", \"fix\"]):\n return \"bug\"\n if any(w in text for w in [\"feature\", \"add\", \"implement\", \"support\"]):\n return \"feature\"\n if any(w in text for w in [\"docs\", \"documentation\", \"readme\"]):\n return \"documentation\"\n return \"ops\"\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0079", "domain": "pr_workflow", "prompt": "Draft a minimal but complete solution that Write a Python function that merges a Gitea pull request with retry logic for merge conflicts. Log all failures for observability.", "response": "import urllib.request\nimport urllib.error\nimport json\nimport time\n\ndef merge_pr(repo: str, number: int, token: str, method: str = \"squash\", retries: int = 3):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{number}/merge\"\n data = {\"Do\": method}\n for attempt in range(retries):\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n try:\n with urllib.request.urlopen(req, timeout=30) as resp:\n return True\n except urllib.error.HTTPError as e:\n if e.code == 405 and attempt < retries - 1:\n time.sleep(5)\n continue\n raise\n return False\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0140", "domain": "pr_workflow", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that dismisses a review on a Gitea pull request. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef dismiss_review(repo: str, pr_number: int, review_id: int, token: str, message: str = \"\"):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/reviews/{review_id}/dismissals\"\n data = {\"message\": message or \"Dismissed\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0136", "domain": "pr_workflow", "prompt": "Design a concise Python snippet that Write a Python function that calculates the net line change (additions - deletions) across all files in a PR. Handle empty responses gracefully.", "response": "def net_line_change(files: list[dict]) -> int:\n return sum(f.get(\"additions\", 0) - f.get(\"deletions\", 0) for f in files)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0094", "domain": "repo_management", "prompt": "Create a typed Python utility that Write a Python function that archives a Gitea repo (read-only) via API. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef archive_repo(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"archived\": True}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0051", "domain": "gitea_api", "prompt": "Write a Python function that pings a Gitea instance to check if it is alive. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport urllib.error\nimport json\n\ndef ping_gitea(base_url: str) -> bool:\n \"\"\"Check if Gitea is responding.\"\"\"\n try:\n req = urllib.request.Request(f\"{base_url}/api/v1/version\")\n with urllib.request.urlopen(req, timeout=5) as resp:\n return resp.status == 200\n except Exception:\n return False\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0080", "domain": "issue_automation", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that assigns a Gitea issue to a specific user. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef assign_issue(repo: str, number: int, assignees: list[str], token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"assignees\": assignees}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0034", "domain": "pr_workflow", "prompt": "Create a typed Python utility that Write a Python function that updates the description of an existing Gitea pull request. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef update_pr_description(repo: str, pr_number: int, new_body: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}\"\n data = {\"body\": new_body}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0094", "domain": "gitea_api", "prompt": "Create a typed Python utility that Write a Python function that compares two Gitea API base URLs and normalizes them by stripping trailing slashes. Log all failures for observability.", "response": "def normalize_base_url(url: str) -> str:\n \"\"\"Strip trailing slashes and ensure no duplicate slashes.\"\"\"\n return url.rstrip(\"/\")\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0085", "domain": "pr_workflow", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that lists the files changed in a Gitea pull request. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef list_pr_files(repo: str, pr_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/files\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0177", "domain": "repo_management", "prompt": "Build a reusable module function that Write a Python function that lists all repos in a Gitea organization with pagination. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef list_org_repos(org: str, token: str, limit: int = 50, page: int = 1):\n url = f\"https://forge.example.com/api/v1/orgs/{org}/repos?limit={limit}&page={page}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0107", "domain": "issue_automation", "prompt": "Build a reusable module function that Write a Python function that labels a batch of Gitea issues with the same label. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef batch_label_issues(repo: str, numbers: list[int], label_id: int, token: str):\n owner, name = repo.split(\"/\")\n for num in numbers:\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{num}/labels\"\n data = {\"labels\": [label_id]}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30):\n pass\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0059", "domain": "repo_management", "prompt": "Draft a minimal but complete solution that Write a Python function that clones a Gitea repo with --depth 1 for a shallow clone. Return typed dataclasses where appropriate.", "response": "import subprocess\n\ndef shallow_clone(repo_url: str, dest: str, branch: str = \"main\"):\n \"\"\"Clone with --depth 1 to save time and space.\"\"\"\n subprocess.run(\n [\"git\", \"clone\", \"--depth\", \"1\", \"--branch\", branch, repo_url, dest],\n check=True,\n capture_output=True,\n )\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0031", "domain": "pr_workflow", "prompt": "Write a Python function that requests a specific user to review a Gitea pull request. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef request_review(repo: str, pr_number: int, reviewers: list[str], token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/requested_reviewers\"\n data = {\"reviewers\": reviewers}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0069", "domain": "issue_automation", "prompt": "Draft a minimal but complete solution that Write a Python function that unlocks a previously locked Gitea issue. Return typed dataclasses where appropriate.", "response": "import urllib.request\n\ndef unlock_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/lock\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0210", "domain": "pr_workflow", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that lists the files changed in a Gitea pull request. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef list_pr_files(repo: str, pr_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/files\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0204", "domain": "gitea_api", "prompt": "Create a typed Python utility that Write a Python function that makes an authenticated GET request to the Gitea API with retries and exponential backoff. Add timeout and connection cleanup.", "response": "import urllib.request\nimport urllib.error\nimport json\nimport time\n\ndef gitea_get_with_retries(url: str, token: str, retries: int = 3, backoff: float = 1.5):\n \"\"\"Authenticated GET with exponential backoff.\"\"\"\n for attempt in range(retries):\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n try:\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n except urllib.error.HTTPError as e:\n if 400 <= e.code < 500 and e.code != 429:\n raise\n if attempt == retries - 1:\n raise\n except urllib.error.URLError:\n if attempt == retries - 1:\n raise\n time.sleep(backoff ** attempt)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0068", "domain": "gitea_api", "prompt": "Author a defensive Python routine that Write a Python function that safely reads the response body from a Gitea API call even when the server returns an empty body. Return typed dataclasses where appropriate.", "response": "import urllib.request\n\ndef safe_read_response(resp: urllib.request.addinfourl) -> dict:\n \"\"\"Return parsed JSON or empty dict if body is empty.\"\"\"\n raw = resp.read().decode()\n if not raw.strip():\n return {}\n import json\n return json.loads(raw)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0146", "domain": "gitea_api", "prompt": "Design a concise Python snippet that Write a Python function that retries only on 5xx and 429 errors, but fails immediately on 4xx (except 429). Handle empty responses gracefully.", "response": "import urllib.request\nimport urllib.error\nimport time\n\ndef smart_retry(req: urllib.request.Request, retries: int = 3):\n \"\"\"Retry on 5xx and 429; fail fast on other 4xx.\"\"\"\n for attempt in range(retries):\n try:\n return urllib.request.urlopen(req, timeout=30)\n except urllib.error.HTTPError as e:\n if e.code == 429 or e.code >= 500:\n if attempt == retries - 1:\n raise\n time.sleep(2 ** attempt)\n else:\n raise\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0157", "domain": "issue_automation", "prompt": "Build a reusable module function that Write a Python function that labels a batch of Gitea issues with the same label. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef batch_label_issues(repo: str, numbers: list[int], label_id: int, token: str):\n owner, name = repo.split(\"/\")\n for num in numbers:\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{num}/labels\"\n data = {\"labels\": [label_id]}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30):\n pass\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0214", "domain": "repo_management", "prompt": "Create a typed Python utility that Write a Python function that forks a Gitea repo into another organization via API. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef fork_repo(repo: str, org: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/forks\"\n data = {\"organization\": org}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0217", "domain": "repo_management", "prompt": "Build a reusable module function that Write a Python function that adds a deploy key to a Gitea repo for CI access. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef add_deploy_key(repo: str, title: str, key: str, token: str, read_only: bool = True):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/keys\"\n data = {\"title\": title, \"key\": key, \"read_only\": read_only}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0109", "domain": "pr_workflow", "prompt": "Draft a minimal but complete solution that Write a Python function that updates the description of an existing Gitea pull request. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef update_pr_description(repo: str, pr_number: int, new_body: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}\"\n data = {\"body\": new_body}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0228", "domain": "pr_workflow", "prompt": "Author a defensive Python routine that Write a Python function that lists all open pull requests for a Gitea repo. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef list_open_prs(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls?state=open&limit=100\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0069", "domain": "gitea_api", "prompt": "Draft a minimal but complete solution that Write a Python function that compares two Gitea API base URLs and normalizes them by stripping trailing slashes. Return typed dataclasses where appropriate.", "response": "def normalize_base_url(url: str) -> str:\n \"\"\"Strip trailing slashes and ensure no duplicate slashes.\"\"\"\n return url.rstrip(\"/\")\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0150", "domain": "issue_automation", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that updates the title of a Gitea issue via API. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef update_issue_title(repo: str, number: int, new_title: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"title\": new_title}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0006", "domain": "issue_automation", "prompt": "Design a concise Python snippet that Write a Python function that checks whether a Gitea issue already has a bot comment to avoid duplicate comments. Include error handling.", "response": "def has_bot_comment(comments: list[dict], bot_marker: str = \"🤖\") -> bool:\n return any(bot_marker in c.get(\"body\", \"\") for c in comments)\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0157", "domain": "repo_management", "prompt": "Build a reusable module function that Write a Python function that lists all labels in a Gitea repo. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef list_labels(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/labels\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0194", "domain": "repo_management", "prompt": "Create a typed Python utility that Write a Python function that archives a Gitea repo (read-only) via API. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef archive_repo(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"archived\": True}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0214", "domain": "gitea_api", "prompt": "Create a typed Python utility that Write a Python function that measures the latency of a Gitea API call and raises a warning if it exceeds 2 seconds. Add timeout and connection cleanup.", "response": "import time\nimport urllib.request\n\ndef timed_request(req: urllib.request.Request, threshold: float = 2.0):\n \"\"\"Execute request and warn if latency exceeds threshold.\"\"\"\n start = time.time()\n with urllib.request.urlopen(req, timeout=30) as resp:\n body = resp.read().decode()\n elapsed = time.time() - start\n if elapsed > threshold:\n print(f\"WARNING: Request took {elapsed:.2f}s\")\n return body\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0010", "domain": "issue_automation", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that finds all unassigned open issues in a Gitea repo. Include error handling.", "response": "import urllib.request\nimport json\n\ndef find_unassigned_issues(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues?state=open&type=issues&limit=100\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n issues = json.loads(resp.read().decode())\n return [i for i in issues if not i.get(\"assignee\") and not i.get(\"pull_request\")]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0189", "domain": "pr_workflow", "prompt": "Draft a minimal but complete solution that Write a Python function that approves a Gitea pull request via API. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef approve_pr(repo: str, pr_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/reviews\"\n data = {\"body\": \"LGTM\", \"event\": \"APPROVE\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0181", "domain": "issue_automation", "prompt": "Write a Python function that checks whether a Gitea issue already has a bot comment to avoid duplicate comments. Optimize for minimal external dependencies.", "response": "def has_bot_comment(comments: list[dict], bot_marker: str = \"🤖\") -> bool:\n return any(bot_marker in c.get(\"body\", \"\") for c in comments)\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0195", "domain": "repo_management", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that un-archives a Gitea repo via API. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef unarchive_repo(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"archived\": False}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0199", "domain": "gitea_api", "prompt": "Draft a minimal but complete solution that Write a Python function that attaches a custom User-Agent header to all Gitea API requests. Optimize for minimal external dependencies.", "response": "import urllib.request\n\ndef request_with_user_agent(url: str, token: str, agent: str = \"timmy-bot/1.0\"):\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"User-Agent\", agent)\n return req\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0106", "domain": "gitea_api", "prompt": "Design a concise Python snippet that Write a Python function that iterates through all pages of a paginated Gitea API endpoint. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef paginate_all(url_template: str, token: str, params: dict, limit: int = 50):\n \"\"\"Iterate all pages of a paginated Gitea endpoint.\"\"\"\n page = 1\n while True:\n params[\"page\"] = page\n params[\"limit\"] = limit\n req = urllib.request.Request(url_template + \"?\" + urllib.parse.urlencode(params))\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n batch = json.loads(resp.read().decode())\n if not batch:\n break\n yield from batch\n if len(batch) < limit:\n break\n page += 1\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0144", "domain": "repo_management", "prompt": "Create a typed Python utility that Write a Python function that archives a Gitea repo (read-only) via API. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef archive_repo(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"archived\": True}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0100", "domain": "pr_workflow", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that cherry-picks a commit from one branch to another via Gitea API. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef cherry_pick_commit(repo: str, commit_sha: str, target_branch: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/git/commits\"\n data = {\"message\": f\"cherry-pick {commit_sha}\", \"parents\": [target_branch], \"tree\": commit_sha}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0102", "domain": "gitea_api", "prompt": "Using only the Python standard library, Write a Python function that reads a Gitea API token from standard local paths and returns it. Validate inputs before making API calls.", "response": "from pathlib import Path\n\ndef read_gitea_token() -> str:\n \"\"\"Read token from standard locations.\"\"\"\n for path in [\n Path.home() / \".hermes\" / \"gitea_token\",\n Path.home() / \".config\" / \"gitea\" / \"token\",\n ]:\n if path.exists():\n return path.read_text().strip()\n raise FileNotFoundError(\"No Gitea token found\")\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0051", "domain": "pr_workflow", "prompt": "Write a Python function that creates a pull request on Gitea via API. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef create_pull_request(repo: str, title: str, head: str, base: str, body: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls\"\n data = {\"title\": title, \"head\": head, \"base\": base, \"body\": body}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0086", "domain": "issue_automation", "prompt": "Design a concise Python snippet that Write a Python function that counts open issues per label in a Gitea repo. Log all failures for observability.", "response": "from collections import Counter\n\ndef count_issues_per_label(issues: list[dict]) -> Counter:\n counts = Counter()\n for i in issues:\n for label in i.get(\"labels\", []):\n counts[label.get(\"name\", \"unknown\")] += 1\n return counts\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0051", "domain": "repo_management", "prompt": "Write a Python function that creates a new Gitea repo under an organization via API. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef create_repo(org: str, name: str, token: str, description: str = \"\", private: bool = False):\n url = f\"https://forge.example.com/api/v1/orgs/{org}/repos\"\n data = {\"name\": name, \"description\": description, \"private\": private}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0196", "domain": "repo_management", "prompt": "Design a concise Python snippet that Write a Python function that transfers a Gitea repo from one owner to another. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef transfer_repo(repo: str, new_owner: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/transfer\"\n data = {\"new_owner\": new_owner}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0239", "domain": "gitea_api", "prompt": "Draft a minimal but complete solution that Write a Python function that measures the latency of a Gitea API call and raises a warning if it exceeds 2 seconds. Surface clear exception messages on failure.", "response": "import time\nimport urllib.request\n\ndef timed_request(req: urllib.request.Request, threshold: float = 2.0):\n \"\"\"Execute request and warn if latency exceeds threshold.\"\"\"\n start = time.time()\n with urllib.request.urlopen(req, timeout=30) as resp:\n body = resp.read().decode()\n elapsed = time.time() - start\n if elapsed > threshold:\n print(f\"WARNING: Request took {elapsed:.2f}s\")\n return body\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0095", "domain": "issue_automation", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that subscribes a user to notifications on a Gitea issue. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef subscribe_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/subscriptions\"\n req = urllib.request.Request(url, data=json.dumps({}).encode(), method=\"PUT\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0227", "domain": "pr_workflow", "prompt": "Build a reusable module function that Write a Python function that checks if an open pull request already exists for a given issue (by scanning title/body/branch). Surface clear exception messages on failure.", "response": "def issue_has_open_pr(prs: list[dict], issue_number: int) -> bool:\n num_str = str(issue_number)\n for pr in prs:\n combined = f\"{pr.get('title','')} {pr.get('body','')} {pr.get('head',{}).get('ref','')}\"\n if num_str in combined:\n return True\n return False\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0198", "domain": "pr_workflow", "prompt": "Author a defensive Python routine that Write a Python function that blocks merging if a PR does not have at least one approved review. Optimize for minimal external dependencies.", "response": "def require_approval(pr: dict, reviews: list[dict]) -> bool:\n if pr.get(\"state\") != \"open\":\n return False\n approvals = [r for r in reviews if r.get(\"state\") == \"APPROVED\"]\n return len(approvals) >= 1\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0237", "domain": "issue_automation", "prompt": "Build a reusable module function that Write a Python function that reopens a closed Gitea issue via API. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef reopen_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"state\": \"open\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0165", "domain": "pr_workflow", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that dismisses a review on a Gitea pull request. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef dismiss_review(repo: str, pr_number: int, review_id: int, token: str, message: str = \"\"):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/reviews/{review_id}/dismissals\"\n data = {\"message\": message or \"Dismissed\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0208", "domain": "gitea_api", "prompt": "Author a defensive Python routine that Write a Python function that wraps the Gitea API in a typed dataclass response (Issue, PR, Comment). Add timeout and connection cleanup.", "response": "from dataclasses import dataclass\nfrom typing import Any\n\n@dataclass\nclass Issue:\n number: int\n title: str\n state: str\n\n @classmethod\n def from_dict(cls, d: dict) -> \"Issue\":\n return cls(\n number=d.get(\"number\", 0),\n title=d.get(\"title\", \"\"),\n state=d.get(\"state\", \"\"),\n )\n\ndef parse_issues(raw: list[dict]) -> list[Issue]:\n \"\"\"Convert raw API response into typed Issue objects.\"\"\"\n return [Issue.from_dict(i) for i in raw]\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0109", "domain": "repo_management", "prompt": "Draft a minimal but complete solution that Write a Python function that clones a Gitea repo with --depth 1 for a shallow clone. Validate inputs before making API calls.", "response": "import subprocess\n\ndef shallow_clone(repo_url: str, dest: str, branch: str = \"main\"):\n \"\"\"Clone with --depth 1 to save time and space.\"\"\"\n subprocess.run(\n [\"git\", \"clone\", \"--depth\", \"1\", \"--branch\", branch, repo_url, dest],\n check=True,\n capture_output=True,\n )\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0107", "domain": "pr_workflow", "prompt": "Build a reusable module function that Write a Python function that checks whether a Gitea pull request is mergeable. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef is_mergeable(repo: str, pr_number: int, token: str) -> bool:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n data = json.loads(resp.read().decode())\n return data.get(\"mergeable\", False)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0123", "domain": "gitea_api", "prompt": "Write a robust, production-ready function that Write a Python function that builds a Gitea API search query for issues across all repos in an organization. Validate inputs before making API calls.", "response": "import urllib.request\nimport urllib.parse\n\ndef search_issues_url(org: str, query: str, state: str = \"open\") -> str:\n \"\"\"Build cross-repo issue search URL.\"\"\"\n params = urllib.parse.urlencode({\n \"q\": query,\n \"state\": state,\n \"type\": \"issues\",\n })\n return f\"/repos/search?{params}\"\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0239", "domain": "repo_management", "prompt": "Draft a minimal but complete solution that Write a Python function that forks a Gitea repo into another organization via API. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef fork_repo(repo: str, org: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/forks\"\n data = {\"organization\": org}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0231", "domain": "issue_automation", "prompt": "Write a Python function that checks whether a Gitea issue already has a bot comment to avoid duplicate comments. Surface clear exception messages on failure.", "response": "def has_bot_comment(comments: list[dict], bot_marker: str = \"🤖\") -> bool:\n return any(bot_marker in c.get(\"body\", \"\") for c in comments)\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0247", "domain": "repo_management", "prompt": "Build a reusable module function that Write a Python function that sets a repo topic (tag) via the Gitea API. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef set_repo_topic(repo: str, topic: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/topics\"\n data = {\"topics\": [topic]}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PUT\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0194", "domain": "pr_workflow", "prompt": "Create a typed Python utility that Write a Python function that auto-squashes all commits on a PR branch before merging. Optimize for minimal external dependencies.", "response": "import subprocess\n\ndef autosquash_branch(branch: str, base: str = \"main\"):\n subprocess.run([\"git\", \"checkout\", branch], check=True, capture_output=True)\n subprocess.run([\"git\", \"reset\", f\"origin/{base}\"], check=True, capture_output=True)\n subprocess.run([\"git\", \"add\", \"-A\"], check=True, capture_output=True)\n subprocess.run([\"git\", \"commit\", \"-m\", f\"feat: squash {branch}\"], check=True, capture_output=True)\n subprocess.run([\"git\", \"push\", \"--force-with-lease\", \"origin\", branch], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0040", "domain": "pr_workflow", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that dismisses a review on a Gitea pull request. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef dismiss_review(repo: str, pr_number: int, review_id: int, token: str, message: str = \"\"):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/reviews/{review_id}/dismissals\"\n data = {\"message\": message or \"Dismissed\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0033", "domain": "repo_management", "prompt": "Write a robust, production-ready function that Write a Python function that creates a milestone in a Gitea repo with a due date. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\nfrom datetime import datetime, timezone\n\ndef create_milestone(repo: str, title: str, due_date: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/milestones\"\n data = {\"title\": title, \"due_on\": due_date}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0013", "domain": "pr_workflow", "prompt": "Write a robust, production-ready function that Write a Python function that closes a pull request without merging it. Include error handling.", "response": "import urllib.request\nimport json\n\ndef close_pr(repo: str, pr_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}\"\n data = {\"state\": \"closed\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0026", "domain": "repo_management", "prompt": "Design a concise Python snippet that Write a Python function that creates a new Gitea repo under an organization via API. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef create_repo(org: str, name: str, token: str, description: str = \"\", private: bool = False):\n url = f\"https://forge.example.com/api/v1/orgs/{org}/repos\"\n data = {\"name\": name, \"description\": description, \"private\": private}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0181", "domain": "pr_workflow", "prompt": "Write a Python function that requests a specific user to review a Gitea pull request. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef request_review(repo: str, pr_number: int, reviewers: list[str], token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/requested_reviewers\"\n data = {\"reviewers\": reviewers}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0078", "domain": "gitea_api", "prompt": "Author a defensive Python routine that Write a Python function that builds a Gitea API URL with query parameters for pagination. Log all failures for observability.", "response": "import urllib.parse\n\ndef build_api_url(base_url: str, path: str, params: dict | None = None) -> str:\n \"\"\"Build a Gitea API URL with optional query params.\"\"\"\n url = f\"{base_url.rstrip('/')}/api/v1{path}\"\n if params:\n clean = {k: v for k, v in params.items() if v is not None}\n url += \"?\" + urllib.parse.urlencode(clean)\n return url\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0041", "domain": "issue_automation", "prompt": "Write a Python function that migrates issues from one Gitea repo to another by creating copies. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef migrate_issue(source_repo: str, target_repo: str, issue: dict, token: str):\n owner, name = target_repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues\"\n data = {\n \"title\": f\"[Migrated] {issue['title']}\",\n \"body\": issue.get(\"body\", \"\"),\n }\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0006", "domain": "pr_workflow", "prompt": "Design a concise Python snippet that Write a Python function that requests a specific user to review a Gitea pull request. Include error handling.", "response": "import urllib.request\nimport json\n\ndef request_review(repo: str, pr_number: int, reviewers: list[str], token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/requested_reviewers\"\n data = {\"reviewers\": reviewers}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0241", "domain": "pr_workflow", "prompt": "Write a Python function that gets the diff of a Gitea pull request as raw text. Surface clear exception messages on failure.", "response": "import urllib.request\n\ndef get_pr_diff(repo: str, pr_number: int, token: str) -> str:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}.diff\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.read().decode()\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0009", "domain": "repo_management", "prompt": "Draft a minimal but complete solution that Write a Python function that clones a Gitea repo with --depth 1 for a shallow clone. Include error handling.", "response": "import subprocess\n\ndef shallow_clone(repo_url: str, dest: str, branch: str = \"main\"):\n \"\"\"Clone with --depth 1 to save time and space.\"\"\"\n subprocess.run(\n [\"git\", \"clone\", \"--depth\", \"1\", \"--branch\", branch, repo_url, dest],\n check=True,\n capture_output=True,\n )\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0033", "domain": "gitea_api", "prompt": "Write a robust, production-ready function that Write a Python function that wraps the Gitea API in a typed dataclass response (Issue, PR, Comment). Add retry logic with exponential backoff.", "response": "from dataclasses import dataclass\nfrom typing import Any\n\n@dataclass\nclass Issue:\n number: int\n title: str\n state: str\n\n @classmethod\n def from_dict(cls, d: dict) -> \"Issue\":\n return cls(\n number=d.get(\"number\", 0),\n title=d.get(\"title\", \"\"),\n state=d.get(\"state\", \"\"),\n )\n\ndef parse_issues(raw: list[dict]) -> list[Issue]:\n \"\"\"Convert raw API response into typed Issue objects.\"\"\"\n return [Issue.from_dict(i) for i in raw]\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0162", "domain": "issue_automation", "prompt": "Using only the Python standard library, Write a Python function that reopens a closed Gitea issue via API. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef reopen_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"state\": \"open\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0160", "domain": "gitea_api", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that implements a circuit breaker for Gitea API requests after 3 consecutive failures. Include docstrings and type hints.", "response": "class CircuitBreaker:\n def __init__(self, threshold: int = 3):\n self.failures = 0\n self.threshold = threshold\n self.open = False\n\n def call(self, fn, *args, **kwargs):\n if self.open:\n raise RuntimeError(\"Circuit breaker is OPEN\")\n try:\n result = fn(*args, **kwargs)\n self.failures = 0\n return result\n except Exception:\n self.failures += 1\n if self.failures >= self.threshold:\n self.open = True\n raise\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0067", "domain": "repo_management", "prompt": "Build a reusable module function that Write a Python function that adds a deploy key to a Gitea repo for CI access. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef add_deploy_key(repo: str, title: str, key: str, token: str, read_only: bool = True):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/keys\"\n data = {\"title\": title, \"key\": key, \"read_only\": read_only}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0132", "domain": "repo_management", "prompt": "Using only the Python standard library, Write a Python function that lists all labels in a Gitea repo. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef list_labels(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/labels\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0173", "domain": "issue_automation", "prompt": "Write a robust, production-ready function that Write a Python function that removes a milestone from a Gitea issue. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef remove_milestone(repo: str, issue_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{issue_number}\"\n data = {\"milestone\": 0}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0127", "domain": "pr_workflow", "prompt": "Build a reusable module function that Write a Python function that checks if an open pull request already exists for a given issue (by scanning title/body/branch). Handle empty responses gracefully.", "response": "def issue_has_open_pr(prs: list[dict], issue_number: int) -> bool:\n num_str = str(issue_number)\n for pr in prs:\n combined = f\"{pr.get('title','')} {pr.get('body','')} {pr.get('head',{}).get('ref','')}\"\n if num_str in combined:\n return True\n return False\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0208", "domain": "issue_automation", "prompt": "Author a defensive Python routine that Write a Python function that searches Gitea issues across an organization by keyword. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef search_issues(org: str, keyword: str, token: str):\n url = f\"https://forge.example.com/api/v1/repos/search?q={keyword}&uid=0&limit=50\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0111", "domain": "issue_automation", "prompt": "Write a Python function that counts open issues per label in a Gitea repo. Validate inputs before making API calls.", "response": "from collections import Counter\n\ndef count_issues_per_label(issues: list[dict]) -> Counter:\n counts = Counter()\n for i in issues:\n for label in i.get(\"labels\", []):\n counts[label.get(\"name\", \"unknown\")] += 1\n return counts\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0124", "domain": "gitea_api", "prompt": "Create a typed Python utility that Write a Python function that attaches a custom User-Agent header to all Gitea API requests. Validate inputs before making API calls.", "response": "import urllib.request\n\ndef request_with_user_agent(url: str, token: str, agent: str = \"timmy-bot/1.0\"):\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"User-Agent\", agent)\n return req\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0054", "domain": "pr_workflow", "prompt": "Create a typed Python utility that Write a Python function that merges a Gitea pull request with retry logic for merge conflicts. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport urllib.error\nimport json\nimport time\n\ndef merge_pr(repo: str, number: int, token: str, method: str = \"squash\", retries: int = 3):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{number}/merge\"\n data = {\"Do\": method}\n for attempt in range(retries):\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n try:\n with urllib.request.urlopen(req, timeout=30) as resp:\n return True\n except urllib.error.HTTPError as e:\n if e.code == 405 and attempt < retries - 1:\n time.sleep(5)\n continue\n raise\n return False\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0233", "domain": "gitea_api", "prompt": "Write a robust, production-ready function that Write a Python function that wraps the Gitea API in a typed dataclass response (Issue, PR, Comment). Surface clear exception messages on failure.", "response": "from dataclasses import dataclass\nfrom typing import Any\n\n@dataclass\nclass Issue:\n number: int\n title: str\n state: str\n\n @classmethod\n def from_dict(cls, d: dict) -> \"Issue\":\n return cls(\n number=d.get(\"number\", 0),\n title=d.get(\"title\", \"\"),\n state=d.get(\"state\", \"\"),\n )\n\ndef parse_issues(raw: list[dict]) -> list[Issue]:\n \"\"\"Convert raw API response into typed Issue objects.\"\"\"\n return [Issue.from_dict(i) for i in raw]\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0122", "domain": "pr_workflow", "prompt": "Using only the Python standard library, Write a Python function that removes a label from a Gitea pull request. Validate inputs before making API calls.", "response": "import urllib.request\n\ndef remove_pr_label(repo: str, pr_number: int, label_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/labels/{label_id}\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0039", "domain": "issue_automation", "prompt": "Draft a minimal but complete solution that Write a Python function that detects stale issues (no activity for 30 days) in a Gitea repo. Add retry logic with exponential backoff.", "response": "from datetime import datetime, timezone\n\ndef find_stale_issues(issues: list[dict], days: int = 30) -> list[dict]:\n now = datetime.now(timezone.utc)\n stale = []\n for i in issues:\n updated = datetime.fromisoformat(i[\"updated_at\"].replace(\"Z\", \"+00:00\"))\n if (now - updated).days > days:\n stale.append(i)\n return stale\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0049", "domain": "repo_management", "prompt": "Draft a minimal but complete solution that Write a Python function that renames a branch in a Gitea repo via API. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef rename_branch(repo: str, old: str, new: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branches/{old}\"\n data = {\"name\": new}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0199", "domain": "issue_automation", "prompt": "Draft a minimal but complete solution that Write a Python function that finds issues created by a specific user in a Gitea repo. Optimize for minimal external dependencies.", "response": "def find_issues_by_author(issues: list[dict], username: str) -> list[dict]:\n return [i for i in issues if i.get(\"user\", {}).get(\"login\") == username]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0233", "domain": "issue_automation", "prompt": "Write a robust, production-ready function that Write a Python function that searches Gitea issues across an organization by keyword. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef search_issues(org: str, keyword: str, token: str):\n url = f\"https://forge.example.com/api/v1/repos/search?q={keyword}&uid=0&limit=50\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0128", "domain": "pr_workflow", "prompt": "Author a defensive Python routine that Write a Python function that lists all open pull requests for a Gitea repo. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef list_open_prs(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls?state=open&limit=100\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0089", "domain": "gitea_api", "prompt": "Draft a minimal but complete solution that Write a Python function that measures the latency of a Gitea API call and raises a warning if it exceeds 2 seconds. Log all failures for observability.", "response": "import time\nimport urllib.request\n\ndef timed_request(req: urllib.request.Request, threshold: float = 2.0):\n \"\"\"Execute request and warn if latency exceeds threshold.\"\"\"\n start = time.time()\n with urllib.request.urlopen(req, timeout=30) as resp:\n body = resp.read().decode()\n elapsed = time.time() - start\n if elapsed > threshold:\n print(f\"WARNING: Request took {elapsed:.2f}s\")\n return body\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0139", "domain": "gitea_api", "prompt": "Draft a minimal but complete solution that Write a Python function that measures the latency of a Gitea API call and raises a warning if it exceeds 2 seconds. Handle empty responses gracefully.", "response": "import time\nimport urllib.request\n\ndef timed_request(req: urllib.request.Request, threshold: float = 2.0):\n \"\"\"Execute request and warn if latency exceeds threshold.\"\"\"\n start = time.time()\n with urllib.request.urlopen(req, timeout=30) as resp:\n body = resp.read().decode()\n elapsed = time.time() - start\n if elapsed > threshold:\n print(f\"WARNING: Request took {elapsed:.2f}s\")\n return body\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0078", "domain": "issue_automation", "prompt": "Author a defensive Python routine that Write a Python function that posts a comment on a Gitea issue via API. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef comment_on_issue(repo: str, number: int, body: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/comments\"\n data = {\"body\": body}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0209", "domain": "issue_automation", "prompt": "Draft a minimal but complete solution that Write a Python function that calculates the age of a Gitea issue in days from its created_at timestamp. Add timeout and connection cleanup.", "response": "from datetime import datetime, timezone\n\ndef issue_age_days(created_at: str) -> int:\n \"\"\"Calculate age of an issue in days.\"\"\"\n fmt = \"%Y-%m-%dT%H:%M:%SZ\"\n created = datetime.strptime(created_at, fmt).replace(tzinfo=timezone.utc)\n return (datetime.now(timezone.utc) - created).days\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0155", "domain": "issue_automation", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that assigns a Gitea issue to a specific user. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef assign_issue(repo: str, number: int, assignees: list[str], token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"assignees\": assignees}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0200", "domain": "issue_automation", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that updates the title of a Gitea issue via API. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef update_issue_title(repo: str, number: int, new_title: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"title\": new_title}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0062", "domain": "pr_workflow", "prompt": "Using only the Python standard library, Write a Python function that detects destructive deletions in a PR (any file losing >50% of lines). Return typed dataclasses where appropriate.", "response": "def detect_destructive(files: list[dict], threshold: float = 0.5) -> list[str]:\n flagged = []\n for f in files:\n if f.get(\"status\") == \"modified\" and f.get(\"deletions\", 0) > 0:\n total = f.get(\"additions\", 0) + f.get(\"deletions\", 0)\n if total > 0 and f[\"deletions\"] / total > threshold:\n flagged.append(f[\"filename\"])\n return flagged\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0202", "domain": "gitea_api", "prompt": "Using only the Python standard library, Write a Python function that reads a Gitea API token from standard local paths and returns it. Add timeout and connection cleanup.", "response": "from pathlib import Path\n\ndef read_gitea_token() -> str:\n \"\"\"Read token from standard locations.\"\"\"\n for path in [\n Path.home() / \".hermes\" / \"gitea_token\",\n Path.home() / \".config\" / \"gitea\" / \"token\",\n ]:\n if path.exists():\n return path.read_text().strip()\n raise FileNotFoundError(\"No Gitea token found\")\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0188", "domain": "pr_workflow", "prompt": "Author a defensive Python routine that Write a Python function that closes a pull request without merging it. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef close_pr(repo: str, pr_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}\"\n data = {\"state\": \"closed\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0096", "domain": "repo_management", "prompt": "Design a concise Python snippet that Write a Python function that transfers a Gitea repo from one owner to another. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef transfer_repo(repo: str, new_owner: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/transfer\"\n data = {\"new_owner\": new_owner}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0145", "domain": "repo_management", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that un-archives a Gitea repo via API. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef unarchive_repo(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"archived\": False}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0066", "domain": "pr_workflow", "prompt": "Design a concise Python snippet that Write a Python function that gets the diff of a Gitea pull request as raw text. Return typed dataclasses where appropriate.", "response": "import urllib.request\n\ndef get_pr_diff(repo: str, pr_number: int, token: str) -> str:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}.diff\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.read().decode()\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0093", "domain": "gitea_api", "prompt": "Write a robust, production-ready function that Write a Python function that safely reads the response body from a Gitea API call even when the server returns an empty body. Log all failures for observability.", "response": "import urllib.request\n\ndef safe_read_response(resp: urllib.request.addinfourl) -> dict:\n \"\"\"Return parsed JSON or empty dict if body is empty.\"\"\"\n raw = resp.read().decode()\n if not raw.strip():\n return {}\n import json\n return json.loads(raw)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0015", "domain": "repo_management", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that sets branch protection rules: no force-push, require status checks. Include error handling.", "response": "import urllib.request\nimport json\n\ndef set_strict_protection(repo: str, branch: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branch_protections\"\n data = {\n \"branch_name\": branch,\n \"enable_push\": False,\n \"enable_status_check\": True,\n \"status_check_contexts\": [\"ci/tests\"],\n }\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0046", "domain": "gitea_api", "prompt": "Design a concise Python snippet that Write a Python function that retries only on 5xx and 429 errors, but fails immediately on 4xx (except 429). Add retry logic with exponential backoff.", "response": "import urllib.request\nimport urllib.error\nimport time\n\ndef smart_retry(req: urllib.request.Request, retries: int = 3):\n \"\"\"Retry on 5xx and 429; fail fast on other 4xx.\"\"\"\n for attempt in range(retries):\n try:\n return urllib.request.urlopen(req, timeout=30)\n except urllib.error.HTTPError as e:\n if e.code == 429 or e.code >= 500:\n if attempt == retries - 1:\n raise\n time.sleep(2 ** attempt)\n else:\n raise\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0026", "domain": "pr_workflow", "prompt": "Design a concise Python snippet that Write a Python function that creates a pull request on Gitea via API. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef create_pull_request(repo: str, title: str, head: str, base: str, body: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls\"\n data = {\"title\": title, \"head\": head, \"base\": base, \"body\": body}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0155", "domain": "repo_management", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that protects a branch in Gitea by requiring PR reviews before merge. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef protect_branch(repo: str, branch: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branch_protections\"\n data = {\"branch_name\": branch, \"enable_push\": False, \"enable_push_whitelist\": False}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0203", "domain": "issue_automation", "prompt": "Write a robust, production-ready function that Write a Python function that posts a comment on a Gitea issue via API. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef comment_on_issue(repo: str, number: int, body: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/comments\"\n data = {\"body\": body}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0150", "domain": "gitea_api", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that closes idle Gitea API connections after 30 seconds to prevent socket exhaustion. Handle empty responses gracefully.", "response": "import urllib.request\nimport socket\n\nclass TimeoutHTTPHandler(urllib.request.HTTPHandler):\n def __init__(self, timeout: int = 30):\n self.timeout = timeout\n super().__init__()\n\n def http_open(self, req):\n return self.do_open(lambda host, port: http.client.HTTPConnection(host, port, timeout=self.timeout), req)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0175", "domain": "issue_automation", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that updates the title of a Gitea issue via API. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef update_issue_title(repo: str, number: int, new_title: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"title\": new_title}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0147", "domain": "gitea_api", "prompt": "Build a reusable module function that Write a Python function that parses a Gitea API error response and extracts the human-readable message. Handle empty responses gracefully.", "response": "import json\nimport urllib.error\n\ndef parse_error_body(e: urllib.error.HTTPError) -> str:\n \"\"\"Extract human-readable message from Gitea error response.\"\"\"\n try:\n body = json.loads(e.read().decode())\n return body.get(\"message\", str(e))\n except Exception:\n return str(e)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0071", "domain": "gitea_api", "prompt": "Write a Python function that retries only on 5xx and 429 errors, but fails immediately on 4xx (except 429). Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport urllib.error\nimport time\n\ndef smart_retry(req: urllib.request.Request, retries: int = 3):\n \"\"\"Retry on 5xx and 429; fail fast on other 4xx.\"\"\"\n for attempt in range(retries):\n try:\n return urllib.request.urlopen(req, timeout=30)\n except urllib.error.HTTPError as e:\n if e.code == 429 or e.code >= 500:\n if attempt == retries - 1:\n raise\n time.sleep(2 ** attempt)\n else:\n raise\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0147", "domain": "pr_workflow", "prompt": "Build a reusable module function that Write a Python function that removes a label from a Gitea pull request. Handle empty responses gracefully.", "response": "import urllib.request\n\ndef remove_pr_label(repo: str, pr_number: int, label_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/labels/{label_id}\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0134", "domain": "repo_management", "prompt": "Create a typed Python utility that Write a Python function that clones a Gitea repo with --depth 1 for a shallow clone. Handle empty responses gracefully.", "response": "import subprocess\n\ndef shallow_clone(repo_url: str, dest: str, branch: str = \"main\"):\n \"\"\"Clone with --depth 1 to save time and space.\"\"\"\n subprocess.run(\n [\"git\", \"clone\", \"--depth\", \"1\", \"--branch\", branch, repo_url, dest],\n check=True,\n capture_output=True,\n )\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0062", "domain": "gitea_api", "prompt": "Using only the Python standard library, Write a Python function that validates a Gitea API token by calling the /user endpoint. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef validate_token(base_url: str, token: str) -> bool:\n \"\"\"Verify a token by calling the /user endpoint.\"\"\"\n req = urllib.request.Request(f\"{base_url}/api/v1/user\")\n req.add_header(\"Authorization\", f\"token {token}\")\n try:\n with urllib.request.urlopen(req, timeout=10) as resp:\n data = json.loads(resp.read().decode())\n return \"login\" in data\n except urllib.error.HTTPError as e:\n if e.code == 401:\n return False\n raise\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0156", "domain": "gitea_api", "prompt": "Design a concise Python snippet that Write a Python function that iterates through all pages of a paginated Gitea API endpoint. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef paginate_all(url_template: str, token: str, params: dict, limit: int = 50):\n \"\"\"Iterate all pages of a paginated Gitea endpoint.\"\"\"\n page = 1\n while True:\n params[\"page\"] = page\n params[\"limit\"] = limit\n req = urllib.request.Request(url_template + \"?\" + urllib.parse.urlencode(params))\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n batch = json.loads(resp.read().decode())\n if not batch:\n break\n yield from batch\n if len(batch) < limit:\n break\n page += 1\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0105", "domain": "repo_management", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that protects a branch in Gitea by requiring PR reviews before merge. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef protect_branch(repo: str, branch: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branch_protections\"\n data = {\"branch_name\": branch, \"enable_push\": False, \"enable_push_whitelist\": False}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0102", "domain": "pr_workflow", "prompt": "Using only the Python standard library, Write a Python function that checks if an open pull request already exists for a given issue (by scanning title/body/branch). Validate inputs before making API calls.", "response": "def issue_has_open_pr(prs: list[dict], issue_number: int) -> bool:\n num_str = str(issue_number)\n for pr in prs:\n combined = f\"{pr.get('title','')} {pr.get('body','')} {pr.get('head',{}).get('ref','')}\"\n if num_str in combined:\n return True\n return False\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0114", "domain": "gitea_api", "prompt": "Create a typed Python utility that Write a Python function that measures the latency of a Gitea API call and raises a warning if it exceeds 2 seconds. Validate inputs before making API calls.", "response": "import time\nimport urllib.request\n\ndef timed_request(req: urllib.request.Request, threshold: float = 2.0):\n \"\"\"Execute request and warn if latency exceeds threshold.\"\"\"\n start = time.time()\n with urllib.request.urlopen(req, timeout=30) as resp:\n body = resp.read().decode()\n elapsed = time.time() - start\n if elapsed > threshold:\n print(f\"WARNING: Request took {elapsed:.2f}s\")\n return body\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0116", "domain": "issue_automation", "prompt": "Design a concise Python snippet that Write a Python function that migrates issues from one Gitea repo to another by creating copies. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef migrate_issue(source_repo: str, target_repo: str, issue: dict, token: str):\n owner, name = target_repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues\"\n data = {\n \"title\": f\"[Migrated] {issue['title']}\",\n \"body\": issue.get(\"body\", \"\"),\n }\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0120", "domain": "pr_workflow", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that generates a release notes draft from merged PRs since the last tag. Validate inputs before making API calls.", "response": "def generate_release_notes(merged_prs: list[dict], tag: str) -> str:\n lines = [f\"## Release {tag}\", \"\"]\n for pr in merged_prs:\n lines.append(f\"- #{pr['number']} {pr['title']}\")\n return \"\n\".join(lines)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0231", "domain": "gitea_api", "prompt": "Write a Python function that iterates through all pages of a paginated Gitea API endpoint. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef paginate_all(url_template: str, token: str, params: dict, limit: int = 50):\n \"\"\"Iterate all pages of a paginated Gitea endpoint.\"\"\"\n page = 1\n while True:\n params[\"page\"] = page\n params[\"limit\"] = limit\n req = urllib.request.Request(url_template + \"?\" + urllib.parse.urlencode(params))\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n batch = json.loads(resp.read().decode())\n if not batch:\n break\n yield from batch\n if len(batch) < limit:\n break\n page += 1\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0208", "domain": "repo_management", "prompt": "Author a defensive Python routine that Write a Python function that creates a milestone in a Gitea repo with a due date. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\nfrom datetime import datetime, timezone\n\ndef create_milestone(repo: str, title: str, due_date: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/milestones\"\n data = {\"title\": title, \"due_on\": due_date}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0118", "domain": "pr_workflow", "prompt": "Author a defensive Python routine that Write a Python function that checks if a PR branch is behind the base branch and needs rebasing. Validate inputs before making API calls.", "response": "import subprocess\n\ndef is_behind(base: str, feature: str) -> bool:\n result = subprocess.run(\n [\"git\", \"merge-base\", f\"origin/{base}\", feature],\n capture_output=True, text=True, check=True,\n )\n merge_base = result.stdout.strip()\n result2 = subprocess.run(\n [\"git\", \"rev-parse\", f\"origin/{base}\"],\n capture_output=True, text=True, check=True,\n )\n return merge_base != result2.stdout.strip()\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0186", "domain": "pr_workflow", "prompt": "Design a concise Python snippet that Write a Python function that calculates the net line change (additions - deletions) across all files in a PR. Optimize for minimal external dependencies.", "response": "def net_line_change(files: list[dict]) -> int:\n return sum(f.get(\"additions\", 0) - f.get(\"deletions\", 0) for f in files)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0081", "domain": "gitea_api", "prompt": "Write a Python function that iterates through all pages of a paginated Gitea API endpoint. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef paginate_all(url_template: str, token: str, params: dict, limit: int = 50):\n \"\"\"Iterate all pages of a paginated Gitea endpoint.\"\"\"\n page = 1\n while True:\n params[\"page\"] = page\n params[\"limit\"] = limit\n req = urllib.request.Request(url_template + \"?\" + urllib.parse.urlencode(params))\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n batch = json.loads(resp.read().decode())\n if not batch:\n break\n yield from batch\n if len(batch) < limit:\n break\n page += 1\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0151", "domain": "gitea_api", "prompt": "Write a Python function that pings a Gitea instance to check if it is alive. Include docstrings and type hints.", "response": "import urllib.request\nimport urllib.error\nimport json\n\ndef ping_gitea(base_url: str) -> bool:\n \"\"\"Check if Gitea is responding.\"\"\"\n try:\n req = urllib.request.Request(f\"{base_url}/api/v1/version\")\n with urllib.request.urlopen(req, timeout=5) as resp:\n return resp.status == 200\n except Exception:\n return False\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0098", "domain": "pr_workflow", "prompt": "Author a defensive Python routine that Write a Python function that blocks merging if a PR does not have at least one approved review. Log all failures for observability.", "response": "def require_approval(pr: dict, reviews: list[dict]) -> bool:\n if pr.get(\"state\") != \"open\":\n return False\n approvals = [r for r in reviews if r.get(\"state\") == \"APPROVED\"]\n return len(approvals) >= 1\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0173", "domain": "pr_workflow", "prompt": "Write a robust, production-ready function that Write a Python function that blocks merging if a PR does not have at least one approved review. Include docstrings and type hints.", "response": "def require_approval(pr: dict, reviews: list[dict]) -> bool:\n if pr.get(\"state\") != \"open\":\n return False\n approvals = [r for r in reviews if r.get(\"state\") == \"APPROVED\"]\n return len(approvals) >= 1\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0034", "domain": "issue_automation", "prompt": "Create a typed Python utility that Write a Python function that calculates the age of a Gitea issue in days from its created_at timestamp. Add retry logic with exponential backoff.", "response": "from datetime import datetime, timezone\n\ndef issue_age_days(created_at: str) -> int:\n \"\"\"Calculate age of an issue in days.\"\"\"\n fmt = \"%Y-%m-%dT%H:%M:%SZ\"\n created = datetime.strptime(created_at, fmt).replace(tzinfo=timezone.utc)\n return (datetime.now(timezone.utc) - created).days\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0163", "domain": "issue_automation", "prompt": "Write a robust, production-ready function that Write a Python function that fetches the full timeline (comments) of a Gitea issue. Include docstrings and type hints.", "response": "import urllib.request\nimport json\n\ndef get_issue_timeline(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/comments\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0205", "domain": "repo_management", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that protects a branch in Gitea by requiring PR reviews before merge. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef protect_branch(repo: str, branch: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branch_protections\"\n data = {\"branch_name\": branch, \"enable_push\": False, \"enable_push_whitelist\": False}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0004", "domain": "pr_workflow", "prompt": "Create a typed Python utility that Write a Python function that merges a Gitea pull request with retry logic for merge conflicts. Include error handling.", "response": "import urllib.request\nimport urllib.error\nimport json\nimport time\n\ndef merge_pr(repo: str, number: int, token: str, method: str = \"squash\", retries: int = 3):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{number}/merge\"\n data = {\"Do\": method}\n for attempt in range(retries):\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n try:\n with urllib.request.urlopen(req, timeout=30) as resp:\n return True\n except urllib.error.HTTPError as e:\n if e.code == 405 and attempt < retries - 1:\n time.sleep(5)\n continue\n raise\n return False\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0067", "domain": "pr_workflow", "prompt": "Build a reusable module function that Write a Python function that triggers a CI pipeline by pushing an empty commit on a PR branch. Return typed dataclasses where appropriate.", "response": "import subprocess\n\ndef trigger_ci(repo_url: str, branch: str):\n subprocess.run(\n [\"git\", \"commit\", \"--allow-empty\", \"-m\", \"ci: trigger pipeline\"],\n check=True, capture_output=True,\n )\n subprocess.run([\"git\", \"push\", repo_url, branch], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0062", "domain": "issue_automation", "prompt": "Using only the Python standard library, Write a Python function that reopens a closed Gitea issue via API. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef reopen_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"state\": \"open\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0242", "domain": "gitea_api", "prompt": "Using only the Python standard library, Write a Python function that serializes a Python dict into JSON and sends it as the body of a PATCH request to Gitea. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef gitea_patch(base_url: str, path: str, token: str, data: dict):\n \"\"\"Serialize dict to JSON and PATCH.\"\"\"\n url = f\"{base_url.rstrip('/')}/api/v1{path}\"\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0026", "domain": "gitea_api", "prompt": "Design a concise Python snippet that Write a Python function that pings a Gitea instance to check if it is alive. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport urllib.error\nimport json\n\ndef ping_gitea(base_url: str) -> bool:\n \"\"\"Check if Gitea is responding.\"\"\"\n try:\n req = urllib.request.Request(f\"{base_url}/api/v1/version\")\n with urllib.request.urlopen(req, timeout=5) as resp:\n return resp.status == 200\n except Exception:\n return False\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0053", "domain": "repo_management", "prompt": "Write a robust, production-ready function that Write a Python function that sets a webhook on a Gitea repo to trigger on push events. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef set_push_webhook(repo: str, token: str, webhook_url: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/hooks\"\n data = {\n \"type\": \"gitea\",\n \"config\": {\"url\": webhook_url, \"content_type\": \"json\"},\n \"events\": [\"push\"],\n \"active\": True,\n }\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0129", "domain": "repo_management", "prompt": "Draft a minimal but complete solution that Write a Python function that lists all branches in a Gitea repo. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef list_branches(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branches\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0121", "domain": "repo_management", "prompt": "Write a Python function that transfers a Gitea repo from one owner to another. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef transfer_repo(repo: str, new_owner: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/transfer\"\n data = {\"new_owner\": new_owner}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0138", "domain": "issue_automation", "prompt": "Author a defensive Python routine that Write a Python function that fetches the full timeline (comments) of a Gitea issue. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef get_issue_timeline(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}/comments\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0072", "domain": "issue_automation", "prompt": "Using only the Python standard library, Write a Python function that sets a milestone on a Gitea issue. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef set_milestone(repo: str, issue_number: int, milestone_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{issue_number}\"\n data = {\"milestone\": milestone_id}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0079", "domain": "gitea_api", "prompt": "Draft a minimal but complete solution that Write a Python function that makes an authenticated GET request to the Gitea API with retries and exponential backoff. Log all failures for observability.", "response": "import urllib.request\nimport urllib.error\nimport json\nimport time\n\ndef gitea_get_with_retries(url: str, token: str, retries: int = 3, backoff: float = 1.5):\n \"\"\"Authenticated GET with exponential backoff.\"\"\"\n for attempt in range(retries):\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n try:\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n except urllib.error.HTTPError as e:\n if 400 <= e.code < 500 and e.code != 429:\n raise\n if attempt == retries - 1:\n raise\n except urllib.error.URLError:\n if attempt == retries - 1:\n raise\n time.sleep(backoff ** attempt)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0081", "domain": "issue_automation", "prompt": "Write a Python function that checks whether a Gitea issue already has a bot comment to avoid duplicate comments. Log all failures for observability.", "response": "def has_bot_comment(comments: list[dict], bot_marker: str = \"🤖\") -> bool:\n return any(bot_marker in c.get(\"body\", \"\") for c in comments)\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0100", "domain": "issue_automation", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that updates the title of a Gitea issue via API. Log all failures for observability.", "response": "import urllib.request\nimport json\n\ndef update_issue_title(repo: str, number: int, new_title: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"title\": new_title}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0199", "domain": "repo_management", "prompt": "Draft a minimal but complete solution that Write a Python function that renames a branch in a Gitea repo via API. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport json\n\ndef rename_branch(repo: str, old: str, new: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/branches/{old}\"\n data = {\"name\": new}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0222", "domain": "pr_workflow", "prompt": "Using only the Python standard library, Write a Python function that removes a label from a Gitea pull request. Add timeout and connection cleanup.", "response": "import urllib.request\n\ndef remove_pr_label(repo: str, pr_number: int, label_id: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/labels/{label_id}\"\n req = urllib.request.Request(url, method=\"DELETE\")\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.status == 204\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0014", "domain": "pr_workflow", "prompt": "Create a typed Python utility that Write a Python function that approves a Gitea pull request via API. Include error handling.", "response": "import urllib.request\nimport json\n\ndef approve_pr(repo: str, pr_number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/reviews\"\n data = {\"body\": \"LGTM\", \"event\": \"APPROVE\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0056", "domain": "pr_workflow", "prompt": "Design a concise Python snippet that Write a Python function that requests a specific user to review a Gitea pull request. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef request_review(repo: str, pr_number: int, reviewers: list[str], token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/requested_reviewers\"\n data = {\"reviewers\": reviewers}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0103", "domain": "pr_workflow", "prompt": "Write a robust, production-ready function that Write a Python function that lists all open pull requests for a Gitea repo. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef list_open_prs(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls?state=open&limit=100\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0086", "domain": "pr_workflow", "prompt": "Design a concise Python snippet that Write a Python function that calculates the net line change (additions - deletions) across all files in a PR. Log all failures for observability.", "response": "def net_line_change(files: list[dict]) -> int:\n return sum(f.get(\"additions\", 0) - f.get(\"deletions\", 0) for f in files)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0209", "domain": "repo_management", "prompt": "Draft a minimal but complete solution that Write a Python function that clones a Gitea repo with --depth 1 for a shallow clone. Add timeout and connection cleanup.", "response": "import subprocess\n\ndef shallow_clone(repo_url: str, dest: str, branch: str = \"main\"):\n \"\"\"Clone with --depth 1 to save time and space.\"\"\"\n subprocess.run(\n [\"git\", \"clone\", \"--depth\", \"1\", \"--branch\", branch, repo_url, dest],\n check=True,\n capture_output=True,\n )\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0179", "domain": "pr_workflow", "prompt": "Draft a minimal but complete solution that Write a Python function that merges a Gitea pull request with retry logic for merge conflicts. Optimize for minimal external dependencies.", "response": "import urllib.request\nimport urllib.error\nimport json\nimport time\n\ndef merge_pr(repo: str, number: int, token: str, method: str = \"squash\", retries: int = 3):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{number}/merge\"\n data = {\"Do\": method}\n for attempt in range(retries):\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n try:\n with urllib.request.urlopen(req, timeout=30) as resp:\n return True\n except urllib.error.HTTPError as e:\n if e.code == 405 and attempt < retries - 1:\n time.sleep(5)\n continue\n raise\n return False\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0055", "domain": "pr_workflow", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that posts a review comment on a Gitea pull request. Return typed dataclasses where appropriate.", "response": "import urllib.request\nimport json\n\ndef review_comment(repo: str, pr_number: int, body: str, token: str, path: str = \"\", position: int = 0):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}/reviews\"\n data = {\"body\": body, \"event\": \"COMMENT\"}\n if path:\n data[\"comments\"] = [{\"path\": path, \"position\": position, \"body\": body}]\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0043", "domain": "repo_management", "prompt": "Write a robust, production-ready function that Write a Python function that enables issue tracking on a Gitea repo via API. Add retry logic with exponential backoff.", "response": "import urllib.request\nimport json\n\ndef enable_issues(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}\"\n data = {\"has_issues\": True}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0150", "domain": "repo_management", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that syncs a fork with its upstream parent repo via Gitea API. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef sync_fork(repo: str, token: str, branch: str = \"main\"):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls\"\n data = {\"title\": \"Sync upstream\", \"head\": f\"upstream:{branch}\", \"base\": branch, \"body\": \"Automated sync\"}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0058", "domain": "gitea_api", "prompt": "Author a defensive Python routine that Write a Python function that wraps the Gitea API in a typed dataclass response (Issue, PR, Comment). Return typed dataclasses where appropriate.", "response": "from dataclasses import dataclass\nfrom typing import Any\n\n@dataclass\nclass Issue:\n number: int\n title: str\n state: str\n\n @classmethod\n def from_dict(cls, d: dict) -> \"Issue\":\n return cls(\n number=d.get(\"number\", 0),\n title=d.get(\"title\", \"\"),\n state=d.get(\"state\", \"\"),\n )\n\ndef parse_issues(raw: list[dict]) -> list[Issue]:\n \"\"\"Convert raw API response into typed Issue objects.\"\"\"\n return [Issue.from_dict(i) for i in raw]\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0110", "domain": "issue_automation", "prompt": "Engineer a fault-tolerant Python method that Write a Python function that finds all unassigned open issues in a Gitea repo. Validate inputs before making API calls.", "response": "import urllib.request\nimport json\n\ndef find_unassigned_issues(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues?state=open&type=issues&limit=100\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n issues = json.loads(resp.read().decode())\n return [i for i in issues if not i.get(\"assignee\") and not i.get(\"pull_request\")]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0012", "domain": "issue_automation", "prompt": "Using only the Python standard library, Write a Python function that reopens a closed Gitea issue via API. Include error handling.", "response": "import urllib.request\nimport json\n\ndef reopen_issue(repo: str, number: int, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/issues/{number}\"\n data = {\"state\": \"open\"}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"PATCH\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0246", "domain": "repo_management", "prompt": "Design a concise Python snippet that Write a Python function that transfers a Gitea repo from one owner to another. Surface clear exception messages on failure.", "response": "import urllib.request\nimport json\n\ndef transfer_repo(repo: str, new_owner: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/transfer\"\n data = {\"new_owner\": new_owner}\n body = json.dumps(data).encode()\n req = urllib.request.Request(url, data=body, method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0225", "domain": "pr_workflow", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that cherry-picks a commit from one branch to another via Gitea API. Add timeout and connection cleanup.", "response": "import urllib.request\nimport json\n\ndef cherry_pick_commit(repo: str, commit_sha: str, target_branch: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/git/commits\"\n data = {\"message\": f\"cherry-pick {commit_sha}\", \"parents\": [target_branch], \"tree\": commit_sha}\n req = urllib.request.Request(url, data=json.dumps(data).encode(), method=\"POST\")\n req.add_header(\"Authorization\", f\"token {token}\")\n req.add_header(\"Content-Type\", \"application/json\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0125", "domain": "gitea_api", "prompt": "Implement a sovereign, zero-dependency helper that Write a Python function that closes idle Gitea API connections after 30 seconds to prevent socket exhaustion. Validate inputs before making API calls.", "response": "import urllib.request\nimport socket\n\nclass TimeoutHTTPHandler(urllib.request.HTTPHandler):\n def __init__(self, timeout: int = 30):\n self.timeout = timeout\n super().__init__()\n\n def http_open(self, req):\n return self.do_open(lambda host, port: http.client.HTTPConnection(host, port, timeout=self.timeout), req)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "repo_management_0141", "domain": "repo_management", "prompt": "Write a Python function that lists all collaborators on a Gitea repo. Handle empty responses gracefully.", "response": "import urllib.request\nimport json\n\ndef list_collaborators(repo: str, token: str):\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/collaborators\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n", "task_type": "code_pattern", "tags": ["repo_management", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0216", "domain": "pr_workflow", "prompt": "Design a concise Python snippet that Write a Python function that gets the diff of a Gitea pull request as raw text. Add timeout and connection cleanup.", "response": "import urllib.request\n\ndef get_pr_diff(repo: str, pr_number: int, token: str) -> str:\n owner, name = repo.split(\"/\")\n url = f\"https://forge.example.com/api/v1/repos/{owner}/{name}/pulls/{pr_number}.diff\"\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n with urllib.request.urlopen(req, timeout=30) as resp:\n return resp.read().decode()\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0072", "domain": "gitea_api", "prompt": "Using only the Python standard library, Write a Python function that parses a Gitea API error response and extracts the human-readable message. Return typed dataclasses where appropriate.", "response": "import json\nimport urllib.error\n\ndef parse_error_body(e: urllib.error.HTTPError) -> str:\n \"\"\"Extract human-readable message from Gitea error response.\"\"\"\n try:\n body = json.loads(e.read().decode())\n return body.get(\"message\", str(e))\n except Exception:\n return str(e)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "gitea_api_0129", "domain": "gitea_api", "prompt": "Draft a minimal but complete solution that Write a Python function that makes an authenticated GET request to the Gitea API with retries and exponential backoff. Handle empty responses gracefully.", "response": "import urllib.request\nimport urllib.error\nimport json\nimport time\n\ndef gitea_get_with_retries(url: str, token: str, retries: int = 3, backoff: float = 1.5):\n \"\"\"Authenticated GET with exponential backoff.\"\"\"\n for attempt in range(retries):\n req = urllib.request.Request(url)\n req.add_header(\"Authorization\", f\"token {token}\")\n try:\n with urllib.request.urlopen(req, timeout=30) as resp:\n return json.loads(resp.read().decode())\n except urllib.error.HTTPError as e:\n if 400 <= e.code < 500 and e.code != 429:\n raise\n if attempt == retries - 1:\n raise\n except urllib.error.URLError:\n if attempt == retries - 1:\n raise\n time.sleep(backoff ** attempt)\n", "task_type": "code_pattern", "tags": ["gitea_api", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0187", "domain": "pr_workflow", "prompt": "Build a reusable module function that Write a Python function that detects destructive deletions in a PR (any file losing >50% of lines). Optimize for minimal external dependencies.", "response": "def detect_destructive(files: list[dict], threshold: float = 0.5) -> list[str]:\n flagged = []\n for f in files:\n if f.get(\"status\") == \"modified\" and f.get(\"deletions\", 0) > 0:\n total = f.get(\"additions\", 0) + f.get(\"deletions\", 0)\n if total > 0 and f[\"deletions\"] / total > threshold:\n flagged.append(f[\"filename\"])\n return flagged\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "issue_automation_0024", "domain": "issue_automation", "prompt": "Create a typed Python utility that Write a Python function that finds issues created by a specific user in a Gitea repo. Include error handling.", "response": "def find_issues_by_author(issues: list[dict], username: str) -> list[dict]:\n return [i for i in issues if i.get(\"user\", {}).get(\"login\") == username]\n", "task_type": "code_pattern", "tags": ["issue_automation", "gitea", "forge", "python", "api"], "source_issue": 591}
{"id": "pr_workflow_0133", "domain": "pr_workflow", "prompt": "Write a robust, production-ready function that Write a Python function that rebases a feature branch onto the base branch before opening a PR. Handle empty responses gracefully.", "response": "import subprocess\n\ndef rebase_branch(feature: str, base: str = \"main\"):\n subprocess.run([\"git\", \"checkout\", feature], check=True, capture_output=True)\n subprocess.run([\"git\", \"fetch\", \"origin\", base], check=True, capture_output=True)\n subprocess.run([\"git\", \"rebase\", f\"origin/{base}\"], check=True, capture_output=True)\n", "task_type": "code_pattern", "tags": ["pr_workflow", "gitea", "forge", "python", "api"], "source_issue": 591}