.PHONY: install lint fmt typecheck test cov up down logs ps run demo-repo

install:
	uv sync

lint:
	uv run ruff check .
	uv run ruff format --check .
	uv run mypy

fmt:
	uv run ruff check --fix .
	uv run ruff format .

test:
	uv run pytest -q

cov:
	uv run pytest -q --cov --cov-report=term

up:
	@test -f .env || { cp .env.example .env; echo "created .env from .env.example — fill in the secrets"; }
	docker compose up -d --build

down:
	docker compose down

logs:
	docker compose logs -f --tail=100 bot

ps:
	docker compose ps

# Run the bot on this machine without Docker: SQLite (./tgit.db) and the settings from .env
run:
	uv run python -m app

# A local uploads repo seeded from the template — try the bot without SourceCraft:
#   make demo-repo  →  put the printed GIT_UPLOADS_URL into .env  →  make run
DEMO_REPO := $(CURDIR)/data/demo-uploads.git
demo-repo:
	@test ! -e $(DEMO_REPO) || { echo "$(DEMO_REPO) already exists"; exit 1; }
	@rm -rf data/demo-seed && mkdir -p data && cp -r infra/uploads-template data/demo-seed
	@cd data/demo-seed && git init -q -b main && git add -A \
		&& git -c user.name=tgit-bot -c user.email=tgit-bot@users.noreply.tgit commit -qm "init: uploads template"
	@git clone -q --bare data/demo-seed $(DEMO_REPO) && rm -rf data/demo-seed
	@echo "GIT_UPLOADS_URL=$(DEMO_REPO)"
