#!/usr/bin/env bash # Claim or release a Gitea issue by toggling the `status:in-progress` label, so # parallel agents/LLMs don't pick up the same issue. # # Usage: # ./mark_issue.sh # claim (adds status:in-progress) # ./mark_issue.sh start # claim # ./mark_issue.sh done # release (removes the label) # # Auth: macOS keychain via `git credential fill` (same as the other scripts). set -euo pipefail HOST="gitea.dadeschools.net" API="https://$HOST/api/v1" ORG="Contractor" REPO="Timesheet" LABEL="status:in-progress" NUM="${1:?usage: mark_issue.sh [start|done]}" ACTION="${2:-start}" CREDS=$(printf "host=%s\nprotocol=https\n\n" "$HOST" | git credential fill) USER=$(printf '%s\n' "$CREDS" | sed -n 's/^username=//p') PASS=$(printf '%s\n' "$CREDS" | sed -n 's/^password=//p') AUTH=(-u "$USER:$PASS") # Resolve the label name -> id (Gitea's issue label endpoints take ids). LID=$(curl -sSL "${AUTH[@]}" "$API/repos/$ORG/$REPO/labels?limit=100" \ | python3 -c "import sys,json;print(next((l['id'] for l in json.load(sys.stdin) if l['name']=='$LABEL'),''))") if [ -z "$LID" ]; then echo "Label '$LABEL' not found in $ORG/$REPO -- run manage_labels.py first." >&2 exit 1 fi case "$ACTION" in start) curl -sSL -X POST "${AUTH[@]}" -H "Content-Type: application/json" \ -d "{\"labels\":[$LID]}" "$API/repos/$ORG/$REPO/issues/$NUM/labels" >/dev/null echo "#$NUM claimed -> $LABEL" ;; done) curl -sSL -X DELETE "${AUTH[@]}" \ "$API/repos/$ORG/$REPO/issues/$NUM/labels/$LID" >/dev/null echo "#$NUM released -> $LABEL removed" ;; *) echo "Unknown action '$ACTION' (expected: start | done)" >&2 exit 1 ;; esac