#!/usr/bin/env -S uv run python

from __future__ import annotations

__VERSION__ = "1"

import os
import sys

import pygit2

from pygittools.hooks import parse_ref_updates
from pygittools.hooks_notify import PostReceiveNotify

NOTIFY_URL = os.environ.get("PYGITWEB_NOTIFY_URL", "http://127.0.0.1:8000/_internal/notify")
PROJECT = os.environ.get("PYGITWEB_PROJECT") or os.path.basename(os.getcwd()).removesuffix(".git")


def main() -> int:
	repo = pygit2.Repository(".")
	updates = parse_ref_updates(sys.stdin)
	result = PostReceiveNotify(repo, NOTIFY_URL, PROJECT).run(updates)
	return int(result.value)


if __name__ == "__main__":
	raise SystemExit(main())