68 lines
2.0 KiB
Python
Executable File
68 lines
2.0 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Claim or release a Gitea issue by toggling status:in-progress label.
|
|
|
|
Usage:
|
|
mark_issue.py <issue_number> [start|done]
|
|
mark_issue.py --remote prgs 12 done
|
|
"""
|
|
import sys
|
|
import argparse
|
|
|
|
from gitea_auth import (
|
|
get_auth_header, resolve_remote, add_remote_args,
|
|
api_request, repo_api_url,
|
|
)
|
|
|
|
LABEL_NAME = "status:in-progress"
|
|
|
|
|
|
def main(argv=None):
|
|
parser = argparse.ArgumentParser(
|
|
description="Claim or release a Gitea issue by toggling the status:in-progress label."
|
|
)
|
|
add_remote_args(parser)
|
|
parser.add_argument("issue_number", type=int, help="Issue number.")
|
|
parser.add_argument(
|
|
"action", nargs="?", choices=["start", "done"], default="start",
|
|
help="Action: 'start' to claim (default) or 'done' to release."
|
|
)
|
|
args = parser.parse_args(argv)
|
|
|
|
host, org, repo = resolve_remote(args)
|
|
|
|
auth = get_auth_header(host)
|
|
if not auth:
|
|
print(f"Could not get credentials or token for {host}.", file=sys.stderr)
|
|
return 1
|
|
|
|
base = repo_api_url(host, org, repo)
|
|
|
|
try:
|
|
# Find the label ID
|
|
labels = api_request("GET", f"{base}/labels?limit=100", auth)
|
|
label_id = None
|
|
for lb in labels:
|
|
if lb["name"] == LABEL_NAME:
|
|
label_id = lb["id"]
|
|
break
|
|
|
|
if label_id is None:
|
|
print(f"Label '{LABEL_NAME}' not found in {org}/{repo} -- run manage_labels.py first.", file=sys.stderr)
|
|
return 1
|
|
|
|
if args.action == "start":
|
|
api_request("POST", f"{base}/issues/{args.issue_number}/labels", auth,
|
|
{"labels": [label_id]})
|
|
print(f"#{args.issue_number} claimed -> {LABEL_NAME}")
|
|
else:
|
|
api_request("DELETE", f"{base}/issues/{args.issue_number}/labels/{label_id}", auth)
|
|
print(f"#{args.issue_number} released -> {LABEL_NAME} removed")
|
|
return 0
|
|
except RuntimeError as e:
|
|
print(f"Error: {e}", file=sys.stderr)
|
|
return 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|