Files
2026-10-07 09:37:57 +03:30

2.7 KiB

Repository Guidelines

Project Structure & Module Organization

src/blackout_notifier/ contains the Python notifier: clients.py handles SAAPA/EitaaYar requests, service.py coordinates notifications, state.py persists deduplication state, and config.py, models.py, messages.py, and cli.py provide supporting logic. main.sh is a standalone, read-only outage dashboard. Python tests and Bash dashboard tests live in tests/. .gitea/workflows/ defines testing, hourly checks, and runner-image publishing. state/outages.json is live notification state; archive/blackouts-1404.json is historical reference. avatar.png is a repository image asset.

Build, Test, and Development Commands

Use Python 3.11 or newer:

python -m venv .venv
source .venv/bin/activate
python -m pip install -e '.[test]'
cp .env.example .env

After configuring .env, use python -m blackout_notifier check --dry-run to preview notifications without sending messages or changing state. python -m blackout_notifier check performs a live check. Run ./main.sh --bill-id 7356609804429 for the dashboard; it requires Bash 4.3+, curl, jq, and GNU date.

Run the CI checks locally:

ruff check .
ruff format --check .
pytest
bash -n main.sh tests/test_main.sh
bash tests/test_main.sh

Coding Style & Naming Conventions

Use four-space indentation in Python, type annotations, snake_case functions and variables, and PascalCase classes. Ruff targets Python 3.11 with a 100-character line limit; use ruff format . to format changes. Follow the existing two-space Bash indentation, quote expansions, and preserve strict shell error handling.

Testing Guidelines

Use pytest files named tests/test_<module>.py and functions named test_<behavior>. Shared fixtures belong in tests/conftest.py. Mock external services and use temporary state files. Cover notification retries, updates, cancellation, malformed responses, and Tehran-time boundaries when relevant. Dashboard tests use Bash assertions in tests/test_main.sh. No numeric coverage threshold is configured.

Commit & Pull Request Guidelines

Recent commits use prefixes such as feat(cli):, fix(cli):, chore(ci):, and style:. Write concise, imperative subjects. Keep automated chore(state): ... [skip ci] commits separate from code changes. Pull requests should explain behavior changes, link relevant issues, and report validation; include terminal screenshots for dashboard layout changes.

Security & Configuration Tips

Keep tokens in ignored .env files or Gitea Actions secrets. Never commit credentials. Avoid editing live state during development: use temporary STATE_FILE paths. Update requirements.lock when changing runner dependencies and document configuration changes in README.md.