ia_dev/gitea-issues/list-pending-spooler.sh
2026-03-16 16:33:52 +01:00

32 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# List .pending files in projects/<id>/data/issues/ with status "pending" (one file per message; status updated in place).
# Run from repo root. If PROJECT_SLUG is set (from MAIL_TO or AI_AGENT_TOKEN), list that project only; else list all projects.
# Output: one path per line.
# Usage: ./ia_dev/gitea-issues/list-pending-spooler.sh
set -euo pipefail
GITEA_ISSUES_DIR="${GITEA_ISSUES_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)}"
ROOT="$(cd "${GITEA_ISSUES_DIR}/../.." && pwd)"
export GITEA_ISSUES_DIR
cd "$ROOT"
# shellcheck source=lib.sh
source "${GITEA_ISSUES_DIR}/lib.sh" 2>/dev/null || true
if [[ -n "${DATA_ISSUES_DIR:-}" && -d "${DATA_ISSUES_DIR}" ]]; then
SPOOLS=("${DATA_ISSUES_DIR}")
else
# No project from MAIL_TO/AI_AGENT_TOKEN: list pending from all projects
SPOOLS=()
for spool in "${GITEA_ISSUES_DIR}/../projects/"*/data/issues; do
[[ -d "$spool" ]] || continue
SPOOLS+=("$spool")
done
fi
for SPOOL in "${SPOOLS[@]}"; do
for f in "${SPOOL}"/*.pending; do
[[ -f "$f" ]] || continue
status="$(jq -r '.status // "pending"' "$f" 2>/dev/null)"
if [[ "$status" != "responded" ]]; then
echo "$f"
fi
done
done