#!/usr/bin/env bash
set -Eeuo pipefail

root=$(cd "$(dirname "$0")/../.." && pwd -P)
fixture=$(mktemp -d)
trap 'rm -rf -- "$fixture"' EXIT

mkdir -p "$fixture/repo/.github/workflows" "$fixture/repo/tests"
git -C "$fixture/repo" init -q
git -C "$fixture/repo" config user.name test
git -C "$fixture/repo" config user.email test@example.invalid
printf '[project]\nname="sample"\n' >"$fixture/repo/pyproject.toml"
printf 'def test_ok():\n    assert True\n' >"$fixture/repo/tests/test_ok.py"
printf 'name: test\n' >"$fixture/repo/.github/workflows/test.yml"
printf 'not-a-secret\n' >"$fixture/repo/deploy.key"
git -C "$fixture/repo" add .
git -C "$fixture/repo" commit -qm fixture

"$root/products/repo-triage/repo-triage.sh" \
  "$fixture/repo" "$fixture/report.md" >/dev/null

rg -q '\| Files \| 4 \|' "$fixture/report.md"
rg -q '\| Test-like files \| 1 \|' "$fixture/report.md"
rg -q '\| CI definitions \| 1 \|' "$fixture/report.md"
rg -q -- '- `pyproject.toml`' "$fixture/report.md"
rg -q -- '- `deploy.key`' "$fixture/report.md"
printf 'repo-triage tests passed\n'
