#!/usr/bin/env python3 """Create a label set on a Gitea repo and apply labels to issues. Auth follows the project convention: credentials are pulled from the macOS keychain via `git credential fill` (HTTPS), then sent as Basic auth. Modes (default = create labels then apply the one-off MAPPING, preserving the original behavior): ./manage_labels.py # create labels + apply MAPPING ./manage_labels.py --create-labels # idempotent label creation only ./manage_labels.py --apply-mapping # one-off MAPPING labeling only ./manage_labels.py --add-label 42 chore # add one label to one issue ./manage_labels.py --dry ... # print actions without writing """ import os import sys # Auto-execute using the project's local virtual environment Python PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__)) venv_python = os.path.join(PROJECT_ROOT, "venv", "bin", "python3") if os.path.exists(venv_python) and sys.executable != venv_python: os.execv(venv_python, [venv_python] + sys.argv) from gitea_auth import get_auth_header, api_request, repo_api_url HOST = "gitea.dadeschools.net" ORG = "Contractor" REPO = "Timesheet" # Mirror of the eAgenda label set (i18n omitted as irrelevant to Timesheet). LABELS = [ {"name": "chore", "color": "5319e7", "description": ""}, {"name": "critical", "color": "b60205", "description": ""}, {"name": "epic", "color": "8250df", "description": ""}, {"name": "important", "color": "fbca04", "description": ""}, {"name": "nice-to-have", "color": "0e8a16", "description": ""}, {"name": "status:in-progress", "color": "fefe2e", "description": "Issue is being worked on"}, ] # issue number -> label names to apply (one-off backfill) MAPPING = { 23: ["chore"], 22: ["chore"], 21: ["chore"], 20: ["chore", "status:in-progress"], 19: ["chore"], 18: ["chore"], 17: ["important"], 14: ["nice-to-have"], 13: ["nice-to-have"], 12: ["important"], 11: ["important"], 8: ["nice-to-have"], 7: ["nice-to-have"], 3: ["important"], 2: ["important"], 1: ["nice-to-have"], } BASE_URL = repo_api_url(HOST, ORG, REPO) USAGE = ( "usage: manage_labels.py [--dry] " "[--create-labels | --apply-mapping | --add-label