Files
nisse/nisse-review/src/nisse_review/main.py
T
dongarandClaude Opus 5.5 faf973be6c
CI / checks (push) Skipped
CI / checks (pull_request) Successful in 1m48s
CI / e2e (pull_request) Successful in 28m44s
nisse-review: match repository patterns against Gitea's search
At bring-up, `dev/*` failed: listing an organization's repositories
(/orgs/dev/repos) needs the read:organization token scope, which the
reviewer's token doesn't have and shouldn't need. Patterns are now matched
against /repos/search, which needs only the repository scope and already
lists every repository the account can read. A pattern that matches
nothing is logged (access.no_match). owner_repositories goes.

A Gitea error at startup is now reported like a config error, not a
traceback.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J5Utyfzw7gF7UhjRDEtjTk
2026-10-16 22:17:47 +00:00

51 lines
1.5 KiB
Python

"""Entry point for the review agent: loads its configuration, checks its
access, and reviews until told to stop."""
import os
import signal
import sys
from pathlib import Path
from types import FrameType
from nisse_core.config import ConfigError
from nisse_core.envfile import load_env_file
from nisse_core.gitea import GiteaError
from nisse_review.access import AccessRefused
from nisse_review.build import StartupError, build
from nisse_review.config import ReviewConfig
def main() -> int:
load_env_file(Path(os.environ.get("NISSE_ENV", ".env")).expanduser())
try:
config = ReviewConfig.load()
built = build(config)
except (ConfigError, StartupError, GiteaError) as exc:
print(f"nisse-review: {exc}", file=sys.stderr)
return 2
def shutdown(_signum: int, _frame: FrameType | None) -> None:
print("nisse-review: stopping", file=sys.stderr)
built.scheduler.stop()
signal.signal(signal.SIGINT, shutdown)
signal.signal(signal.SIGTERM, shutdown)
print(
f"nisse-review: ready as {built.account}, reading "
+ (", ".join(built.repositories) or "no repositories"),
file=sys.stderr,
)
try:
built.scheduler.run_forever()
except AccessRefused as exc:
# R3: a grant made while it ran. It stops rather than review on.
print(f"nisse-review: stopping: {exc}", file=sys.stderr)
return 3
finally:
built.close()
return 0
if __name__ == "__main__":
sys.exit(main())